Skip to content

Commit

Permalink
XCharts 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
monitor1394 committed Jan 17, 2021
1 parent 5c9e52a commit f330d2e
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 11 deletions.
47 changes: 43 additions & 4 deletions Assets/XCharts/Editor/BaseChartEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
/* */
/************************************************/

using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
using System.Text;
Expand Down Expand Up @@ -45,6 +46,7 @@ public class BaseChartEditor : Editor

private bool m_BaseFoldout;
protected bool m_ShowAllComponent;
protected Dictionary<string, bool> m_Flodouts = new Dictionary<string, bool>();

protected virtual void OnEnable()
{
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand All @@ -199,7 +238,7 @@ private void CheckWarning()
{
m_Chart.RemoveChartObject();
}
if (GUILayout.Button("Check XCharts Update "))
if (GUILayout.Button("Check XCharts Update"))
{
CheckVersionEditor.ShowWindow();
}
Expand Down
8 changes: 6 additions & 2 deletions Assets/XCharts/Editor/PropertyDrawers/BasePropertyDrawer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion Assets/XCharts/Editor/PropertyDrawers/LegendDrawer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
4 changes: 2 additions & 2 deletions Assets/XCharts/Editor/PropertyDrawers/VisualMapDrawer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
2 changes: 1 addition & 1 deletion Assets/XCharts/Editor/Utility/ChartEditorHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion Assets/XCharts/Runtime/Component/Main/Legend.cs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ internal override void ClearComponentDirty()
/// <summary>
/// 多列时每列的宽度
/// </summary>
public Dictionary<int, float> runtimeEachWidth { get { return m_RuntimeEachWidth; }}
public Dictionary<int, float> runtimeEachWidth { get { return m_RuntimeEachWidth; } }
/// <summary>
/// 单列高度
/// </summary>
Expand Down

0 comments on commit f330d2e

Please sign in to comment.