3.0 - inspector

This commit is contained in:
monitor1394
2022-02-25 08:10:09 +08:00
parent e72349a69f
commit 1ee0df09eb
43 changed files with 217 additions and 1004 deletions

View File

@@ -17,7 +17,6 @@ namespace XCharts.Editor
protected SerializedProperty m_Settings;
protected SerializedProperty m_Theme;
protected SerializedProperty m_ChartName;
protected SerializedProperty m_DebugMode;
protected SerializedProperty m_DebugInfo;
protected SerializedProperty m_RaycastTarget;
@@ -25,6 +24,7 @@ namespace XCharts.Editor
protected List<SerializedProperty> m_Series = new List<SerializedProperty>();
private bool m_BaseFoldout;
private bool m_CheckWarning = false;
private int m_LastComponentCount = 0;
private int m_LastSerieCount = 0;
@@ -41,7 +41,6 @@ namespace XCharts.Editor
m_ChartName = serializedObject.FindProperty("m_ChartName");
m_Theme = serializedObject.FindProperty("m_Theme");
m_Settings = serializedObject.FindProperty("m_Settings");
m_DebugMode = serializedObject.FindProperty("m_DebugMode");
m_DebugInfo = serializedObject.FindProperty("m_DebugInfo");
m_RaycastTarget = serializedObject.FindProperty("m_RaycastTarget");
@@ -57,7 +56,7 @@ namespace XCharts.Editor
public List<SerializedProperty> RefreshComponent()
{
m_Components.Clear();
serializedObject.Update();
serializedObject.UpdateIfRequiredOrScript();
foreach (var kv in m_Chart.typeListForComponent)
{
InitComponent(kv.Value.Name);
@@ -68,7 +67,7 @@ namespace XCharts.Editor
public List<SerializedProperty> RefreshSeries()
{
m_Series.Clear();
serializedObject.Update();
serializedObject.UpdateIfRequiredOrScript();
foreach (var kv in m_Chart.typeListForSerie)
{
InitSerie(kv.Value.Name);
@@ -83,7 +82,7 @@ namespace XCharts.Editor
base.OnInspectorGUI();
return;
}
serializedObject.Update();
serializedObject.UpdateIfRequiredOrScript();
if (m_LastComponentCount != m_Chart.components.Count)
{
m_LastComponentCount = m_Chart.components.Count;
@@ -107,16 +106,7 @@ namespace XCharts.Editor
protected virtual void OnStartInspectorGUI()
{
var version = string.Format("v{0}_{1}", XChartsMgr.version, XChartsMgr.versionDate);
if (m_EnableTextMeshPro.boolValue)
{
version += " TMP";
}
EditorGUILayout.Space();
EditorGUILayout.LabelField(version);
EditorGUILayout.Space();
serializedObject.Update();
ShowVersion();
m_BaseFoldout = ChartEditorHelper.DrawHeader("Base", m_BaseFoldout, false, null, null);
if (m_BaseFoldout)
{
@@ -134,13 +124,10 @@ namespace XCharts.Editor
protected virtual void OnDebugInspectorGUI()
{
EditorGUILayout.PropertyField(m_DebugInfo, true);
AddSerie();
AddComponent();
CheckWarning();
EditorGUILayout.BeginVertical(EditorStyles.helpBox);
EditorGUILayout.PropertyField(m_DebugMode);
EditorGUILayout.PropertyField(m_DebugInfo, true);
EditorGUILayout.EndVertical();
}
protected void PropertyComponnetList(SerializedProperty prop)
@@ -176,6 +163,15 @@ namespace XCharts.Editor
});
}
private void ShowVersion()
{
sb.Length = 0;
sb.AppendFormat("v{0}", XChartsMgr.fullVersion);
//if(m_EnableTextMeshPro.boolValue)
sb.Append("-tmp");
EditorGUILayout.HelpBox(sb.ToString(), MessageType.None);
}
private void AddComponent()
{
if (GUILayout.Button("Add Component"))
@@ -267,9 +263,9 @@ namespace XCharts.Editor
if (GUILayout.Button("Covert XY Axis"))
m_Chart.CovertXYAxis(0);
}
if (GUILayout.Button("Remove All Chart Object"))
if (GUILayout.Button("Reinit Component"))
{
m_Chart.RemoveChartObject();
m_Chart.ReinitAllChartComponent();
}
if (m_CheckWarning)
{
@@ -305,6 +301,7 @@ namespace XCharts.Editor
m_CheckWarning = true;
m_Chart.CheckWarning();
}
}
}
}

View File

@@ -0,0 +1,26 @@

using UnityEditor;
using UnityEngine;
using XCharts.Runtime;
namespace XCharts.Editor
{
[CustomPropertyDrawer(typeof(DebugInfo), true)]
public class DebugInfoDrawer : BasePropertyDrawer
{
public override string ClassName { get { return "Debug"; } }
public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label)
{
base.OnGUI(pos, prop, label);
if (MakeComponentFoldout(prop, ""))
{
++EditorGUI.indentLevel;
PropertyField(prop, "m_FoldSeries");
PropertyField(prop, "m_ShowDebugInfo");
PropertyField(prop, "m_ShowAllChildObject");
PropertyField(prop, "m_DebugInfoTextStyle");
--EditorGUI.indentLevel;
}
}
}
}

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 41f7e109291bd44de96fccf526e9c7f1
guid: 99bd61acea264400fb4747b17a2731e4
MonoImporter:
externalObjects: {}
serializedVersion: 2

View File

@@ -12,7 +12,7 @@ namespace XCharts.Editor
public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label)
{
base.OnGUI(pos, prop, label);
if (MakeComponentFoldout(prop, "", new HeaderMenuInfo("Reset", () =>
if (MakeComponentFoldout(prop, "m_Show", new HeaderMenuInfo("Reset", () =>
{
var chart = prop.serializedObject.targetObject as BaseChart;
chart.settings.Reset();

View File

@@ -19,7 +19,7 @@ namespace XCharts.Editor
var defaultWidth = pos.width;
var defaultX = pos.x;
var chart = prop.serializedObject.targetObject as BaseChart;
if (MakeComponentFoldout(prop, "", new HeaderMenuInfo("Reset|Reset to theme default color", () =>
if (MakeComponentFoldout(prop, "m_Show", new HeaderMenuInfo("Reset|Reset to theme default color", () =>
{
chart.theme.sharedTheme.ResetTheme();
chart.RefreshAllComponent();

View File

@@ -15,6 +15,9 @@ namespace XCharts.Editor
PropertyField("m_Top");
PropertyField("m_Bottom");
PropertyField("m_BackgroundColor");
PropertyField("m_ShowBorder");
PropertyField("m_BorderWidth");
PropertyField("m_BorderColor");
--EditorGUI.indentLevel;
}
}

View File

@@ -10,19 +10,17 @@ namespace XCharts.Editor
{
protected const string MORE = "More";
protected bool m_MoreFoldout = false;
internal BaseChart chart { get; private set; }
internal MainComponent component { get; private set; }
public BaseChart chart { get; private set; }
public MainComponent component { get; private set; }
//Editor m_Inspector;
internal SerializedProperty baseProperty;
internal SerializedProperty showProperty;
public SerializedProperty baseProperty;
public SerializedProperty showProperty;
internal void Init(BaseChart chart, MainComponent target, SerializedProperty property, UnityEditor.Editor inspector)
{
this.chart = chart;
this.component = target;
this.baseProperty = property;
//m_Inspector = inspector;
showProperty = baseProperty.FindPropertyRelative("m_Show");
if (showProperty == null)
showProperty = baseProperty.FindPropertyRelative("m_Enable");

View File

@@ -32,7 +32,6 @@ namespace XCharts.Editor
this.chart = chart;
m_ComponentsProperty = componentProps;
//m_SerializedObject = serializedObject;
Assert.IsNotNull(m_ComponentsProperty);
@@ -73,24 +72,17 @@ namespace XCharts.Editor
if (chart == null)
return;
// if (chart.isDirty)
// {
// RefreshEditors();
// chart.isDirty = false;
// }
// Override list
for (int i = 0; i < m_Editors.Count; i++)
{
var editor = m_Editors[i];
string title = editor.GetDisplayTitle();
int id = i; // Needed for closure capture below
int id = i;
bool displayContent = ChartEditorHelper.DrawHeader(
title,
editor.baseProperty,
editor.showProperty,
() => { },
() => { ResetComponentEditor(id); },
() => { RemoveComponentEditor(id); }
);
if (displayContent)
@@ -99,11 +91,7 @@ namespace XCharts.Editor
}
}
if (m_Editors.Count > 0)
{
//EditorGUILayout.Space();
}
else
if (m_Editors.Count == 0)
{
EditorGUILayout.HelpBox("No componnet.", MessageType.Info);
}
@@ -151,6 +139,14 @@ namespace XCharts.Editor
AssetDatabase.Refresh();
}
private void ResetComponentEditor(int id)
{
m_Editors[id].component.Reset();
EditorUtility.SetDirty(chart);
AssetDatabase.SaveAssets();
AssetDatabase.Refresh();
}
private void RemoveComponentEditor(int id)
{
m_Editors[id].OnDisable();

View File

@@ -1,36 +0,0 @@
using UnityEditor;
using XCharts.Runtime;
namespace XCharts.Editor
{
[ComponentEditor(typeof(Vessel))]
public class VesselEditor : MainComponentEditor<Vessel>
{
public override void OnInspectorGUI()
{
++EditorGUI.indentLevel;
var shape = (Vessel.Shape)baseProperty.FindPropertyRelative("m_Shape").intValue;
PropertyField("m_Shape");
PropertyField("m_ShapeWidth");
PropertyField("m_Gap");
PropertyTwoFiled("m_Center");
PropertyField("m_BackgroundColor");
PropertyField("m_Color");
PropertyField("m_AutoColor");
switch (shape)
{
case Vessel.Shape.Circle:
PropertyField("m_Radius");
PropertyField("m_Smoothness");
break;
case Vessel.Shape.Rect:
PropertyField("m_Width");
PropertyField("m_Height");
PropertyField("m_CornerRadius");
break;
}
--EditorGUI.indentLevel;
}
}
}

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: ffd6706dd3dd048d5ab9c538c133e963
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,22 +0,0 @@
using XCharts.Runtime;
namespace XCharts.Editor
{
[SerieEditor(typeof(Liquid))]
public class LiquidEditor : SerieEditor<Liquid>
{
public override void OnCustomInspectorGUI()
{
PropertyField("m_VesselIndex");
PropertyField("m_Min");
PropertyField("m_Max");
PropertyField("m_WaveLength");
PropertyField("m_WaveHeight");
PropertyField("m_WaveSpeed");
PropertyField("m_WaveOffset");
PropertyField("m_ItemStyle");
PropertyField("m_Animation");
}
}
}

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: d62c400d54e9f412abb6a9befbfa3937
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -20,6 +20,7 @@ namespace XCharts.Editor
Dictionary<Type, Type> m_EditorTypes;
List<SerieBaseEditor> m_Editors;
private bool m_SerieFoldout;
public SerieListEditor(BaseChartEditor editor)
@@ -73,7 +74,22 @@ namespace XCharts.Editor
{
if (chart == null)
return;
if (chart.debug.foldSeries)
{
m_SerieFoldout = ChartEditorHelper.DrawHeader("Series", m_SerieFoldout, false, null, null);
if (m_SerieFoldout)
{
DrawSeries();
}
}
else
{
DrawSeries();
}
}
void DrawSeries()
{
for (int i = 0; i < m_Editors.Count; i++)
{
var editor = m_Editors[i];
@@ -96,6 +112,7 @@ namespace XCharts.Editor
void RefreshEditors()
{
m_SerializedObject.UpdateIfRequiredOrScript();
foreach (var editor in m_Editors)
editor.OnDisable();

View File

@@ -127,13 +127,6 @@ namespace XCharts.Editor
AddChart<RingChart>("RingChart");
}
[MenuItem("XCharts/LiquidChart", priority = 53)]
[MenuItem("GameObject/XCharts/LiquidChart", priority = 53)]
public static void AddLiquidChart()
{
AddChart<LiquidChart>("LiquidChart");
}
[MenuItem("XCharts/CandlestickChart", priority = 54)]
[MenuItem("GameObject/XCharts/CandlestickChart", priority = 54)]
public static void CandlestickChart()

View File

@@ -1,27 +0,0 @@

using UnityEngine;
namespace XCharts.Runtime
{
/// <summary>
/// 水位图
/// </summary>
[AddComponentMenu("XCharts/LiquidChart", 22)]
[ExecuteInEditMode]
[RequireComponent(typeof(RectTransform))]
[DisallowMultipleComponent]
public class LiquidChart : BaseChart
{
#if UNITY_EDITOR
protected override void Reset()
{
base.Reset();
GetChartComponent<Tooltip>().type = Tooltip.Type.Line;
RemoveData();
Liquid.AddDefaultSerie(this, GenerateDefaultSerieName());
}
#endif
}
}

View File

@@ -2,9 +2,10 @@
using System;
using UnityEngine;
using UnityEngine.UI;
using XCharts.Runtime;
using XUGL;
namespace XCharts.Runtime
namespace XCharts
{
public abstract class AxisHandler<T> : MainComponentHandler
where T : Axis

View File

@@ -3,16 +3,17 @@ using UnityEngine;
using System;
using System.Collections.Generic;
using System.Text;
using UnityEngine.UI;
namespace XCharts.Runtime
{
[Serializable]
public class DebugInfo
{
[SerializeField] private bool m_Show;
[SerializeField] private bool m_ShowDebugInfo = false;
[SerializeField] protected bool m_ShowAllChildObject = false;
[SerializeField] protected bool m_FoldSeries = false;
[SerializeField]
private TextStyle m_TextStyle = new TextStyle()
private TextStyle m_DebugInfoTextStyle = new TextStyle()
{
fontSize = 18,
backgroundColor = new Color32(32, 32, 32, 170),
@@ -31,7 +32,8 @@ namespace XCharts.Runtime
private ChartLabel m_Label;
private List<float> m_FpsList = new List<float>();
public bool showAllChildObject { get { return m_ShowAllChildObject; } }
public bool foldSeries { get { return m_FoldSeries; } set { m_FoldSeries = value; } }
public float fps { get; private set; }
public float avgFps { get; private set; }
public int refreshCount { get; internal set; }
@@ -40,15 +42,15 @@ namespace XCharts.Runtime
public void Init(BaseChart chart)
{
m_Chart = chart;
m_Label = AddDebugInfoObject("debug", chart.transform, m_TextStyle, chart.theme);
m_Label = AddDebugInfoObject("debug", chart.transform, m_DebugInfoTextStyle, chart.theme);
}
public void Update()
{
if (clickChartCount >= 2)
{
m_Show = !m_Show;
ChartHelper.SetActive(m_Label.transform, m_Show);
m_ShowDebugInfo = !m_ShowDebugInfo;
ChartHelper.SetActive(m_Label.transform, m_ShowDebugInfo);
clickChartCount = 0;
m_LastCheckShowTime = Time.realtimeSinceStartup;
return;
@@ -58,7 +60,7 @@ namespace XCharts.Runtime
m_LastCheckShowTime = Time.realtimeSinceStartup;
clickChartCount = 0;
}
if (!m_Show || m_Label == null)
if (!m_ShowDebugInfo || m_Label == null)
return;
m_FrameCount++;
@@ -130,7 +132,7 @@ namespace XCharts.Runtime
var labelGameObject = ChartHelper.AddObject(name, parent, anchorMin, anchorMax, pivot, sizeDelta);
labelGameObject.transform.SetAsLastSibling();
labelGameObject.hideFlags = m_Chart.chartHideFlags;
ChartHelper.SetActive(labelGameObject, m_Show);
ChartHelper.SetActive(labelGameObject, m_ShowDebugInfo);
var label = ChartHelper.GetOrAddComponent<ChartLabel>(labelGameObject);
label.labelBackground = label;

View File

@@ -9,8 +9,9 @@ namespace XCharts.Runtime
/// 全局参数设置组件。一般情况下可使用默认值,当有需要时可进行调整。
/// </summary>
[Serializable]
public class Settings : ChildComponent
public class Settings : MainComponent
{
[SerializeField] private bool m_Show = true;
[SerializeField] [Range(1, 20)] protected int m_MaxPainter = 10;
[SerializeField] protected bool m_ReversePainter = false;
[SerializeField] protected Material m_BasePainterMaterial;
@@ -23,6 +24,7 @@ namespace XCharts.Runtime
[SerializeField] protected float m_LegendIconLineWidth = 2;
[SerializeField] private float[] m_LegendIconCornerRadius = new float[] { 0.25f, 0.25f, 0.25f, 0.25f };
public bool show { get { return m_Show; } }
/// <summary>
/// max painter.
/// 设定的painter数量。
@@ -142,7 +144,7 @@ namespace XCharts.Runtime
ChartHelper.CopyArray(m_LegendIconCornerRadius, settings.legendIconCornerRadius);
}
public void Reset()
public override void Reset()
{
Copy(DefaultSettings);
}

View File

@@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: cb8cbed03560e47d59d15c19bc6cd11f
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,198 +0,0 @@

using System;
using System.Collections.Generic;
using UnityEngine;
namespace XCharts.Runtime
{
/// <summary>
/// Vessel component for liquid chart. There can be multiple vessels in a Chart, which can be matched by vesselIndex in Serie.
/// <para>
/// 容器组件。
/// 一般用于LiquidChart。一个Chart中可以有多个VesselSerie中用vesselIndex来对应。
/// </para>
/// </summary>
[Serializable]
[ComponentHandler(typeof(VesselHandler), true)]
public class Vessel : MainComponent, ISerieContainer
{
public enum Shape
{
/// <summary>
/// 圆形
/// </summary>
Circle,
/// <summary>
/// 正方形。
/// </summary>
Rect,
/// <summary>
/// 三角形。
/// </summary>
Triangle,
/// <summary>
/// 菱形。
/// </summary>
Diamond,
/// <summary>
/// 不显示标记。
/// </summary>
None,
}
[SerializeField] private bool m_Show = true;
[SerializeField] private Shape m_Shape = Shape.Circle;
[SerializeField] private float m_ShapeWidth = 5f;
[SerializeField] private float m_Gap = 5f;
[SerializeField] private Color32 m_Color = new Color32(70, 70, 240, 255);
[SerializeField] private Color32 m_BackgroundColor;
[SerializeField] private bool m_AutoColor = true;
[SerializeField] private float[] m_Center = new float[2] { 0.5f, 0.45f };
[SerializeField] private float m_Radius = 0.35f;
[SerializeField] [Range(0.5f, 10f)] private float m_Smoothness = 1f;
[SerializeField] private float m_Width = 0.5f;
[SerializeField] private float m_Height = 0.7f;
[SerializeField] private float[] m_CornerRadius = new float[] { 0, 0, 0, 0 };
public VesselContext context = new VesselContext();
/// <summary>
/// Whether to show the vessel.
/// 是否显示容器组件。
/// [defaut: true]
/// </summary>
public bool show
{
get { return m_Show; }
set { if (PropertyUtil.SetStruct(ref m_Show, value)) SetVerticesDirty(); }
}
/// <summary>
/// The shape of vessel.
/// 容器形状。
/// [default: Shape.Circle]
/// </summary>
public Shape shape
{
get { return m_Shape; }
set { if (PropertyUtil.SetStruct(ref m_Shape, value)) SetVerticesDirty(); }
}
/// <summary>
/// Thickness of vessel.
/// 容器厚度。
/// [defaut: 5f]
/// </summary>
public float shapeWidth
{
get { return m_ShapeWidth; }
set { if (PropertyUtil.SetStruct(ref m_ShapeWidth, value)) SetVerticesDirty(); }
}
/// <summary>
/// The gap between the vessel and the liquid.
/// 间隙。容器和液体的间隙。
/// [defaut: 10f]
/// </summary>
public float gap
{
get { return m_Gap; }
set { if (PropertyUtil.SetStruct(ref m_Gap, value)) SetVerticesDirty(); }
}
/// <summary>
/// The center of vesselß. The center[0] is the x-coordinate, and the center[1] is the y-coordinate.
/// When value between 0 and 1 represents a percentage relative to the chart.
/// 中心点。数组的第一项是横坐标,第二项是纵坐标。
/// 当值为0-1之间时表示百分比设置成百分比时表示图表宽高最小值的百分比。
/// [default:[0.5f,0.45f]]
/// </summary>
public float[] center
{
get { return m_Center; }
set { if (value != null) { m_Center = value; SetAllDirty(); } }
}
/// <summary>
/// The radius of vessel.
/// When value between 0 and 1 represents a percentage relative to the chart.
/// 半径。
/// [default: 0.35f]
/// </summary>
public float radius
{
get { return m_Radius; }
set { if (PropertyUtil.SetStruct(ref m_Radius, value)) SetAllDirty(); }
}
/// <summary>
/// The width of vessel.
/// When value between 0 and 1 represents a percentage relative to the chart.
/// 容器的宽。shape为Rect时有效。
/// [default: 0.35f]
/// </summary>
public float width
{
get { return m_Width; }
set { if (PropertyUtil.SetStruct(ref m_Width, value)) SetAllDirty(); }
}
/// <summary>
/// The height of vessel.
/// When value between 0 and 1 represents a percentage relative to the chart.
/// 容器的高。shape为Rect时有效。
/// [default: 0.35f]
/// </summary>
public float height
{
get { return m_Height; }
set { if (PropertyUtil.SetStruct(ref m_Height, value)) SetAllDirty(); }
}
/// <summary>
/// The smoothness of wave.
/// 水波平滑度。
/// [default: 1f]
/// </summary>
public float smoothness
{
get { return m_Smoothness; }
set { if (PropertyUtil.SetStruct(ref m_Smoothness, value)) SetAllDirty(); }
}
/// <summary>
/// Background color of polar, which is transparent by default.
/// 背景色,默认透明。
/// [default: `Color.clear`]
/// </summary>
public Color32 backgroundColor
{
get { return m_BackgroundColor; }
set { if (PropertyUtil.SetColor(ref m_BackgroundColor, value)) SetVerticesDirty(); }
}
/// <summary>
/// Vessel color. The default is consistent with Serie.
/// 容器颜色。默认和serie一致。
/// </summary>
public Color32 color
{
get { return m_Color; }
set { if (PropertyUtil.SetColor(ref m_Color, value)) SetVerticesDirty(); }
}
/// <summary>
/// Whether automatic color. If true, the color matches serie.
/// 是否自动颜色。为true时颜色会和serie一致。
/// [default: true]
/// </summary>
public bool autoColor
{
get { return m_AutoColor; }
set { if (PropertyUtil.SetStruct(ref m_AutoColor, value)) SetVerticesDirty(); }
}
/// <summary>
/// The radius of rounded corner. Its unit is px. Use array to respectively specify the 4 corner radiuses((clockwise upper left, upper right, bottom right and bottom left)).
/// 容器的圆角半径。用数组分别指定4个圆角半径顺时针左上右上右下左下。shape为Rect时有效。
/// </summary>
public float[] cornerRadius
{
get { return m_CornerRadius; }
set { if (PropertyUtil.SetClass(ref m_CornerRadius, value, true)) SetVerticesDirty(); }
}
public bool IsPointerEnter()
{
return context.isPointerEnter;
}
}
}

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 849f583b643a44246b3ec4abd7909b1b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,27 +0,0 @@
using UnityEngine;
namespace XCharts.Runtime
{
public class VesselContext : MainComponentContext
{
/// <summary>
/// the runtime center position of vessel.
/// 运行时中心点。
/// </summary>
public Vector3 center { get; internal set; }
/// <summary>
/// the runtime radius of vessel.
/// 运行时半径。
/// </summary>
public float radius { get; internal set; }
/// <summary>
/// The actual radius after deducting shapeWidth and gap.
/// 运行时内半径。扣除厚度和间隙后的实际半径。
/// </summary>
public float innerRadius { get; internal set; }
public float width { get; set; }
public float height { get; set; }
public bool isPointerEnter { get; set; }
}
}

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: ab0e7ad914ca24fcaa1fe470be695fd2
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,24 +0,0 @@
using System;
using System.Collections.Generic;
using UnityEngine;
namespace XCharts.Runtime
{
[UnityEngine.Scripting.Preserve]
internal sealed class VesselHandler : MainComponentHandler<Vessel>
{
public override void Update()
{
if (chart.isPointerInChart)
{
component.context.isPointerEnter = false;
return;
}
var vessel = component;
vessel.context.isPointerEnter = vessel.show
&& Vector3.Distance(vessel.context.center, chart.pointerPos) <= vessel.context.radius;
}
}
}

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: d52746e0238ff482589d37ee481394f6
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,36 +0,0 @@
using System;
using System.Collections.Generic;
using UnityEngine;
namespace XCharts.Runtime
{
internal static class VesselHelper
{
public static Color32 GetColor(Vessel vessel, Serie serie, ThemeStyle theme, List<string> legendRealShowName)
{
if (serie != null && vessel.autoColor)
{
var colorIndex = legendRealShowName.IndexOf(serie.serieName);
return SerieHelper.GetItemColor(serie, null, theme, colorIndex, false);
}
else
{
return vessel.color;
}
}
public static void UpdateVesselCenter(Vessel vessel, Vector3 chartPosition, float chartWidth, float chartHeight)
{
if (vessel.center.Length < 2) return;
var centerX = vessel.center[0] <= 1 ? chartWidth * vessel.center[0] : vessel.center[0];
var centerY = vessel.center[1] <= 1 ? chartHeight * vessel.center[1] : vessel.center[1];
var checkWidth = Mathf.Min(chartWidth, chartHeight);
vessel.context.center = chartPosition + new Vector3(centerX, centerY);
vessel.context.radius = ChartHelper.GetRuntimeRelativeOrAbsoluteValue(vessel.radius, checkWidth);
vessel.context.innerRadius = vessel.context.radius - vessel.shapeWidth - vessel.gap;
vessel.context.width = ChartHelper.GetRuntimeRelativeOrAbsoluteValue(vessel.width, checkWidth) - 2 * vessel.gap;
vessel.context.height = ChartHelper.GetRuntimeRelativeOrAbsoluteValue(vessel.height, chartHeight) - 2 * vessel.gap;
}
}
}

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 5d0abd225ece74e94b6f84034da63d13
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -22,7 +22,10 @@ namespace XCharts.Runtime
[SerializeField] private float m_Right = 0.08f;
[SerializeField] private float m_Top = 0.22f;
[SerializeField] private float m_Bottom = 0.12f;
[SerializeField] private Color m_BackgroundColor;
[SerializeField] private Color32 m_BackgroundColor;
[SerializeField] private bool m_ShowBorder = false;
[SerializeField] private float m_BorderWidth = 0f;
[SerializeField] private Color32 m_BorderColor;
public GridCoordContext context = new GridCoordContext();
@@ -75,11 +78,38 @@ namespace XCharts.Runtime
/// Background color of grid, which is transparent by default.
/// 网格背景色,默认透明。
/// </summary>
public Color backgroundColor
public Color32 backgroundColor
{
get { return m_BackgroundColor; }
set { if (PropertyUtil.SetColor(ref m_BackgroundColor, value)) SetVerticesDirty(); }
}
/// <summary>
/// Whether to show the grid border.
/// 是否显示网格边框。
/// </summary>
public bool showBorder
{
get { return m_ShowBorder; }
set { if (PropertyUtil.SetStruct(ref m_ShowBorder, value)) SetVerticesDirty(); }
}
/// <summary>
/// Border width of grid.
/// 网格边框宽。
/// </summary>
public float borderWidth
{
get { return m_BorderWidth; }
set { if (PropertyUtil.SetStruct(ref m_BorderWidth, value)) SetVerticesDirty(); }
}
/// <summary>
/// The color of grid border.
/// 网格边框颜色。
/// </summary>
public Color32 borderColor
{
get { return m_BorderColor; }
set { if (PropertyUtil.SetColor(ref m_BorderColor, value)) SetVerticesDirty(); }
}
public bool IsPointerEnter()
{
@@ -97,6 +127,7 @@ namespace XCharts.Runtime
context.width = chartWidth - context.left - context.right;
context.height = chartHeight - context.top - context.bottom;
context.position = new Vector3(context.x, context.y);
context.center = new Vector3(context.x + context.width / 2, context.y + context.height / 2);
}
public bool Contains(Vector3 pos)

View File

@@ -10,6 +10,7 @@ namespace XCharts.Runtime
public float width { get; internal set; }
public float height { get; internal set; }
public Vector3 position { get; internal set; }
public Vector3 center { get; internal set; }
public float left { get; internal set; }
public float right { get; internal set; }
public float bottom { get; internal set; }

View File

@@ -55,21 +55,21 @@ namespace XCharts.Runtime
{
if (!SeriesHelper.IsAnyClipSerie(chart.series))
{
DrawCoord(vh);
DrawCoord(vh, component);
}
}
public override void DrawTop(VertexHelper vh)
{
if (SeriesHelper.IsAnyClipSerie(chart.series))
{
DrawCoord(vh);
DrawCoord(vh, component);
}
}
private void DrawCoord(VertexHelper vh)
private void DrawCoord(VertexHelper vh, GridCoord grid)
{
var grid = component;
if (grid.show && !ChartHelper.IsClearColor(grid.backgroundColor))
if (!grid.show) return;
if (!ChartHelper.IsClearColor(grid.backgroundColor))
{
var p1 = new Vector2(grid.context.x, grid.context.y);
var p2 = new Vector2(grid.context.x, grid.context.y + grid.context.height);
@@ -77,6 +77,15 @@ namespace XCharts.Runtime
var p4 = new Vector2(grid.context.x + grid.context.width, grid.context.y);
UGL.DrawQuadrilateral(vh, p1, p2, p3, p4, grid.backgroundColor);
}
if (grid.showBorder)
{
var borderWidth = grid.borderWidth == 0 ? chart.theme.axis.lineWidth * 2 : grid.borderWidth;
var borderColor = ChartHelper.IsClearColor(grid.borderColor)
? chart.theme.axis.lineColor
: grid.borderColor;
UGL.DrawBorder(vh, grid.context.center, grid.context.width - borderWidth,
grid.context.height - borderWidth, borderWidth, borderColor);
}
}
}
}

View File

@@ -18,7 +18,6 @@ namespace XCharts.Runtime
[SerializeField] protected string m_ChartName;
[SerializeField] protected ThemeStyle m_Theme = new ThemeStyle();
[SerializeField] protected Settings m_Settings;
[SerializeField] protected DebugInfo m_DebugInfo = new DebugInfo();
#pragma warning disable 0414
[SerializeField] [ListForComponent(typeof(AngleAxis))] private List<AngleAxis> m_AngleAxes = new List<AngleAxis>();
@@ -33,7 +32,6 @@ namespace XCharts.Runtime
[SerializeField] [ListForComponent(typeof(RadiusAxis))] private List<RadiusAxis> m_RadiusAxes = new List<RadiusAxis>();
[SerializeField] [ListForComponent(typeof(Title))] private List<Title> m_Titles = new List<Title>();
[SerializeField] [ListForComponent(typeof(Tooltip))] private List<Tooltip> m_Tooltips = new List<Tooltip>();
[SerializeField] [ListForComponent(typeof(Vessel))] private List<Vessel> m_Vessels = new List<Vessel>();
[SerializeField] [ListForComponent(typeof(VisualMap))] private List<VisualMap> m_VisualMaps = new List<VisualMap>();
[SerializeField] [ListForComponent(typeof(XAxis))] private List<XAxis> m_XAxes = new List<XAxis>();
[SerializeField] [ListForComponent(typeof(YAxis))] private List<YAxis> m_YAxes = new List<YAxis>();
@@ -46,7 +44,6 @@ namespace XCharts.Runtime
[SerializeField] [ListForSerie(typeof(EffectScatter))] private List<EffectScatter> m_SerieEffectScatters = new List<EffectScatter>();
[SerializeField] [ListForSerie(typeof(Heatmap))] private List<Heatmap> m_SerieHeatmaps = new List<Heatmap>();
[SerializeField] [ListForSerie(typeof(Line))] private List<Line> m_SerieLines = new List<Line>();
[SerializeField] [ListForSerie(typeof(Liquid))] private List<Liquid> m_SerieLiquids = new List<Liquid>();
[SerializeField] [ListForSerie(typeof(Pie))] private List<Pie> m_SeriePies = new List<Pie>();
[SerializeField] [ListForSerie(typeof(Radar))] private List<Radar> m_SerieRadars = new List<Radar>();
[SerializeField] [ListForSerie(typeof(Ring))] private List<Ring> m_SerieRings = new List<Ring>();
@@ -212,7 +209,7 @@ namespace XCharts.Runtime
{
var painter = GetPainter(index);
if (painter == null) return;
painter.SetActive(flag, m_DebugMode);
painter.SetActive(flag, m_DebugInfo.showAllChildObject);
}
protected virtual void CheckTheme()
@@ -309,7 +306,7 @@ namespace XCharts.Runtime
painter.index = m_PainterList.Count;
painter.type = Painter.Type.Serie;
painter.onPopulateMesh = OnDrawPainterSerie;
painter.SetActive(false, m_DebugMode);
painter.SetActive(false, m_DebugInfo.showAllChildObject);
painter.material = settings.seriePainterMaterial;
painter.transform.SetSiblingIndex(index + 1);
m_PainterList.Add(painter);
@@ -318,7 +315,7 @@ namespace XCharts.Runtime
m_GraphMaxAnchor, m_GraphPivot, sizeDelta, chartHideFlags, 2 + settings.maxPainter);
m_PainterTop.type = Painter.Type.Top;
m_PainterTop.onPopulateMesh = OnDrawPainterTop;
m_PainterTop.SetActive(true, m_DebugMode);
m_PainterTop.SetActive(true, m_DebugInfo.showAllChildObject);
m_PainterTop.material = settings.topPainterMaterial;
m_PainterTop.transform.SetSiblingIndex(settings.maxPainter + 1);
}
@@ -626,6 +623,11 @@ namespace XCharts.Runtime
public void OnBeforeSerialize()
{
#if UNITY_EDITOR && UNITY_2019_1_OR_NEWER
if (!UnityEditor.EditorUtility.IsDirty(this))
return;
UnityEditor.EditorUtility.ClearDirty(this);
#endif
InitListForFieldInfos();
foreach (var kv in m_TypeListForSerie)
{

View File

@@ -143,12 +143,12 @@ namespace XCharts.Runtime
}
/// <summary>
/// 移除所有图表子节点,会自动重新初始化。
/// 移除重新初始化所有组件
/// </summary>
public void RemoveChartObject()
public void ReinitAllChartComponent()
{
ChartHelper.DestroyAllChildren(transform);
//SetAllComponentDirty();
SetAllComponentDirty();
}
public bool ScreenPointToChartPoint(Vector2 screenPoint, out Vector2 chartPoint)

View File

@@ -11,8 +11,9 @@ namespace XCharts.Runtime
IPointerEnterHandler, IPointerExitHandler, IBeginDragHandler, IPointerClickHandler,
IDragHandler, IEndDragHandler, IScrollHandler
{
[SerializeField] protected bool m_DebugMode = false;
[SerializeField] protected bool m_EnableTextMeshPro = false;
[SerializeField] protected DebugInfo m_DebugInfo = new DebugInfo();
protected Painter m_Painter;
protected int m_SiblingIndex;
@@ -48,12 +49,11 @@ namespace XCharts.Runtime
protected Vector2 graphAnchorMax { get { return m_GraphMinAnchor; } }
protected Vector2 graphAnchorMin { get { return m_GraphMaxAnchor; } }
protected Vector2 graphPivot { get { return m_GraphPivot; } }
public HideFlags chartHideFlags { get { return m_DebugMode ? HideFlags.None : HideFlags.HideInHierarchy; } }
public HideFlags chartHideFlags { get { return m_DebugInfo.showAllChildObject ? HideFlags.None : HideFlags.HideInHierarchy; } }
public DebugInfo debug { get { return m_DebugInfo; } }
private ScrollRect m_ScrollRect;
public Painter painter { get { return m_Painter; } }
internal bool debugModel { get { return m_DebugMode; } }
protected virtual void InitComponent()
{
@@ -100,7 +100,7 @@ namespace XCharts.Runtime
if (!Application.isPlaying)
{
m_IsOnValidate = true;
Update();
//Update();
}
#endif
m_PainerDirty = true;
@@ -125,7 +125,7 @@ namespace XCharts.Runtime
if (m_EnableTextMeshPro != enableTextMeshPro)
{
m_EnableTextMeshPro = enableTextMeshPro;
RemoveChartObject();
ReinitAllChartComponent();
}
}

View File

@@ -53,6 +53,10 @@ namespace XCharts.Runtime
m_ComponentDirty = false;
}
public virtual void Reset()
{
}
public virtual void ClearData()
{
}

View File

@@ -32,7 +32,7 @@ namespace XCharts.Runtime
{
SerieLabelPool.ClearAll();
chartList.Clear();
if(Resources.Load<XCSettings>("XCSettings"))
if (Resources.Load<XCSettings>("XCSettings"))
XCThemeMgr.ReloadThemeList();
SceneManager.sceneUnloaded += OnSceneLoaded;
}
@@ -66,7 +66,7 @@ namespace XCharts.Runtime
public static List<BaseChart> GetCharts(string chartName)
{
if (string.IsNullOrEmpty(chartName)) return null;
return chartList.FindAll(chart => chartName.Equals(chartName));
return chartList.FindAll(chart => chartName.Equals(chart.chartName));
}
public static void RemoveChart(string chartName)
@@ -86,6 +86,33 @@ namespace XCharts.Runtime
return chartList.Contains(chart);
}
public static bool IsRepeatChartName(BaseChart chart, string chartName = null)
{
if (chartName == null)
chartName = chart.chartName;
if (string.IsNullOrEmpty(chartName))
return false;
foreach (var temp in chartList)
{
if (temp != chart && chartName.Equals(temp.chartName))
return true;
}
return false;
}
public static string GetRepeatChartNameInfo(BaseChart chart, string chartName)
{
if (string.IsNullOrEmpty(chartName))
return string.Empty;
string result = "";
foreach (var temp in chartList)
{
if (temp != chart && chartName.Equals(temp.chartName))
result += ChartHelper.GetFullName(temp.transform) + "\n";
}
return result;
}
public static void RemoveAllChartObject()
{
if (chartList.Count == 0)
@@ -95,7 +122,7 @@ namespace XCharts.Runtime
foreach (var chart in chartList)
{
if (chart != null)
chart.RemoveChartObject();
chart.ReinitAllChartComponent();
}
}

View File

@@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: 296736becc9a041c8ac957be56db7c8f
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,68 +0,0 @@
using UnityEngine;
namespace XCharts.Runtime
{
[System.Serializable]
[SerieHandler(typeof(LiquidHandler), true)]
[RequireChartComponent(typeof(Vessel))]
[SerieExtraComponent(typeof(LabelStyle))]
public class Liquid : Serie, INeedSerieContainer
{
[SerializeField] private float m_WaveHeight = 10f;
[SerializeField] private float m_WaveLength = 20f;
[SerializeField] private float m_WaveSpeed = 5f;
[SerializeField] private float m_WaveOffset = 0f;
/// <summary>
/// Wave length of the wave, which is relative to the diameter.
/// 波长。为0-1小数时指直线的百分比。
/// </summary>
public float waveLength
{
get { return m_WaveLength; }
set { if (PropertyUtil.SetStruct(ref m_WaveLength, value)) SetVerticesDirty(); }
}
/// <summary>
/// 波高。
/// </summary>
public float waveHeight
{
get { return m_WaveHeight; }
set { if (PropertyUtil.SetStruct(ref m_WaveHeight, value)) SetVerticesDirty(); }
}
/// <summary>
/// 波偏移。
/// </summary>
public float waveOffset
{
get { return m_WaveOffset; }
set { if (PropertyUtil.SetStruct(ref m_WaveOffset, value)) SetVerticesDirty(); }
}
/// <summary>
/// 波速。正数时左移,负数时右移。
/// </summary>
public float waveSpeed
{
get { return m_WaveSpeed; }
set { if (PropertyUtil.SetStruct(ref m_WaveSpeed, value)) SetVerticesDirty(); }
}
public int containerIndex { get { return vesselIndex; } }
public int containterInstanceId { get; internal set; }
public static Serie AddDefaultSerie(BaseChart chart, string serieName)
{
chart.AddChartComponentWhenNoExist<Vessel>();
var serie = chart.AddSerie<Liquid>(serieName);
serie.min = 0;
serie.max = 100;
serie.AddExtraComponent<LabelStyle>();
serie.label.show = true;
serie.label.textStyle.fontSize = 40;
serie.label.formatter = "{d}%";
serie.label.textStyle.color = new Color32(70, 70, 240, 255);
chart.AddData(serie.index, UnityEngine.Random.Range(0, 100));
return serie;
}
}
}

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 5695e4d13541046f5b782ee6dfed489a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,369 +0,0 @@
using UnityEngine;
using UnityEngine.UI;
using XUGL;
namespace XCharts.Runtime
{
[UnityEngine.Scripting.Preserve]
internal sealed class LiquidHandler : SerieHandler<Liquid>
{
private bool m_UpdateLabelText = false;
private float m_WaveSpeed;
public override void Update()
{
base.Update();
if (m_UpdateLabelText)
{
m_UpdateLabelText = false;
RefreshLabelInternal();
}
}
public override void RefreshLabelNextFrame()
{
}
public override void DrawSerie(VertexHelper vh)
{
UpdateRuntimeData(serie);
DrawVesselBackground(vh, serie);
DrawLiquid(vh, serie);
DrawVessel(vh, serie);
}
private void UpdateRuntimeData(Liquid serie)
{
Vessel vessel;
if (chart.TryGetChartComponent<Vessel>(out vessel, serie.vesselIndex))
{
VesselHelper.UpdateVesselCenter(vessel, chart.chartPosition, chart.chartWidth, chart.chartHeight);
}
}
private void DrawVesselBackground(VertexHelper vh, Liquid serie)
{
var vessel = chart.GetChartComponent<Vessel>(serie.vesselIndex);
if (vessel != null)
{
if (vessel.backgroundColor.a != 0)
{
switch (vessel.shape)
{
case Vessel.Shape.Circle:
var cenPos = vessel.context.center;
var radius = vessel.context.radius;
UGL.DrawCricle(vh, cenPos, vessel.context.innerRadius + vessel.gap, vessel.backgroundColor,
chart.settings.cicleSmoothness);
UGL.DrawDoughnut(vh, cenPos, vessel.context.innerRadius, vessel.context.innerRadius + vessel.gap,
vessel.backgroundColor, Color.clear, chart.settings.cicleSmoothness);
break;
case Vessel.Shape.Rect:
UGL.DrawRectangle(vh, vessel.context.center, vessel.context.width / 2, vessel.context.height / 2,
vessel.backgroundColor);
break;
default:
break;
}
}
}
}
private void DrawVessel(VertexHelper vh, Liquid serie)
{
var vessel = chart.GetChartComponent<Vessel>(serie.vesselIndex);
if (vessel != null)
{
switch (vessel.shape)
{
case Vessel.Shape.Circle:
DrawCirleVessel(vh, vessel);
break;
case Vessel.Shape.Rect:
DrawRectVessel(vh, vessel);
break;
default:
DrawCirleVessel(vh, vessel);
break;
}
}
}
private void DrawCirleVessel(VertexHelper vh, Vessel vessel)
{
var cenPos = vessel.context.center;
var radius = vessel.context.radius;
var serie = SeriesHelper.GetSerieByVesselIndex(chart.series, vessel.index);
var vesselColor = VesselHelper.GetColor(vessel, serie, chart.theme, chart.m_LegendRealShowName);
if (vessel.gap != 0)
{
UGL.DrawDoughnut(vh, cenPos, vessel.context.innerRadius, vessel.context.innerRadius + vessel.gap,
vessel.backgroundColor, Color.clear, chart.settings.cicleSmoothness);
}
UGL.DrawDoughnut(vh, cenPos, radius - vessel.shapeWidth, radius, vesselColor, Color.clear,
chart.settings.cicleSmoothness);
}
private void DrawRectVessel(VertexHelper vh, Vessel vessel)
{
var serie = SeriesHelper.GetSerieByVesselIndex(chart.series, vessel.index);
var vesselColor = VesselHelper.GetColor(vessel, serie, chart.theme, chart.m_LegendRealShowName);
if (vessel.gap != 0)
{
UGL.DrawBorder(vh, vessel.context.center, vessel.context.width,
vessel.context.height, vessel.gap, vessel.backgroundColor, 0, vessel.cornerRadius);
}
UGL.DrawBorder(vh, vessel.context.center, vessel.context.width + 2 * vessel.gap,
vessel.context.height + 2 * vessel.gap, vessel.shapeWidth, vesselColor, 0, vessel.cornerRadius);
}
private void DrawLiquid(VertexHelper vh, Liquid serie)
{
if (!serie.show) return;
if (serie.animation.HasFadeOut()) return;
var vessel = chart.GetChartComponent<Vessel>(serie.vesselIndex);
if (vessel == null) return;
switch (vessel.shape)
{
case Vessel.Shape.Circle:
DrawCirleLiquid(vh, serie, vessel);
break;
case Vessel.Shape.Rect:
DrawRectLiquid(vh, serie, vessel);
break;
default:
DrawCirleLiquid(vh, serie, vessel);
break;
}
}
private void DrawCirleLiquid(VertexHelper vh, Liquid serie, Vessel vessel)
{
var cenPos = vessel.context.center;
var radius = vessel.context.innerRadius;
var serieData = serie.GetSerieData(0);
if (serieData == null) return;
var dataChangeDuration = serie.animation.GetUpdateAnimationDuration();
var value = serieData.GetCurrData(1, dataChangeDuration);
if (serie.context.checkValue != value)
{
serie.context.checkValue = value;
m_UpdateLabelText = true;
}
if (serieData.context.labelPosition != cenPos)
{
serieData.context.labelPosition = cenPos;
m_UpdateLabelText = true;
}
if (value <= 0) return;
var colorIndex = chart.m_LegendRealShowName.IndexOf(serie.serieName);
var realHig = (float)((value - serie.min) / (serie.max - serie.min) * radius * 2);
serie.animation.InitProgress(0, realHig);
var hig = serie.animation.IsFinish() ? realHig : serie.animation.GetCurrDetail();
var a = Mathf.Abs(radius - hig + (hig > radius ? serie.waveHeight : -serie.waveHeight));
var diff = Mathf.Sqrt(radius * radius - Mathf.Pow(a, 2));
var color = SerieHelper.GetItemColor(serie, serieData, chart.theme, colorIndex, false);
var toColor = SerieHelper.GetItemToColor(serie, serieData, chart.theme, colorIndex, false);
var isNeedGradient = !ChartHelper.IsValueEqualsColor(color, toColor);
var isFull = hig >= 2 * radius;
if (hig >= 2 * radius) hig = 2 * radius;
if (isFull && !isNeedGradient)
{
UGL.DrawCricle(vh, cenPos, radius, toColor, chart.settings.cicleSmoothness);
}
else
{
var startY = cenPos.y - radius + hig;
var waveStartPos = new Vector3(cenPos.x - diff, startY);
var waveEndPos = new Vector3(cenPos.x + diff, startY);
var startX = hig > radius ? cenPos.x - radius : waveStartPos.x;
var endX = hig > radius ? cenPos.x + radius : waveEndPos.x;
var step = vessel.smoothness;
if (step < 0.5f) step = 0.5f;
var lup = hig > radius ? new Vector3(cenPos.x - radius, cenPos.y) : waveStartPos;
var ldp = lup;
var nup = Vector3.zero;
var ndp = Vector3.zero;
var angle = 0f;
m_WaveSpeed += serie.waveSpeed * Time.deltaTime;
var isStarted = false;
var isEnded = false;
var waveHeight = isFull ? 0 : serie.waveHeight;
while (startX < endX)
{
startX += step;
if (startX > endX) startX = endX;
if (startX > waveStartPos.x && !isStarted)
{
startX = waveStartPos.x;
isStarted = true;
}
if (startX > waveEndPos.x && !isEnded)
{
startX = waveEndPos.x;
isEnded = true;
}
var py = Mathf.Sqrt(Mathf.Pow(radius, 2) - Mathf.Pow(Mathf.Abs(cenPos.x - startX), 2));
if (startX < waveStartPos.x || startX > waveEndPos.x)
{
nup = new Vector3(startX, cenPos.y + py);
}
else
{
var py2 = waveHeight * Mathf.Sin(1 / serie.waveLength * angle + m_WaveSpeed + serie.waveOffset);
var nupY = waveStartPos.y + py2;
if (nupY > cenPos.y + py) nupY = cenPos.y + py;
else if (nupY < cenPos.y - py) nupY = cenPos.y - py;
nup = new Vector3(startX, nupY);
angle += step;
}
ndp = new Vector3(startX, cenPos.y - py);
if (!ChartHelper.IsValueEqualsColor(color, toColor))
{
var colorMin = cenPos.y - radius;
var colorMax = startY + serie.waveHeight;
var tcolor1 = Color32.Lerp(color, toColor, 1 - (lup.y - colorMin) / (colorMax - colorMin));
var tcolor2 = Color32.Lerp(color, toColor, 1 - (ldp.y - colorMin) / (colorMax - colorMin));
UGL.DrawQuadrilateral(vh, lup, nup, ndp, ldp, tcolor1, tcolor2);
}
else
{
UGL.DrawQuadrilateral(vh, lup, nup, ndp, ldp, color);
}
lup = nup;
ldp = ndp;
}
}
if (serie.waveSpeed != 0 && Application.isPlaying && !isFull)
{
chart.RefreshPainter(serie);
}
if (!serie.animation.IsFinish())
{
serie.animation.CheckProgress(realHig);
chart.RefreshPainter(serie);
}
}
private void DrawRectLiquid(VertexHelper vh, Liquid serie, Vessel vessel)
{
var cenPos = vessel.context.center;
var serieData = serie.GetSerieData(0);
if (serieData == null) return;
var dataChangeDuration = serie.animation.GetUpdateAnimationDuration();
var value = serieData.GetCurrData(1, dataChangeDuration);
if (serie.context.checkValue != value)
{
serie.context.checkValue = value;
m_UpdateLabelText = true;
}
if (serieData.context.labelPosition != cenPos)
{
serieData.context.labelPosition = cenPos;
m_UpdateLabelText = true;
}
if (value <= 0) return;
var colorIndex = chart.m_LegendRealShowName.IndexOf(serie.serieName);
var realHig = (value - serie.min) / (serie.max - serie.min) * vessel.context.height;
serie.animation.InitProgress(0, (float)realHig);
var hig = serie.animation.IsFinish() ? realHig : serie.animation.GetCurrDetail();
var color = SerieHelper.GetItemColor(serie, serieData, chart.theme, colorIndex, false);
var toColor = SerieHelper.GetItemToColor(serie, serieData, chart.theme, colorIndex, false);
var isNeedGradient = !ChartHelper.IsValueEqualsColor(color, toColor);
var isFull = hig >= vessel.context.height;
if (hig >= vessel.context.height) hig = vessel.context.height;
if (isFull && !isNeedGradient)
{
UGL.DrawRectangle(vh, cenPos, vessel.context.width / 2, vessel.context.height / 2, toColor);
}
else
{
var startY = (float)(cenPos.y - vessel.context.height / 2 + hig);
var waveStartPos = new Vector3(cenPos.x - vessel.context.width / 2, startY);
var waveEndPos = new Vector3(cenPos.x + vessel.context.width / 2, startY);
var startX = waveStartPos.x;
var endX = waveEndPos.x;
var step = vessel.smoothness;
if (step < 0.5f) step = 0.5f;
var lup = waveStartPos;
var ldp = new Vector3(startX, vessel.context.center.y - vessel.context.height / 2);
var nup = Vector3.zero;
var ndp = Vector3.zero;
var angle = 0f;
var isStarted = false;
var isEnded = false;
var waveHeight = isFull ? 0 : serie.waveHeight;
m_WaveSpeed += serie.waveSpeed * Time.deltaTime;
while (startX < endX)
{
startX += step;
if (startX > endX) startX = endX;
if (startX > waveStartPos.x && !isStarted)
{
startX = waveStartPos.x;
isStarted = true;
}
if (startX > waveEndPos.x && !isEnded)
{
startX = waveEndPos.x;
isEnded = true;
}
var py = Mathf.Sqrt(Mathf.Pow(vessel.context.height, 2) - Mathf.Pow(Mathf.Abs(cenPos.x - startX), 2));
if (startX < waveStartPos.x || startX > waveEndPos.x)
{
nup = new Vector3(startX, cenPos.y + py);
}
else
{
var py2 = waveHeight * Mathf.Sin(1 / serie.waveLength * angle + m_WaveSpeed + serie.waveOffset);
var nupY = waveStartPos.y + py2;
nup = new Vector3(startX, nupY);
angle += step;
}
ndp = new Vector3(startX, cenPos.y - vessel.context.height / 2);
if (nup.y > cenPos.y + vessel.context.height / 2)
{
nup.y = cenPos.y + vessel.context.height / 2;
}
if (nup.y < cenPos.y - vessel.context.height / 2)
{
nup.y = cenPos.y - vessel.context.height / 2;
}
if (!ChartHelper.IsValueEqualsColor(color, toColor))
{
var colorMin = cenPos.y - vessel.context.height;
var colorMax = startY + serie.waveHeight;
var tcolor1 = Color32.Lerp(color, toColor, 1 - (lup.y - colorMin) / (colorMax - colorMin));
var tcolor2 = Color32.Lerp(color, toColor, 1 - (ldp.y - colorMin) / (colorMax - colorMin));
UGL.DrawQuadrilateral(vh, lup, nup, ndp, ldp, tcolor1, tcolor2);
}
else
{
UGL.DrawQuadrilateral(vh, lup, nup, ndp, ldp, color);
}
lup = nup;
ldp = ndp;
}
}
if (serie.waveSpeed != 0 && Application.isPlaying && !isFull)
{
chart.RefreshPainter(serie);
}
if (!serie.animation.IsFinish())
{
serie.animation.CheckProgress(realHig);
chart.RefreshPainter(serie);
}
}
}
}

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: afc0f085dba22490b8c727c29271bfe5
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -39,6 +39,7 @@ namespace XCharts.Runtime
/// </summary>
public class ThemeStyle : ChildComponent
{
[SerializeField] private bool m_Show = true;
[SerializeField] private Theme m_SharedTheme;
[SerializeField] private bool m_EnableCustomTheme;
[SerializeField] private Font m_CustomFont;
@@ -48,6 +49,7 @@ namespace XCharts.Runtime
#endif
[SerializeField] private List<Color32> m_CustomColorPalette = new List<Color32>(13);
public bool show { get { return m_Show; } }
/// <summary>
/// the theme of chart.
/// 主题类型。

View File

@@ -1,13 +1,13 @@
using System;
using System.Collections.Generic;
using UnityEngine;
namespace XCharts.Runtime
{
public static class DateTimeUtil
{
private static readonly DateTime k_DateTime1970 = TimeZoneInfo.ConvertTime(new DateTime(1970, 1, 1), TimeZoneInfo.Local);
//private static readonly DateTime k_DateTime1970 = TimeZoneInfo.ConvertTime(new DateTime(1970, 1, 1), TimeZoneInfo.Local);
private static readonly DateTime k_DateTime1970 = new DateTime(1970, 1, 1);
public static readonly int ONE_SECOND = 1;
public static readonly int ONE_MINUTE = ONE_SECOND * 60;
public static readonly int ONE_HOUR = ONE_MINUTE * 60;

View File

@@ -9,10 +9,18 @@ namespace XCharts.Runtime
{
public static class ReflectionUtil
{
private static Dictionary<object, MethodInfo> listClearMethodInfoCaches = new Dictionary<object, MethodInfo>();
private static Dictionary<object, MethodInfo> listAddMethodInfoCaches = new Dictionary<object, MethodInfo>();
public static void InvokeListClear(object obj, FieldInfo field)
{
var list = field.GetValue(obj);
var method = list.GetType().GetMethod("Clear");
MethodInfo method;
if (!listClearMethodInfoCaches.TryGetValue(list, out method))
{
method = list.GetType().GetMethod("Clear");
listClearMethodInfoCaches[list] = method;
}
method.Invoke(list, new object[] { });
}
public static int InvokeListCount(object obj, FieldInfo field)
@@ -24,7 +32,12 @@ namespace XCharts.Runtime
public static void InvokeListAdd(object obj, FieldInfo field, object item)
{
var list = field.GetValue(obj);
var method = list.GetType().GetMethod("Add");
MethodInfo method;
if (!listAddMethodInfoCaches.TryGetValue(list, out method))
{
method = list.GetType().GetMethod("Add");
listAddMethodInfoCaches[list] = method;
}
method.Invoke(list, new object[] { item });
}