增加二维数据支持,XY轴都可以设置为数值轴

This commit is contained in:
monitor1394
2019-07-14 14:34:18 +08:00
parent e0ca33d7cb
commit 9ec5e80d22
15 changed files with 11930 additions and 13223 deletions

View File

@@ -1,5 +1,5 @@
using UnityEditor;
using UnityEditorInternal;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
namespace XCharts
@@ -7,11 +7,12 @@ namespace XCharts
[CustomPropertyDrawer(typeof(Axis), true)]
public class AxisDrawer : PropertyDrawer
{
private bool m_DataFoldout = false;
private List<bool> m_AxisModuleToggle = new List<bool>();
private List<bool> m_DataFoldout = new List<bool>();
private int m_DataSize = 0;
private bool m_ShowJsonDataArea = false;
private string m_JsonDataAreaText;
private bool m_AxisModuleToggle = false;
protected virtual string GetDisplayName(string displayName)
{
@@ -39,9 +40,12 @@ namespace XCharts
SerializedProperty m_Min = prop.FindPropertyRelative("m_Min");
SerializedProperty m_Max = prop.FindPropertyRelative("m_Max");
ChartEditorHelper.MakeFoldout(ref drawRect, ref m_AxisModuleToggle, GetDisplayName(prop.displayName), m_Show);
int index = InitToggle(prop);
bool toggle = m_AxisModuleToggle[index];
m_AxisModuleToggle[index] = ChartEditorHelper.MakeFoldout(ref drawRect, ref toggle,
GetDisplayName(prop.displayName), m_Show);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
if (m_AxisModuleToggle)
if (m_AxisModuleToggle[index])
{
Axis.AxisType type = (Axis.AxisType)m_Type.enumValueIndex;
EditorGUI.indentLevel++;
@@ -108,10 +112,10 @@ namespace XCharts
if (type == Axis.AxisType.Category)
{
drawRect.width = EditorGUIUtility.labelWidth + 10;
m_DataFoldout = EditorGUI.Foldout(drawRect, m_DataFoldout, "Data");
m_DataFoldout[index] = EditorGUI.Foldout(drawRect, m_DataFoldout[index], "Data");
ChartEditorHelper.MakeJsonData(ref drawRect, ref m_ShowJsonDataArea, ref m_JsonDataAreaText, prop);
drawRect.width = pos.width;
if (m_DataFoldout)
if (m_DataFoldout[index])
{
ChartEditorHelper.MakeList(ref drawRect, ref m_DataSize, m_Data);
}
@@ -122,7 +126,8 @@ namespace XCharts
public override float GetPropertyHeight(SerializedProperty prop, GUIContent label)
{
if (!m_AxisModuleToggle)
int index = InitToggle(prop);
if (!m_AxisModuleToggle[index])
{
return EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
}
@@ -139,7 +144,7 @@ namespace XCharts
Axis.AxisType type = (Axis.AxisType)m_Type.enumValueIndex;
if (type == Axis.AxisType.Category)
{
if (m_DataFoldout)
if (m_DataFoldout[index])
{
SerializedProperty m_Data = prop.FindPropertyRelative("m_Data");
int num = m_Data.arraySize + 2;
@@ -172,7 +177,21 @@ namespace XCharts
height += EditorGUI.GetPropertyHeight(m_SplitArea);
return height;
}
}
private int InitToggle(SerializedProperty prop)
{
int index = 0;
int.TryParse(prop.displayName.Split(' ')[1],out index);
if (index >= m_DataFoldout.Count)
{
m_DataFoldout.Add(false);
}
if (index >= m_AxisModuleToggle.Count)
{
m_AxisModuleToggle.Add(false);
}
return index;
}
}
}

View File

@@ -49,7 +49,7 @@ namespace XCharts
float height = 0;
if (m_AxisLabelToggle)
{
height += 8 * EditorGUIUtility.singleLineHeight + 7 * EditorGUIUtility.standardVerticalSpacing;
height += 7 * EditorGUIUtility.singleLineHeight + 6 * EditorGUIUtility.standardVerticalSpacing;
}
return height;
}

View File

@@ -13,6 +13,7 @@ namespace XCharts
Rect drawRect = pos;
drawRect.height = EditorGUIUtility.singleLineHeight;
SerializedProperty show = prop.FindPropertyRelative("m_Show");
SerializedProperty m_OnZero = prop.FindPropertyRelative("m_OnZero");
SerializedProperty m_Symbol = prop.FindPropertyRelative("m_Symbol");
SerializedProperty m_SymbolWidth = prop.FindPropertyRelative("m_SymbolWidth");
SerializedProperty m_SymbolHeight = prop.FindPropertyRelative("m_SymbolHeight");
@@ -24,6 +25,8 @@ namespace XCharts
if (m_AxisLineToggle)
{
++EditorGUI.indentLevel;
EditorGUI.PropertyField(drawRect, m_OnZero);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_Symbol);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_SymbolWidth);
@@ -43,7 +46,7 @@ namespace XCharts
float height = 0;
if (m_AxisLineToggle)
{
height += 5 * EditorGUIUtility.singleLineHeight + 4 * EditorGUIUtility.standardVerticalSpacing;
height += 6 * EditorGUIUtility.singleLineHeight + 7 * EditorGUIUtility.standardVerticalSpacing;
}
return height;
}

View File

@@ -1,4 +1,5 @@
using UnityEditor;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
namespace XCharts
@@ -6,32 +7,34 @@ namespace XCharts
[CustomPropertyDrawer(typeof(Serie), true)]
public class SerieDrawer : PropertyDrawer
{
private bool m_DataFoldout = false;
private List<bool> m_SerieModuleToggle = new List<bool>();
private List<bool> m_DataFoldout = new List<bool>();
private int m_DataSize = 0;
private bool m_ShowJsonDataArea = false;
private string m_JsonDataAreaText;
private bool m_SerieModuleToggle = false;
public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label)
{
Rect drawRect = pos;
drawRect.height = EditorGUIUtility.singleLineHeight;
SerializedProperty show = prop.FindPropertyRelative("m_Show");
//SerializedProperty type = prop.FindPropertyRelative("m_Type");
SerializedProperty type = prop.FindPropertyRelative("m_Type");
SerializedProperty name = prop.FindPropertyRelative("m_Name");
SerializedProperty stack = prop.FindPropertyRelative("m_Stack");
SerializedProperty m_AxisIndex = prop.FindPropertyRelative("m_AxisIndex");
SerializedProperty m_Data = prop.FindPropertyRelative("m_Data");
SerializedProperty m_TwoDimensionData = prop.FindPropertyRelative("m_TwoDimensionData");
SerializedProperty m_XData = prop.FindPropertyRelative("m_XData");
SerializedProperty m_YData = prop.FindPropertyRelative("m_YData");
string moduleName = "Serie " + prop.displayName.Split(' ')[1];
if (!string.IsNullOrEmpty(name.stringValue))
moduleName += ":" + name.stringValue;
m_SerieModuleToggle = EditorGUI.Foldout(drawRect, m_SerieModuleToggle, "Serie");
int index = InitToggle(prop);
string moduleName = "Serie " + index;
bool toggle = m_SerieModuleToggle[index];
m_SerieModuleToggle[index] = ChartEditorHelper.MakeFoldout(ref drawRect, ref toggle, moduleName, show);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
if (m_SerieModuleToggle)
if (m_SerieModuleToggle[index])
{
++EditorGUI.indentLevel;
EditorGUI.PropertyField(drawRect, show);
EditorGUI.PropertyField(drawRect, type);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, name);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
@@ -39,33 +42,101 @@ namespace XCharts
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_AxisIndex);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_TwoDimensionData);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
drawRect.width = EditorGUIUtility.labelWidth + 10;
m_DataFoldout = EditorGUI.Foldout(drawRect, m_DataFoldout, "Data");
m_DataFoldout[index] = EditorGUI.Foldout(drawRect, m_DataFoldout[index], "Data");
ChartEditorHelper.MakeJsonData(ref drawRect, ref m_ShowJsonDataArea, ref m_JsonDataAreaText, prop);
drawRect.width = pos.width;
if (m_DataFoldout)
if (m_DataFoldout[index])
{
ChartEditorHelper.MakeList(ref drawRect, ref m_DataSize, m_Data);
if (m_TwoDimensionData.boolValue)
{
EditorGUI.indentLevel++;
var listSize = m_YData.arraySize;
listSize = EditorGUI.IntField(drawRect, "Size", listSize);
if (listSize < 0) listSize = 0;
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
if (listSize != m_XData.arraySize)
{
while (listSize > m_XData.arraySize)
m_XData.InsertArrayElementAtIndex(m_XData.arraySize);
while (listSize < m_XData.arraySize)
m_XData.DeleteArrayElementAtIndex(m_XData.arraySize - 1);
}
if (listSize != m_YData.arraySize)
{
while (listSize > m_YData.arraySize)
m_YData.InsertArrayElementAtIndex(m_YData.arraySize);
while (listSize < m_YData.arraySize)
m_YData.DeleteArrayElementAtIndex(m_YData.arraySize - 1);
}
if (listSize > 30)
{
int num = listSize > 10 ? 10 : listSize;
for (int i = 0; i < num; i++)
{
DrawTwoDimensionDataElement(ref drawRect, m_XData, m_YData, i);
}
if (num >= 10)
{
EditorGUI.LabelField(drawRect, "...");
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
DrawTwoDimensionDataElement(ref drawRect, m_XData, m_YData, listSize - 1);
}
}
else
{
for (int i = 0; i < m_YData.arraySize; i++)
{
DrawTwoDimensionDataElement(ref drawRect, m_XData, m_YData, i);
}
}
EditorGUI.indentLevel--;
}
else
{
ChartEditorHelper.MakeList(ref drawRect, ref m_DataSize, m_YData);
}
}
--EditorGUI.indentLevel;
}
}
private void DrawTwoDimensionDataElement(ref Rect drawRect, SerializedProperty m_Data1,
SerializedProperty m_Data2, int i)
{
var lastX = drawRect.x;
SerializedProperty element1 = m_Data1.GetArrayElementAtIndex(i);
SerializedProperty element2 = m_Data2.GetArrayElementAtIndex(i);
EditorGUI.LabelField(drawRect, "Element " + i);
var startX = EditorGUIUtility.labelWidth - (EditorGUI.indentLevel - 1) * 15 - 1;
var dataWid = (EditorGUIUtility.currentViewWidth - startX) / 2 + 15;
drawRect.x = startX;
drawRect.width = dataWid;
element1.floatValue = EditorGUI.FloatField(drawRect, element1.floatValue);
drawRect.x += dataWid - 35;
element2.floatValue = EditorGUI.FloatField(drawRect, element2.floatValue);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
drawRect.x = lastX;
}
public override float GetPropertyHeight(SerializedProperty prop, GUIContent label)
{
float height = 0;
if (!m_SerieModuleToggle)
int index = InitToggle(prop);
if (!m_SerieModuleToggle[index])
{
return EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
}
else
{
height += 6 * EditorGUIUtility.singleLineHeight + 5 * EditorGUIUtility.standardVerticalSpacing;
if (m_DataFoldout)
height += 7 * EditorGUIUtility.singleLineHeight + 6 * EditorGUIUtility.standardVerticalSpacing;
if (m_DataFoldout[index])
{
SerializedProperty m_Data = prop.FindPropertyRelative("m_Data");
SerializedProperty m_Data = prop.FindPropertyRelative("m_YData");
int num = m_Data.arraySize + 1;
if (num > 50) num = 13;
if (num > 30) num = 13;
height += num * EditorGUIUtility.singleLineHeight + (num - 1) * EditorGUIUtility.standardVerticalSpacing;
}
if (m_ShowJsonDataArea)
@@ -75,5 +146,20 @@ namespace XCharts
return height;
}
}
private int InitToggle(SerializedProperty prop)
{
int index = 0;
int.TryParse(prop.displayName.Split(' ')[1],out index);
if (index >= m_DataFoldout.Count)
{
m_DataFoldout.Add(false);
}
if (index >= m_SerieModuleToggle.Count)
{
m_SerieModuleToggle.Add(false);
}
return index;
}
}
}

View File

@@ -48,7 +48,7 @@ public class ChartEditorHelper
}
}
public static void MakeFoldout(ref Rect drawRect, ref bool moduleToggle, string content,
public static bool MakeFoldout(ref Rect drawRect, ref bool moduleToggle, string content,
SerializedProperty prop = null, bool bold = true)
{
float defaultWidth = drawRect.width;
@@ -63,6 +63,7 @@ public class ChartEditorHelper
}
drawRect.width = defaultWidth;
drawRect.x = defaultX;
return moduleToggle;
}
public static void MakeList(ref Rect drawRect, ref int listSize, SerializedProperty listProp, SerializedProperty large = null)
@@ -80,7 +81,7 @@ public class ChartEditorHelper
while (listSize < listProp.arraySize)
listProp.DeleteArrayElementAtIndex(listProp.arraySize - 1);
}
if (listSize > 50)
if (listSize > 30)
{
SerializedProperty element;
int num = listSize > 10 ? 10 : listSize;