XCharts 2.0

This commit is contained in:
monitor1394
2021-01-17 22:52:32 +08:00
parent 5c9e52a807
commit f330d2eb7b
6 changed files with 55 additions and 11 deletions

View File

@@ -5,6 +5,7 @@
/* */ /* */
/************************************************/ /************************************************/
using System.Collections.Generic;
using UnityEditor; using UnityEditor;
using UnityEngine; using UnityEngine;
using System.Text; using System.Text;
@@ -45,6 +46,7 @@ namespace XCharts
private bool m_BaseFoldout; private bool m_BaseFoldout;
protected bool m_ShowAllComponent; protected bool m_ShowAllComponent;
protected Dictionary<string, bool> m_Flodouts = new Dictionary<string, bool>();
protected virtual void OnEnable() protected virtual void OnEnable()
{ {
@@ -140,8 +142,6 @@ namespace XCharts
protected virtual void OnDebugInspectorGUI() protected virtual void OnDebugInspectorGUI()
{ {
EditorGUILayout.Space();
EditorGUILayout.Space();
BlockStart(); BlockStart();
EditorGUILayout.PropertyField(m_DebugMode); EditorGUILayout.PropertyField(m_DebugMode);
EditorGUILayout.PropertyField(m_MultiComponentMode); EditorGUILayout.PropertyField(m_MultiComponentMode);
@@ -181,7 +181,46 @@ namespace XCharts
BlockStart(); BlockStart();
foreach (var prop in props) 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); else if (prop.arraySize > 0) EditorGUILayout.PropertyField(prop.GetArrayElementAtIndex(0), true);
} }
BlockEnd(); BlockEnd();
@@ -199,7 +238,7 @@ namespace XCharts
{ {
m_Chart.RemoveChartObject(); m_Chart.RemoveChartObject();
} }
if (GUILayout.Button("Check XCharts Update ")) if (GUILayout.Button("Check XCharts Update"))
{ {
CheckVersionEditor.ShowWindow(); CheckVersionEditor.ShowWindow();
} }

View File

@@ -86,10 +86,9 @@ namespace XCharts
m_DrawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; 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; if (IngorePropertys.Contains(relativePropName)) return;
var height = m_Heights[m_KeyName]; var height = m_Heights[m_KeyName];
var toggleKeyName = m_KeyName + relativePropName; var toggleKeyName = m_KeyName + relativePropName;
m_DataToggles[toggleKeyName] = ChartEditorHelper.MakeListWithFoldout(ref m_DrawRect, ref height, m_DataToggles[toggleKeyName] = ChartEditorHelper.MakeListWithFoldout(ref m_DrawRect, ref height,
@@ -101,6 +100,11 @@ namespace XCharts
protected void PropertyField(SerializedProperty prop, string relativePropName) protected void PropertyField(SerializedProperty prop, string relativePropName)
{ {
if (IngorePropertys.Contains(relativePropName)) return; 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)) if (!ChartEditorHelper.PropertyField(ref m_DrawRect, m_Heights, m_KeyName, prop, relativePropName))
{ {
Debug.LogError("PropertyField ERROR:" + prop.displayName + ", " + relativePropName); Debug.LogError("PropertyField ERROR:" + prop.displayName + ", " + relativePropName);

View File

@@ -29,7 +29,8 @@ namespace XCharts
PropertyField(prop, "m_Location"); PropertyField(prop, "m_Location");
PropertyField(prop, "m_Formatter"); PropertyField(prop, "m_Formatter");
PropertyField(prop, "m_TextStyle"); PropertyField(prop, "m_TextStyle");
PropertyField(prop, "m_Icons"); PropertyListField(prop, "m_Icons");
PropertyListField(prop, "m_Data");
--EditorGUI.indentLevel; --EditorGUI.indentLevel;
} }
} }

View File

@@ -27,8 +27,8 @@ namespace XCharts
PropertyField(prop, "m_Max"); PropertyField(prop, "m_Max");
PropertyField(prop, "m_SplitNumber"); PropertyField(prop, "m_SplitNumber");
PropertyField(prop, "m_Dimension"); PropertyField(prop, "m_Dimension");
PropertyField(prop, "m_InRange"); PropertyListField(prop, "m_InRange");
PropertyField(prop, "m_OutOfRange"); PropertyListField(prop, "m_OutOfRange");
PropertyField(prop, "m_Show"); PropertyField(prop, "m_Show");
if (prop.FindPropertyRelative("m_Show").boolValue) if (prop.FindPropertyRelative("m_Show").boolValue)
{ {

View File

@@ -18,7 +18,7 @@ public class ChartEditorHelper
public const float GAP_WIDTH = 0; public const float GAP_WIDTH = 0;
#endif #endif
private class Styles public class Styles
{ {
public static readonly GUIStyle headerStyle = EditorStyles.boldLabel; public static readonly GUIStyle headerStyle = EditorStyles.boldLabel;
public static readonly GUIStyle foldoutStyle = new GUIStyle(EditorStyles.foldout) public static readonly GUIStyle foldoutStyle = new GUIStyle(EditorStyles.foldout)

View File

@@ -211,7 +211,7 @@ namespace XCharts
/// <summary> /// <summary>
/// 多列时每列的宽度 /// 多列时每列的宽度
/// </summary> /// </summary>
public Dictionary<int, float> runtimeEachWidth { get { return m_RuntimeEachWidth; }} public Dictionary<int, float> runtimeEachWidth { get { return m_RuntimeEachWidth; } }
/// <summary> /// <summary>
/// 单列高度 /// 单列高度
/// </summary> /// </summary>