diff --git a/Demo/Editor.meta b/Demo/Editor.meta
new file mode 100644
index 00000000..dcffc9b7
--- /dev/null
+++ b/Demo/Editor.meta
@@ -0,0 +1,8 @@
+fileFormatVersion: 2
+guid: cc28a4ebefb884f6ab7132e3910b7461
+folderAsset: yes
+DefaultImporter:
+ externalObjects: {}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Demo/Editor/ChartModuleDrawer.cs b/Demo/Editor/ChartModuleDrawer.cs
new file mode 100644
index 00000000..e2715f2f
--- /dev/null
+++ b/Demo/Editor/ChartModuleDrawer.cs
@@ -0,0 +1,40 @@
+using UnityEditor;
+using UnityEngine;
+
+namespace XCharts
+{
+ [CustomPropertyDrawer(typeof(ChartModule), true)]
+ public class ChartModuleDrawer : PropertyDrawer
+ {
+ bool m_BarModuleToggle = true;
+
+ public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label)
+ {
+ Rect drawRect = pos;
+ drawRect.height = EditorGUIUtility.singleLineHeight;
+ var lastX = drawRect.x;
+ var lastWid = drawRect.width;
+ SerializedProperty m_Name = prop.FindPropertyRelative("m_Name");
+ SerializedProperty m_Title = prop.FindPropertyRelative("m_Title");
+ SerializedProperty m_Selected = prop.FindPropertyRelative("m_Selected");
+ SerializedProperty m_Panel = prop.FindPropertyRelative("m_Panel");
+ var fieldWid = EditorGUIUtility.currentViewWidth - 30 - 5 - 50 - 90;
+ drawRect.width = 15;
+ EditorGUI.PropertyField(drawRect,m_Selected,GUIContent.none);
+ drawRect.x += 15;
+ drawRect.width = 50;
+ EditorGUI.PropertyField(drawRect,m_Name,GUIContent.none);
+ drawRect.x += 52;
+ drawRect.width = fieldWid;
+ EditorGUI.PropertyField(drawRect,m_Title,GUIContent.none);
+ drawRect.x += fieldWid + 2;
+ drawRect.width = 90;
+ EditorGUI.PropertyField(drawRect,m_Panel,GUIContent.none);
+ }
+
+ public override float GetPropertyHeight(SerializedProperty prop, GUIContent label)
+ {
+ return 1 * EditorGUIUtility.singleLineHeight + 1 * EditorGUIUtility.standardVerticalSpacing;
+ }
+ }
+}
\ No newline at end of file
diff --git a/Demo/Editor/ChartModuleDrawer.cs.meta b/Demo/Editor/ChartModuleDrawer.cs.meta
new file mode 100644
index 00000000..02bf09b5
--- /dev/null
+++ b/Demo/Editor/ChartModuleDrawer.cs.meta
@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 97c0f1cf754c54fd1913ec5b4129c6e5
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Demo/Editor/DemoEditor.cs b/Demo/Editor/DemoEditor.cs
new file mode 100644
index 00000000..62d5fb30
--- /dev/null
+++ b/Demo/Editor/DemoEditor.cs
@@ -0,0 +1,59 @@
+using UnityEditor;
+using UnityEngine;
+
+namespace XCharts
+{
+ ///
+ /// Editor class used to edit UI BaseChart.
+ ///
+
+ [CustomEditor(typeof(Demo), false)]
+ public class DemoEditor : Editor
+ {
+ protected Demo m_Target;
+ protected SerializedProperty m_Script;
+ protected SerializedProperty m_ButtonNormalColor;
+ protected SerializedProperty m_ButtonSelectedColor;
+ protected SerializedProperty m_ButtonHighlightColor;
+ protected SerializedProperty m_ChartModule;
+ protected virtual void OnEnable()
+ {
+ m_Target = (Demo)target;
+ m_Script = serializedObject.FindProperty("m_Script");
+ m_ButtonNormalColor = serializedObject.FindProperty("m_ButtonNormalColor");
+ m_ButtonSelectedColor = serializedObject.FindProperty("m_ButtonSelectedColor");
+ m_ButtonHighlightColor = serializedObject.FindProperty("m_ButtonHighlightColor");
+ m_ChartModule = serializedObject.FindProperty("m_ChartModule");
+
+ }
+
+ public override void OnInspectorGUI()
+ {
+ if (m_Target == null && target == null)
+ {
+ base.OnInspectorGUI();
+ return;
+ }
+ serializedObject.Update();
+ EditorGUILayout.PropertyField(m_ButtonNormalColor);
+ EditorGUILayout.PropertyField(m_ButtonSelectedColor);
+ EditorGUILayout.PropertyField(m_ButtonHighlightColor);
+
+ var size = m_ChartModule.arraySize;
+ size = EditorGUILayout.IntField("Chart Module Size", size);
+ if (size != m_ChartModule.arraySize)
+ {
+ while (size > m_ChartModule.arraySize)
+ m_ChartModule.InsertArrayElementAtIndex(m_ChartModule.arraySize);
+ while (size < m_ChartModule.arraySize)
+ m_ChartModule.DeleteArrayElementAtIndex(m_ChartModule.arraySize - 1);
+ }
+ for (int i = 0; i < size; i++)
+ {
+ EditorGUILayout.PropertyField(m_ChartModule.GetArrayElementAtIndex(i));
+ }
+
+ serializedObject.ApplyModifiedProperties();
+ }
+ }
+}
\ No newline at end of file
diff --git a/Demo/Editor/DemoEditor.cs.meta b/Demo/Editor/DemoEditor.cs.meta
new file mode 100644
index 00000000..207a1834
--- /dev/null
+++ b/Demo/Editor/DemoEditor.cs.meta
@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: bc37c9f35cd6b4f0f936526a63fb19a5
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Demo/Scripts/Demo.cs b/Demo/Scripts/Demo.cs
index 7019d805..fad9e3a6 100644
--- a/Demo/Scripts/Demo.cs
+++ b/Demo/Scripts/Demo.cs
@@ -1,36 +1,44 @@
-using UnityEngine;
+using System.Linq;
+using System.Collections.Generic;
+using UnityEngine;
+using UnityEngine.EventSystems;
using UnityEngine.UI;
using XCharts;
+
+[System.Serializable]
+public class ChartModule
+{
+ [SerializeField] private string m_Name;
+ [SerializeField] private string m_Title;
+ [SerializeField] private bool m_Selected;
+ [SerializeField] private GameObject m_Panel;
+
+ public string name { get { return m_Name; } set { m_Name = value; } }
+ public string title { get { return m_Title; } set { m_Title = value; } }
+ public bool select { get { return m_Selected; } set { m_Selected = value; } }
+ public GameObject panel { get { return m_Panel; } set { m_Panel = value; } }
+ public Button button { get; set; }
+}
+
[DisallowMultipleComponent]
[ExecuteInEditMode]
public class Demo : MonoBehaviour
{
- private Theme m_SelectedTheme;
- private GameObject m_SelectedModule;
+ [SerializeField] private Color m_ButtonNormalColor;
+ [SerializeField] private Color m_ButtonSelectedColor;
+ [SerializeField] private Color m_ButtonHighlightColor;
+ [SerializeField] private List m_ChartModule;
- private GameObject m_LineChartModule;
- private GameObject m_BarChartModule;
- private GameObject m_PieChartModule;
- private GameObject m_RadarChartModule;
- private GameObject m_ScatterChartModule;
- private GameObject m_OtherModule;
+ private GameObject m_BtnClone;
+ private Theme m_SelectedTheme;
+ private int m_LastSelectedModuleIndex;
private Button m_DefaultThemeButton;
private Button m_LightThemeButton;
private Button m_DarkThemeButton;
- private Button m_LineChartButton;
- private Button m_BarChartButton;
- private Button m_PieChartButton;
- private Button m_RadarChartButton;
- private Button m_ScatterChartButton;
- private Button m_OtherButton;
-
private Text m_Title;
- private Color m_NormalColor;
- private Color m_SelectedColor;
- private Color m_HighlightColor;
private ScrollRect m_ScrollRect;
private Mask m_Mark;
@@ -39,58 +47,116 @@ public class Demo : MonoBehaviour
{
m_SelectedTheme = Theme.Default;
- m_NormalColor = ChartHelper.GetColor("#293C55FF");
- m_SelectedColor = ChartHelper.GetColor("#e43c59ff");
- m_HighlightColor = ChartHelper.GetColor("#0E151FFF");
+ m_ButtonNormalColor = ChartHelper.GetColor("#293C55FF");
+ m_ButtonSelectedColor = ChartHelper.GetColor("#e43c59ff");
+ m_ButtonHighlightColor = ChartHelper.GetColor("#0E151FFF");
m_ScrollRect = transform.Find("chart_detail").GetComponent();
-
- m_LineChartModule = transform.Find("chart_detail/Viewport/line_chart").gameObject;
- m_BarChartModule = transform.Find("chart_detail/Viewport/bar_chart").gameObject;
- m_PieChartModule = transform.Find("chart_detail/Viewport/pie_chart").gameObject;
- m_RadarChartModule = transform.Find("chart_detail/Viewport/radar_chart").gameObject;
- m_ScatterChartModule = transform.Find("chart_detail/Viewport/scatter_chart").gameObject;
- m_OtherModule = transform.Find("chart_detail/Viewport/other").gameObject;
m_Mark = transform.Find("chart_detail/Viewport").GetComponent();
m_Mark.enabled = true;
-
m_Title = transform.Find("chart_title/Text").GetComponent();
-
- // LineChart[] charts = m_LineChartModule.GetComponentsInChildren();
- // foreach(var chart in charts){
- // foreach(var serie in chart.series.series){
- // serie.symbol.type = SerieSymbolType.EmptyCircle;
- // serie.symbol.size = 4;
- // serie.symbol.selectedSize = 6;
- // }
- // }
InitThemeButton();
- InitChartButton();
+ InitModuleButton();
}
void Update()
{
-
+#if UNITY_EDITOR
+ if (m_ChartModule.Count <= 0) return;
+ int selectedModuleIndex = -1;
+ for (int i = 0; i < m_ChartModule.Count; i++)
+ {
+ if (selectedModuleIndex >= 0 && i > selectedModuleIndex)
+ {
+ m_ChartModule[i].select = false;
+ }
+ else if (m_ChartModule[i].select)
+ {
+ selectedModuleIndex = i;
+ }
+ }
+ if (selectedModuleIndex < 0) selectedModuleIndex = 0;
+ if (selectedModuleIndex != m_LastSelectedModuleIndex)
+ {
+ InitModuleButton();
+ }
+#endif
}
- void InitChartButton()
+ void InitModuleButton()
{
- m_LineChartButton = transform.Find("chart_list/btn_linechart").GetComponent