diff --git a/Editor/Charts/BaseChartEditor.cs b/Editor/Charts/BaseChartEditor.cs index 079d6a50..7b152cf5 100644 --- a/Editor/Charts/BaseChartEditor.cs +++ b/Editor/Charts/BaseChartEditor.cs @@ -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 m_Series = new List(); 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 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 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(); } + } } } diff --git a/Editor/ChildComponents/DebugInfoDrawer.cs b/Editor/ChildComponents/DebugInfoDrawer.cs new file mode 100644 index 00000000..0ddd25c6 --- /dev/null +++ b/Editor/ChildComponents/DebugInfoDrawer.cs @@ -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; + } + } + } +} \ No newline at end of file diff --git a/Runtime/Chart/LiquidChart.cs.meta b/Editor/ChildComponents/DebugInfoDrawer.cs.meta similarity index 83% rename from Runtime/Chart/LiquidChart.cs.meta rename to Editor/ChildComponents/DebugInfoDrawer.cs.meta index c80a4829..34acfda7 100644 --- a/Runtime/Chart/LiquidChart.cs.meta +++ b/Editor/ChildComponents/DebugInfoDrawer.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 41f7e109291bd44de96fccf526e9c7f1 +guid: 99bd61acea264400fb4747b17a2731e4 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Editor/ChildComponents/SettingsDrawer.cs b/Editor/ChildComponents/SettingsDrawer.cs index 88b82c55..8a4b9db7 100644 --- a/Editor/ChildComponents/SettingsDrawer.cs +++ b/Editor/ChildComponents/SettingsDrawer.cs @@ -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(); diff --git a/Editor/ChildComponents/ThemeDrawer.cs b/Editor/ChildComponents/ThemeDrawer.cs index 5e1ec0b9..04bc2d24 100644 --- a/Editor/ChildComponents/ThemeDrawer.cs +++ b/Editor/ChildComponents/ThemeDrawer.cs @@ -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(); diff --git a/Editor/MainComponents/GridCoordEditor.cs b/Editor/MainComponents/GridCoordEditor.cs index 0baccf23..d507a78e 100644 --- a/Editor/MainComponents/GridCoordEditor.cs +++ b/Editor/MainComponents/GridCoordEditor.cs @@ -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; } } diff --git a/Editor/MainComponents/MainComponentBaseEditor.cs b/Editor/MainComponents/MainComponentBaseEditor.cs index a9da0246..1646cd4b 100644 --- a/Editor/MainComponents/MainComponentBaseEditor.cs +++ b/Editor/MainComponents/MainComponentBaseEditor.cs @@ -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"); diff --git a/Editor/MainComponents/MainComponentListEditor.cs b/Editor/MainComponents/MainComponentListEditor.cs index aabb5e2d..68afc0a3 100644 --- a/Editor/MainComponents/MainComponentListEditor.cs +++ b/Editor/MainComponents/MainComponentListEditor.cs @@ -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(); diff --git a/Editor/MainComponents/VesselEditor.cs b/Editor/MainComponents/VesselEditor.cs deleted file mode 100644 index f2a21047..00000000 --- a/Editor/MainComponents/VesselEditor.cs +++ /dev/null @@ -1,36 +0,0 @@ - -using UnityEditor; -using XCharts.Runtime; - -namespace XCharts.Editor -{ - [ComponentEditor(typeof(Vessel))] - public class VesselEditor : MainComponentEditor - { - 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; - } - } -} \ No newline at end of file diff --git a/Editor/MainComponents/VesselEditor.cs.meta b/Editor/MainComponents/VesselEditor.cs.meta deleted file mode 100644 index 446e827a..00000000 --- a/Editor/MainComponents/VesselEditor.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: ffd6706dd3dd048d5ab9c538c133e963 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Editor/Series/LiquidEditor.cs b/Editor/Series/LiquidEditor.cs deleted file mode 100644 index 35c02c6e..00000000 --- a/Editor/Series/LiquidEditor.cs +++ /dev/null @@ -1,22 +0,0 @@ -using XCharts.Runtime; - -namespace XCharts.Editor -{ - [SerieEditor(typeof(Liquid))] - public class LiquidEditor : SerieEditor - { - 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"); - } - } -} \ No newline at end of file diff --git a/Editor/Series/LiquidEditor.cs.meta b/Editor/Series/LiquidEditor.cs.meta deleted file mode 100644 index f15aa0ec..00000000 --- a/Editor/Series/LiquidEditor.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: d62c400d54e9f412abb6a9befbfa3937 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Editor/Series/SerieListEditor.cs b/Editor/Series/SerieListEditor.cs index 38d5c01c..7fbdf4b4 100644 --- a/Editor/Series/SerieListEditor.cs +++ b/Editor/Series/SerieListEditor.cs @@ -20,6 +20,7 @@ namespace XCharts.Editor Dictionary m_EditorTypes; List 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(); diff --git a/Editor/Windows/XChartsEditor.cs b/Editor/Windows/XChartsEditor.cs index 25bc4bc2..a01561b2 100644 --- a/Editor/Windows/XChartsEditor.cs +++ b/Editor/Windows/XChartsEditor.cs @@ -127,13 +127,6 @@ namespace XCharts.Editor AddChart("RingChart"); } - [MenuItem("XCharts/LiquidChart", priority = 53)] - [MenuItem("GameObject/XCharts/LiquidChart", priority = 53)] - public static void AddLiquidChart() - { - AddChart("LiquidChart"); - } - [MenuItem("XCharts/CandlestickChart", priority = 54)] [MenuItem("GameObject/XCharts/CandlestickChart", priority = 54)] public static void CandlestickChart() diff --git a/Runtime/Chart/LiquidChart.cs b/Runtime/Chart/LiquidChart.cs deleted file mode 100644 index 52201805..00000000 --- a/Runtime/Chart/LiquidChart.cs +++ /dev/null @@ -1,27 +0,0 @@ - -using UnityEngine; - -namespace XCharts.Runtime -{ - /// - /// 水位图 - /// - [AddComponentMenu("XCharts/LiquidChart", 22)] - [ExecuteInEditMode] - [RequireComponent(typeof(RectTransform))] - [DisallowMultipleComponent] - public class LiquidChart : BaseChart - { - -#if UNITY_EDITOR - protected override void Reset() - { - base.Reset(); - GetChartComponent().type = Tooltip.Type.Line; - RemoveData(); - - Liquid.AddDefaultSerie(this, GenerateDefaultSerieName()); - } -#endif - } -} diff --git a/Runtime/Component/Axis/AxisHandler.cs b/Runtime/Component/Axis/AxisHandler.cs index 3a33bd89..018e5f6d 100644 --- a/Runtime/Component/Axis/AxisHandler.cs +++ b/Runtime/Component/Axis/AxisHandler.cs @@ -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 : MainComponentHandler where T : Axis diff --git a/Runtime/Component/Debug/DebugInfo.cs b/Runtime/Component/Debug/DebugInfo.cs index 189de8dd..9f160182 100644 --- a/Runtime/Component/Debug/DebugInfo.cs +++ b/Runtime/Component/Debug/DebugInfo.cs @@ -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 m_FpsList = new List(); - + 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(labelGameObject); label.labelBackground = label; diff --git a/Runtime/Component/Settings/Settings.cs b/Runtime/Component/Settings/Settings.cs index 1ab1d0a4..87946f62 100644 --- a/Runtime/Component/Settings/Settings.cs +++ b/Runtime/Component/Settings/Settings.cs @@ -9,8 +9,9 @@ namespace XCharts.Runtime /// 全局参数设置组件。一般情况下可使用默认值,当有需要时可进行调整。 /// [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; } } /// /// 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); } diff --git a/Runtime/Component/Vessel.meta b/Runtime/Component/Vessel.meta deleted file mode 100644 index 1eb0732a..00000000 --- a/Runtime/Component/Vessel.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: cb8cbed03560e47d59d15c19bc6cd11f -folderAsset: yes -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Runtime/Component/Vessel/Vessel.cs b/Runtime/Component/Vessel/Vessel.cs deleted file mode 100644 index ba59752f..00000000 --- a/Runtime/Component/Vessel/Vessel.cs +++ /dev/null @@ -1,198 +0,0 @@ - -using System; -using System.Collections.Generic; -using UnityEngine; - -namespace XCharts.Runtime -{ - /// - /// Vessel component for liquid chart. There can be multiple vessels in a Chart, which can be matched by vesselIndex in Serie. - /// - /// 容器组件。 - /// 一般用于LiquidChart。一个Chart中可以有多个Vessel,Serie中用vesselIndex来对应。 - /// - /// - [Serializable] - [ComponentHandler(typeof(VesselHandler), true)] - public class Vessel : MainComponent, ISerieContainer - { - public enum Shape - { - /// - /// 圆形 - /// - Circle, - /// - /// 正方形。 - /// - Rect, - /// - /// 三角形。 - /// - Triangle, - /// - /// 菱形。 - /// - Diamond, - /// - /// 不显示标记。 - /// - 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(); - - /// - /// Whether to show the vessel. - /// 是否显示容器组件。 - /// [defaut: true] - /// - public bool show - { - get { return m_Show; } - set { if (PropertyUtil.SetStruct(ref m_Show, value)) SetVerticesDirty(); } - } - /// - /// The shape of vessel. - /// 容器形状。 - /// [default: Shape.Circle] - /// - public Shape shape - { - get { return m_Shape; } - set { if (PropertyUtil.SetStruct(ref m_Shape, value)) SetVerticesDirty(); } - } - /// - /// Thickness of vessel. - /// 容器厚度。 - /// [defaut: 5f] - /// - public float shapeWidth - { - get { return m_ShapeWidth; } - set { if (PropertyUtil.SetStruct(ref m_ShapeWidth, value)) SetVerticesDirty(); } - } - /// - /// The gap between the vessel and the liquid. - /// 间隙。容器和液体的间隙。 - /// [defaut: 10f] - /// - public float gap - { - get { return m_Gap; } - set { if (PropertyUtil.SetStruct(ref m_Gap, value)) SetVerticesDirty(); } - } - /// - /// 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]] - /// - public float[] center - { - get { return m_Center; } - set { if (value != null) { m_Center = value; SetAllDirty(); } } - } - /// - /// The radius of vessel. - /// When value between 0 and 1 represents a percentage relative to the chart. - /// 半径。 - /// [default: 0.35f] - /// - public float radius - { - get { return m_Radius; } - set { if (PropertyUtil.SetStruct(ref m_Radius, value)) SetAllDirty(); } - } - /// - /// The width of vessel. - /// When value between 0 and 1 represents a percentage relative to the chart. - /// 容器的宽。shape为Rect时有效。 - /// [default: 0.35f] - /// - public float width - { - get { return m_Width; } - set { if (PropertyUtil.SetStruct(ref m_Width, value)) SetAllDirty(); } - } - /// - /// The height of vessel. - /// When value between 0 and 1 represents a percentage relative to the chart. - /// 容器的高。shape为Rect时有效。 - /// [default: 0.35f] - /// - public float height - { - get { return m_Height; } - set { if (PropertyUtil.SetStruct(ref m_Height, value)) SetAllDirty(); } - } - /// - /// The smoothness of wave. - /// 水波平滑度。 - /// [default: 1f] - /// - public float smoothness - { - get { return m_Smoothness; } - set { if (PropertyUtil.SetStruct(ref m_Smoothness, value)) SetAllDirty(); } - } - /// - /// Background color of polar, which is transparent by default. - /// 背景色,默认透明。 - /// [default: `Color.clear`] - /// - public Color32 backgroundColor - { - get { return m_BackgroundColor; } - set { if (PropertyUtil.SetColor(ref m_BackgroundColor, value)) SetVerticesDirty(); } - } - /// - /// Vessel color. The default is consistent with Serie. - /// 容器颜色。默认和serie一致。 - /// - public Color32 color - { - get { return m_Color; } - set { if (PropertyUtil.SetColor(ref m_Color, value)) SetVerticesDirty(); } - } - /// - /// Whether automatic color. If true, the color matches serie. - /// 是否自动颜色。为true时颜色会和serie一致。 - /// [default: true] - /// - public bool autoColor - { - get { return m_AutoColor; } - set { if (PropertyUtil.SetStruct(ref m_AutoColor, value)) SetVerticesDirty(); } - } - /// - /// 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时有效。 - /// - public float[] cornerRadius - { - get { return m_CornerRadius; } - set { if (PropertyUtil.SetClass(ref m_CornerRadius, value, true)) SetVerticesDirty(); } - } - - public bool IsPointerEnter() - { - return context.isPointerEnter; - } - - } -} \ No newline at end of file diff --git a/Runtime/Component/Vessel/Vessel.cs.meta b/Runtime/Component/Vessel/Vessel.cs.meta deleted file mode 100644 index ff310ce2..00000000 --- a/Runtime/Component/Vessel/Vessel.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 849f583b643a44246b3ec4abd7909b1b -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Runtime/Component/Vessel/VesselContext.cs b/Runtime/Component/Vessel/VesselContext.cs deleted file mode 100644 index 39e8e176..00000000 --- a/Runtime/Component/Vessel/VesselContext.cs +++ /dev/null @@ -1,27 +0,0 @@ - -using UnityEngine; - -namespace XCharts.Runtime -{ - public class VesselContext : MainComponentContext - { - /// - /// the runtime center position of vessel. - /// 运行时中心点。 - /// - public Vector3 center { get; internal set; } - /// - /// the runtime radius of vessel. - /// 运行时半径。 - /// - public float radius { get; internal set; } - /// - /// The actual radius after deducting shapeWidth and gap. - /// 运行时内半径。扣除厚度和间隙后的实际半径。 - /// - public float innerRadius { get; internal set; } - public float width { get; set; } - public float height { get; set; } - public bool isPointerEnter { get; set; } - } -} \ No newline at end of file diff --git a/Runtime/Component/Vessel/VesselContext.cs.meta b/Runtime/Component/Vessel/VesselContext.cs.meta deleted file mode 100644 index 5f3eac97..00000000 --- a/Runtime/Component/Vessel/VesselContext.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: ab0e7ad914ca24fcaa1fe470be695fd2 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Runtime/Component/Vessel/VesselHandler.cs b/Runtime/Component/Vessel/VesselHandler.cs deleted file mode 100644 index 88fa814d..00000000 --- a/Runtime/Component/Vessel/VesselHandler.cs +++ /dev/null @@ -1,24 +0,0 @@ - - -using System; -using System.Collections.Generic; -using UnityEngine; - -namespace XCharts.Runtime -{ - [UnityEngine.Scripting.Preserve] - internal sealed class VesselHandler : MainComponentHandler - { - 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; - } - } -} \ No newline at end of file diff --git a/Runtime/Component/Vessel/VesselHandler.cs.meta b/Runtime/Component/Vessel/VesselHandler.cs.meta deleted file mode 100644 index 02a777fb..00000000 --- a/Runtime/Component/Vessel/VesselHandler.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: d52746e0238ff482589d37ee481394f6 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Runtime/Component/Vessel/VesselHelper.cs b/Runtime/Component/Vessel/VesselHelper.cs deleted file mode 100644 index 8127f29b..00000000 --- a/Runtime/Component/Vessel/VesselHelper.cs +++ /dev/null @@ -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 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; - } - } -} \ No newline at end of file diff --git a/Runtime/Component/Vessel/VesselHelper.cs.meta b/Runtime/Component/Vessel/VesselHelper.cs.meta deleted file mode 100644 index 91f81764..00000000 --- a/Runtime/Component/Vessel/VesselHelper.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 5d0abd225ece74e94b6f84034da63d13 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Runtime/Coord/Grid/GridCoord.cs b/Runtime/Coord/Grid/GridCoord.cs index 69311bc4..efd2a0e8 100644 --- a/Runtime/Coord/Grid/GridCoord.cs +++ b/Runtime/Coord/Grid/GridCoord.cs @@ -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. /// 网格背景色,默认透明。 /// - public Color backgroundColor + public Color32 backgroundColor { get { return m_BackgroundColor; } set { if (PropertyUtil.SetColor(ref m_BackgroundColor, value)) SetVerticesDirty(); } } + /// + /// Whether to show the grid border. + /// 是否显示网格边框。 + /// + public bool showBorder + { + get { return m_ShowBorder; } + set { if (PropertyUtil.SetStruct(ref m_ShowBorder, value)) SetVerticesDirty(); } + } + /// + /// Border width of grid. + /// 网格边框宽。 + /// + public float borderWidth + { + get { return m_BorderWidth; } + set { if (PropertyUtil.SetStruct(ref m_BorderWidth, value)) SetVerticesDirty(); } + } + /// + /// The color of grid border. + /// 网格边框颜色。 + /// + 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) diff --git a/Runtime/Coord/Grid/GridCoordContext.cs b/Runtime/Coord/Grid/GridCoordContext.cs index b5a64cee..43d2220b 100644 --- a/Runtime/Coord/Grid/GridCoordContext.cs +++ b/Runtime/Coord/Grid/GridCoordContext.cs @@ -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; } diff --git a/Runtime/Coord/Grid/GridCoordHandler.cs b/Runtime/Coord/Grid/GridCoordHandler.cs index 0bbc60b5..eace2db8 100644 --- a/Runtime/Coord/Grid/GridCoordHandler.cs +++ b/Runtime/Coord/Grid/GridCoordHandler.cs @@ -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); + } } } } \ No newline at end of file diff --git a/Runtime/Internal/BaseChart.cs b/Runtime/Internal/BaseChart.cs index 42270171..a462cfe0 100644 --- a/Runtime/Internal/BaseChart.cs +++ b/Runtime/Internal/BaseChart.cs @@ -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 m_AngleAxes = new List(); @@ -33,7 +32,6 @@ namespace XCharts.Runtime [SerializeField] [ListForComponent(typeof(RadiusAxis))] private List m_RadiusAxes = new List(); [SerializeField] [ListForComponent(typeof(Title))] private List 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) { diff --git a/Runtime/Internal/BaseGraph.API.cs b/Runtime/Internal/BaseGraph.API.cs index d1973a6c..ad7545ab 100644 --- a/Runtime/Internal/BaseGraph.API.cs +++ b/Runtime/Internal/BaseGraph.API.cs @@ -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) diff --git a/Runtime/Internal/BaseGraph.cs b/Runtime/Internal/BaseGraph.cs index 6194ef32..8d03098c 100644 --- a/Runtime/Internal/BaseGraph.cs +++ b/Runtime/Internal/BaseGraph.cs @@ -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(); } } diff --git a/Runtime/Internal/Basic/MainComponent.cs b/Runtime/Internal/Basic/MainComponent.cs index 3a452725..06813aa3 100644 --- a/Runtime/Internal/Basic/MainComponent.cs +++ b/Runtime/Internal/Basic/MainComponent.cs @@ -53,6 +53,10 @@ namespace XCharts.Runtime m_ComponentDirty = false; } + public virtual void Reset() + { + } + public virtual void ClearData() { } diff --git a/Runtime/Internal/XChartsMgr.cs b/Runtime/Internal/XChartsMgr.cs index 30b1e941..efc68c4e 100644 --- a/Runtime/Internal/XChartsMgr.cs +++ b/Runtime/Internal/XChartsMgr.cs @@ -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(); } } diff --git a/Runtime/Serie/Liquid.meta b/Runtime/Serie/Liquid.meta deleted file mode 100644 index 87fff016..00000000 --- a/Runtime/Serie/Liquid.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 296736becc9a041c8ac957be56db7c8f -folderAsset: yes -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Runtime/Serie/Liquid/Liquid.cs b/Runtime/Serie/Liquid/Liquid.cs deleted file mode 100644 index 5a5526b1..00000000 --- a/Runtime/Serie/Liquid/Liquid.cs +++ /dev/null @@ -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; - } - } -} \ No newline at end of file diff --git a/Runtime/Serie/Liquid/Liquid.cs.meta b/Runtime/Serie/Liquid/Liquid.cs.meta deleted file mode 100644 index 5178d185..00000000 --- a/Runtime/Serie/Liquid/Liquid.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 5695e4d13541046f5b782ee6dfed489a -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Runtime/Serie/Liquid/LiquidHandler.cs b/Runtime/Serie/Liquid/LiquidHandler.cs deleted file mode 100644 index c213368a..00000000 --- a/Runtime/Serie/Liquid/LiquidHandler.cs +++ /dev/null @@ -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); - } - } - } -} \ No newline at end of file diff --git a/Runtime/Serie/Liquid/LiquidHandler.cs.meta b/Runtime/Serie/Liquid/LiquidHandler.cs.meta deleted file mode 100644 index 63d3bbe0..00000000 --- a/Runtime/Serie/Liquid/LiquidHandler.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: afc0f085dba22490b8c727c29271bfe5 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Runtime/Theme/ThemeStyle.cs b/Runtime/Theme/ThemeStyle.cs index 68ce2208..6a7356a3 100644 --- a/Runtime/Theme/ThemeStyle.cs +++ b/Runtime/Theme/ThemeStyle.cs @@ -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. /// 主题类型。 diff --git a/Runtime/Utilities/DateTimeUtil.cs b/Runtime/Utilities/DateTimeUtil.cs index f6e178a6..c9d00bc9 100644 --- a/Runtime/Utilities/DateTimeUtil.cs +++ b/Runtime/Utilities/DateTimeUtil.cs @@ -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; diff --git a/Runtime/Utilities/ReflectionUtil.cs b/Runtime/Utilities/ReflectionUtil.cs index 6c9a7203..d1105bf7 100644 --- a/Runtime/Utilities/ReflectionUtil.cs +++ b/Runtime/Utilities/ReflectionUtil.cs @@ -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 }); }