From f330d2eb7b163e3c8f91d7c64944a67b7bb00f27 Mon Sep 17 00:00:00 2001 From: monitor1394 Date: Sun, 17 Jan 2021 22:52:32 +0800 Subject: [PATCH] XCharts 2.0 --- Assets/XCharts/Editor/BaseChartEditor.cs | 47 +++++++++++++++++-- .../PropertyDrawers/BasePropertyDrawer.cs | 8 +++- .../Editor/PropertyDrawers/LegendDrawer.cs | 3 +- .../Editor/PropertyDrawers/VisualMapDrawer.cs | 4 +- .../Editor/Utility/ChartEditorHelper.cs | 2 +- .../XCharts/Runtime/Component/Main/Legend.cs | 2 +- 6 files changed, 55 insertions(+), 11 deletions(-) diff --git a/Assets/XCharts/Editor/BaseChartEditor.cs b/Assets/XCharts/Editor/BaseChartEditor.cs index 6da03eb9..3da65679 100644 --- a/Assets/XCharts/Editor/BaseChartEditor.cs +++ b/Assets/XCharts/Editor/BaseChartEditor.cs @@ -5,6 +5,7 @@ /* */ /************************************************/ +using System.Collections.Generic; using UnityEditor; using UnityEngine; using System.Text; @@ -45,6 +46,7 @@ public class BaseChartEditor : Editor private bool m_BaseFoldout; protected bool m_ShowAllComponent; + protected Dictionary m_Flodouts = new Dictionary(); protected virtual void OnEnable() { @@ -140,8 +142,6 @@ protected virtual void OnEndInspectorGUI() protected virtual void OnDebugInspectorGUI() { - EditorGUILayout.Space(); - EditorGUILayout.Space(); BlockStart(); EditorGUILayout.PropertyField(m_DebugMode); EditorGUILayout.PropertyField(m_MultiComponentMode); @@ -181,7 +181,46 @@ protected void BlockListField(bool all, params SerializedProperty[] props) BlockStart(); foreach (var prop in props) { - if (all) EditorGUILayout.PropertyField(prop, true); + if (all) + { + var flag = m_Flodouts.ContainsKey(prop.displayName) && m_Flodouts[prop.displayName]; + m_Flodouts[prop.displayName] = EditorGUILayout.Foldout(flag, prop.displayName); + if (m_Flodouts[prop.displayName]) + { + EditorGUI.indentLevel++; + prop.arraySize = EditorGUILayout.IntField("Size", prop.arraySize); + for (int i = 0; i < prop.arraySize; i++) + { + SerializedProperty element = prop.GetArrayElementAtIndex(i); + var currRect = EditorGUILayout.GetControlRect(); + var iconWidth = 14; + var iconGap = 0f; + var xDiff = 10f; + var yDiff = 3f; + var rect1 = new Rect(currRect.width + xDiff, currRect.y + yDiff, + iconWidth, EditorGUIUtility.singleLineHeight); + if (GUI.Button(rect1, ChartEditorHelper.Styles.iconRemove, ChartEditorHelper.Styles.invisibleButton)) + { + if (i < prop.arraySize && i >= 0) prop.DeleteArrayElementAtIndex(i); + } + var rect2 = new Rect(currRect.width + xDiff - iconWidth - iconGap, currRect.y + yDiff, + iconWidth, EditorGUIUtility.singleLineHeight); + if (GUI.Button(rect2, ChartEditorHelper.Styles.iconDown, ChartEditorHelper.Styles.invisibleButton)) + { + if (i < prop.arraySize - 1) prop.MoveArrayElement(i, i + 1); + } + var rect3 = new Rect(currRect.width + xDiff - 2 * (iconWidth + iconGap), currRect.y + yDiff, + iconWidth, EditorGUIUtility.singleLineHeight); + if (GUI.Button(rect3, ChartEditorHelper.Styles.iconUp, ChartEditorHelper.Styles.invisibleButton)) + { + if (i > 0) prop.MoveArrayElement(i, i - 1); + } + EditorGUILayout.Space(-EditorGUIUtility.singleLineHeight - EditorGUIUtility.standardVerticalSpacing); + EditorGUILayout.PropertyField(element, true); + } + EditorGUI.indentLevel--; + } + } else if (prop.arraySize > 0) EditorGUILayout.PropertyField(prop.GetArrayElementAtIndex(0), true); } BlockEnd(); @@ -199,7 +238,7 @@ private void CheckWarning() { m_Chart.RemoveChartObject(); } - if (GUILayout.Button("Check XCharts Update ")) + if (GUILayout.Button("Check XCharts Update")) { CheckVersionEditor.ShowWindow(); } diff --git a/Assets/XCharts/Editor/PropertyDrawers/BasePropertyDrawer.cs b/Assets/XCharts/Editor/PropertyDrawers/BasePropertyDrawer.cs index 81fe50a6..6883fcab 100644 --- a/Assets/XCharts/Editor/PropertyDrawers/BasePropertyDrawer.cs +++ b/Assets/XCharts/Editor/PropertyDrawers/BasePropertyDrawer.cs @@ -86,10 +86,9 @@ protected void AddSingleLineHeight() m_DrawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; } - protected void PropertyListField(SerializedProperty prop, string relativePropName, bool showOrder = false) + protected void PropertyListField(SerializedProperty prop, string relativePropName, bool showOrder = true) { if (IngorePropertys.Contains(relativePropName)) return; - var height = m_Heights[m_KeyName]; var toggleKeyName = m_KeyName + relativePropName; m_DataToggles[toggleKeyName] = ChartEditorHelper.MakeListWithFoldout(ref m_DrawRect, ref height, @@ -101,6 +100,11 @@ protected void PropertyListField(SerializedProperty prop, string relativePropNam protected void PropertyField(SerializedProperty prop, string relativePropName) { if (IngorePropertys.Contains(relativePropName)) return; + if (prop.FindPropertyRelative(relativePropName).isArray) + { + PropertyListField(prop, relativePropName); + return; + } if (!ChartEditorHelper.PropertyField(ref m_DrawRect, m_Heights, m_KeyName, prop, relativePropName)) { Debug.LogError("PropertyField ERROR:" + prop.displayName + ", " + relativePropName); diff --git a/Assets/XCharts/Editor/PropertyDrawers/LegendDrawer.cs b/Assets/XCharts/Editor/PropertyDrawers/LegendDrawer.cs index b7c3723b..09dc977a 100644 --- a/Assets/XCharts/Editor/PropertyDrawers/LegendDrawer.cs +++ b/Assets/XCharts/Editor/PropertyDrawers/LegendDrawer.cs @@ -29,7 +29,8 @@ public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label) PropertyField(prop, "m_Location"); PropertyField(prop, "m_Formatter"); PropertyField(prop, "m_TextStyle"); - PropertyField(prop, "m_Icons"); + PropertyListField(prop, "m_Icons"); + PropertyListField(prop, "m_Data"); --EditorGUI.indentLevel; } } diff --git a/Assets/XCharts/Editor/PropertyDrawers/VisualMapDrawer.cs b/Assets/XCharts/Editor/PropertyDrawers/VisualMapDrawer.cs index d2110e9f..4c736a5d 100644 --- a/Assets/XCharts/Editor/PropertyDrawers/VisualMapDrawer.cs +++ b/Assets/XCharts/Editor/PropertyDrawers/VisualMapDrawer.cs @@ -27,8 +27,8 @@ public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label) PropertyField(prop, "m_Max"); PropertyField(prop, "m_SplitNumber"); PropertyField(prop, "m_Dimension"); - PropertyField(prop, "m_InRange"); - PropertyField(prop, "m_OutOfRange"); + PropertyListField(prop, "m_InRange"); + PropertyListField(prop, "m_OutOfRange"); PropertyField(prop, "m_Show"); if (prop.FindPropertyRelative("m_Show").boolValue) { diff --git a/Assets/XCharts/Editor/Utility/ChartEditorHelper.cs b/Assets/XCharts/Editor/Utility/ChartEditorHelper.cs index 6831a109..9267929a 100644 --- a/Assets/XCharts/Editor/Utility/ChartEditorHelper.cs +++ b/Assets/XCharts/Editor/Utility/ChartEditorHelper.cs @@ -18,7 +18,7 @@ public class ChartEditorHelper public const float GAP_WIDTH = 0; #endif - private class Styles + public class Styles { public static readonly GUIStyle headerStyle = EditorStyles.boldLabel; public static readonly GUIStyle foldoutStyle = new GUIStyle(EditorStyles.foldout) diff --git a/Assets/XCharts/Runtime/Component/Main/Legend.cs b/Assets/XCharts/Runtime/Component/Main/Legend.cs index 8c5d5cef..f4bb1336 100644 --- a/Assets/XCharts/Runtime/Component/Main/Legend.cs +++ b/Assets/XCharts/Runtime/Component/Main/Legend.cs @@ -211,7 +211,7 @@ internal override void ClearComponentDirty() /// /// 多列时每列的宽度 /// - public Dictionary runtimeEachWidth { get { return m_RuntimeEachWidth; }} + public Dictionary runtimeEachWidth { get { return m_RuntimeEachWidth; } } /// /// 单列高度 ///