3.0 - unitypackage

This commit is contained in:
monitor1394
2022-01-05 21:40:48 +08:00
parent c160867765
commit 228a4b2840
846 changed files with 105 additions and 467693 deletions

View File

@@ -0,0 +1,46 @@
namespace XCharts.Editor
{
[SerieEditor(typeof(Bar))]
public class BarEditor : SerieEditor<Bar>
{
public override void OnCustomInspectorGUI()
{
PropertyField("m_Stack");
if (serie.IsUseCoord<PolarCoord>())
{
PropertyField("m_PolarIndex");
}
else
{
PropertyField("m_XAxisIndex");
PropertyField("m_YAxisIndex");
}
PropertyField("m_BarType");
PropertyField("m_BarPercentStack");
PropertyField("m_BarWidth");
PropertyField("m_BarGap");
if (serie.barType == BarType.Zebra)
{
PropertyField("m_BarZebraWidth");
PropertyField("m_BarZebraGap");
}
PropertyFiledMore(() =>
{
PropertyFieldLimitMin("m_MinShow", 0);
PropertyFieldLimitMin("m_MaxShow", 0);
PropertyFieldLimitMin("m_MaxCache", 0);
PropertyField("m_Ignore");
PropertyField("m_IgnoreValue");
PropertyField("m_IgnoreLineBreak");
PropertyField("m_ShowAsPositiveNumber");
PropertyField("m_Large");
PropertyField("m_LargeThreshold");
PropertyField("m_Clip");
});
PropertyField("m_ItemStyle");
PropertyField("m_Animation");
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 3b924d2e0412243769e4ac6ee8bd5fa6
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,24 @@
namespace XCharts.Editor
{
[SerieEditor(typeof(Candlestick))]
public class CandlestickEditor : SerieEditor<Candlestick>
{
public override void OnCustomInspectorGUI()
{
PropertyField("m_XAxisIndex");
PropertyField("m_YAxisIndex");
PropertyFieldLimitMin("m_MinShow", 0);
PropertyFieldLimitMin("m_MaxShow", 0);
PropertyFieldLimitMin("m_MaxCache", 0);
PropertyField("m_BarWidth");
PropertyField("m_Clip");
PropertyField("m_ShowAsPositiveNumber");
PropertyField("m_Large");
PropertyField("m_LargeThreshold");
PropertyField("m_ItemStyle");
PropertyField("m_Animation");
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 713afd224d3194435b9559720035a5fb
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,26 @@
namespace XCharts.Editor
{
[SerieEditor(typeof(EffectScatter))]
public class EffectScatterEditor : SerieEditor<EffectScatter>
{
public override void OnCustomInspectorGUI()
{
if (serie.IsUseCoord<SingleAxisCoord>())
{
PropertyField("m_SingleAxisIndex");
}
else
{
PropertyField("m_XAxisIndex");
PropertyField("m_YAxisIndex");
}
PropertyField("m_Clip");
PropertyField("m_Symbol");
PropertyField("m_ItemStyle");
PropertyField("m_Animation");
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: fc8fce25209234fa3b6c3cb79d02b47e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,17 @@
namespace XCharts.Editor
{
[SerieEditor(typeof(Heatmap))]
public class HeatmapEditor : SerieEditor<Heatmap>
{
public override void OnCustomInspectorGUI()
{
PropertyField("m_Ignore");
PropertyField("m_IgnoreValue");
PropertyField("m_ItemStyle");
PropertyField("m_Animation");
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 3137acf1aff4f4cd29af0d3c3ca78bca
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,43 @@
namespace XCharts.Editor
{
[SerieEditor(typeof(Line))]
public class LineEditor : SerieEditor<Line>
{
public override void OnCustomInspectorGUI()
{
PropertyField("m_Stack");
if (serie.IsUseCoord<PolarCoord>())
{
PropertyField("m_PolarIndex");
}
else
{
PropertyField("m_XAxisIndex");
PropertyField("m_YAxisIndex");
}
PropertyField("m_LineType");
PropertyFiledMore(() =>
{
PropertyFieldLimitMin("m_MinShow", 0);
PropertyFieldLimitMin("m_MaxShow", 0);
PropertyFieldLimitMin("m_MaxCache", 0);
PropertyField("m_SampleDist");
PropertyField("m_SampleType");
PropertyField("m_SampleAverage");
PropertyField("m_Ignore");
PropertyField("m_IgnoreValue");
PropertyField("m_IgnoreLineBreak");
PropertyField("m_ShowAsPositiveNumber");
PropertyField("m_Large");
PropertyField("m_LargeThreshold");
PropertyField("m_Clip");
});
PropertyField("m_Symbol");
PropertyField("m_LineStyle");
PropertyField("m_ItemStyle");
PropertyField("m_Animation");
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 065fbd043ce6e40609cfb52114aaaa6a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,22 @@
namespace XCharts.Editor
{
[SerieEditor(typeof(Liquid))]
public class LiquidEditor : SerieEditor<Liquid>
{
public override void OnCustomInspectorGUI()
{
PropertyField("m_VesselIndex");
PropertyField("m_Min");
PropertyField("m_Max");
PropertyField("m_WaveLength");
PropertyField("m_WaveHeight");
PropertyField("m_WaveSpeed");
PropertyField("m_WaveOffset");
PropertyField("m_ItemStyle");
PropertyField("m_Animation");
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: d62c400d54e9f412abb6a9befbfa3937
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,16 @@
namespace XCharts.Editor
{
[SerieEditor(typeof(Parallel))]
public class ParallelEditor : SerieEditor<Parallel>
{
public override void OnCustomInspectorGUI()
{
PropertyField("m_ParallelIndex");
PropertyField("m_LineType");
PropertyField("m_LineStyle");
PropertyField("m_Animation");
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 01af34b37a31d4876bd2d9ca7687ccd1
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,28 @@
namespace XCharts.Editor
{
[SerieEditor(typeof(Pie))]
public class PieEditor : SerieEditor<Pie>
{
public override void OnCustomInspectorGUI()
{
PropertyField("m_RoseType");
PropertyField("m_Space");
PropertyTwoFiled("m_Center");
PropertyTwoFiled("m_Radius");
PropertyFiledMore(() =>
{
PropertyField("m_MinAngle");
PropertyField("m_RoundCap");
PropertyField("m_Ignore");
PropertyField("m_IgnoreValue");
PropertyField("m_AvoidLabelOverlap");
});
PropertyField("m_ItemStyle");
PropertyField("m_Animation");
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 3e7ae042a30a3433d8ae63a82bf37278
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,19 @@
namespace XCharts.Editor
{
[SerieEditor(typeof(Radar))]
public class RadarEditor : SerieEditor<Radar>
{
public override void OnCustomInspectorGUI()
{
PropertyField("m_RadarType");
PropertyField("m_RadarIndex");
PropertyField("m_Symbol");
PropertyField("m_LineStyle");
PropertyField("m_ItemStyle");
PropertyField("m_Animation");
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 7b6a9ab6dd1ea4e3a98bef73e90d42a9
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,22 @@
namespace XCharts.Editor
{
[SerieEditor(typeof(Ring))]
public class RingEditor : SerieEditor<Ring>
{
public override void OnCustomInspectorGUI()
{
PropertyTwoFiled("m_Center");
PropertyTwoFiled("m_Radius");
PropertyField("m_StartAngle");
PropertyField("m_RingGap");
PropertyField("m_RoundCap");
PropertyField("m_Clockwise");
PropertyField("m_TitleStyle");
PropertyField("m_ItemStyle");
PropertyField("m_Animation");
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 647f8e564429a4b76833d3b428f5ab13
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,26 @@
namespace XCharts.Editor
{
[SerieEditor(typeof(Scatter))]
public class ScatterEditor : SerieEditor<Scatter>
{
public override void OnCustomInspectorGUI()
{
if (serie.IsUseCoord<SingleAxisCoord>())
{
PropertyField("m_SingleAxisIndex");
}
else
{
PropertyField("m_XAxisIndex");
PropertyField("m_YAxisIndex");
}
PropertyField("m_Clip");
PropertyField("m_Symbol");
PropertyField("m_ItemStyle");
PropertyField("m_Animation");
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 3dfef7780c8cc412f87d00e437c94715
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,160 @@
using System;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
using UnityEngine.Assertions;
namespace XCharts.Editor
{
public class SerieBaseEditor
{
internal BaseChart chart { get; private set; }
internal Serie serie { get; private set; }
//Editor m_Inspector;
internal SerializedProperty baseProperty;
internal SerializedProperty showProperty;
internal List<HeaderMenuInfo> menus = new List<HeaderMenuInfo>();
protected Dictionary<string, Type> m_CoordOptionsDic;
protected List<string> m_CoordOptionsNames;
internal void Init(BaseChart chart, Serie target, SerializedProperty property, UnityEditor.Editor inspector)
{
this.chart = chart;
this.serie = target;
this.baseProperty = property;
//m_Inspector = inspector;
showProperty = baseProperty.FindPropertyRelative("m_Show");
if (showProperty == null)
showProperty = baseProperty.FindPropertyRelative("m_Enable");
OnEnable();
if (serie.GetType().IsDefined(typeof(CoordOptionsAttribute), false))
{
var attribute = serie.GetType().GetAttribute<CoordOptionsAttribute>();
m_CoordOptionsDic = new Dictionary<string, Type>();
m_CoordOptionsNames = new List<string>();
if (attribute.type0 != null)
{
m_CoordOptionsDic[attribute.type0.Name] = attribute.type0;
m_CoordOptionsNames.Add(attribute.type0.Name);
}
if (attribute.type1 != null)
{
m_CoordOptionsDic[attribute.type1.Name] = attribute.type1;
m_CoordOptionsNames.Add(attribute.type1.Name);
}
if (attribute.type2 != null)
{
m_CoordOptionsDic[attribute.type2.Name] = attribute.type2;
m_CoordOptionsNames.Add(attribute.type2.Name);
}
if (attribute.type3 != null)
{
m_CoordOptionsDic[attribute.type3.Name] = attribute.type3;
m_CoordOptionsNames.Add(attribute.type3.Name);
}
}
}
public virtual void OnEnable()
{
}
public virtual void OnDisable()
{
}
internal void OnInternalInspectorGUI()
{
OnInspectorGUI();
EditorGUILayout.Space();
}
public virtual void OnInspectorGUI()
{
}
protected virtual void DrawExtendeds()
{
}
public virtual string GetDisplayTitle()
{
var title = string.Format("serie {0}: {1}", serie.index, serie.GetType().Name);
return ObjectNames.NicifyVariableName(title);
}
internal SerializedProperty FindProperty(string path)
{
return baseProperty.FindPropertyRelative(path);
}
protected SerializedProperty PropertyField(string path)
{
Assert.IsNotNull(path);
var property = FindProperty(path);
Assert.IsNotNull(property, "Can't find:" + path);
var title = ChartEditorHelper.GetContent(property.displayName);
PropertyField(property, title);
return property;
}
protected void PropertyField(SerializedProperty property)
{
Assert.IsNotNull(property);
var title = ChartEditorHelper.GetContent(property.displayName);
PropertyField(property, title);
}
protected void PropertyField(SerializedProperty property, GUIContent title)
{
EditorGUILayout.PropertyField(property, title);
}
protected void PropertyListField(string relativePropName, bool showOrder = true)
{
//TODO:
PropertyField(relativePropName);
}
protected void PropertyTwoFiled(string relativePropName)
{
var m_DrawRect = GUILayoutUtility.GetRect(1f, 17f);
var prop = FindProperty(relativePropName);
ChartEditorHelper.MakeTwoField(ref m_DrawRect, m_DrawRect.width, prop, prop.displayName);
}
protected void PropertyFieldLimitMin(string relativePropName, double min)
{
var prop = PropertyField(relativePropName);
switch (prop.propertyType)
{
case SerializedPropertyType.Float:
if (prop.floatValue < min)
prop.floatValue = (float)min;
break;
case SerializedPropertyType.Integer:
if (prop.intValue < min)
prop.intValue = (int)min;
break;
}
}
protected void PropertyFieldLimitMax(string relativePropName, int max)
{
var prop = PropertyField(relativePropName);
switch (prop.propertyType)
{
case SerializedPropertyType.Float:
if (prop.floatValue > max)
prop.floatValue = (float)max;
break;
case SerializedPropertyType.Integer:
if (prop.intValue > max)
prop.intValue = (int)max;
break;
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 991edc42b5abf429b8062fd202278a4d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,272 @@
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
namespace XCharts.Editor
{
public class SerieEditor<T> : SerieBaseEditor where T : Serie
{
protected const string MORE = "More";
protected bool m_MoreFoldout = false;
private bool m_DataFoldout = false;
private bool m_DataComponentFoldout = true;
private Dictionary<int, bool> m_DataElementFoldout = new Dictionary<int, bool>();
public override void OnInspectorGUI()
{
++EditorGUI.indentLevel;
//PropertyField("m_InsertDataToHead");
PropertyField("m_SerieName");
if (m_CoordOptionsNames != null && m_CoordOptionsNames.Count > 1)
{
var index = m_CoordOptionsNames.IndexOf(serie.coordSystem);
var selectedIndex = EditorGUILayout.Popup("Coord System", index, m_CoordOptionsNames.ToArray());
if (selectedIndex != index)
{
var typeName = m_CoordOptionsNames[selectedIndex];
serie.coordSystem = m_CoordOptionsDic[typeName].Name;
}
}
OnCustomInspectorGUI();
OnExtraInspectorGUI();
PropertyFieldData();
--EditorGUI.indentLevel;
}
public virtual void OnCustomInspectorGUI()
{
}
private void OnExtraInspectorGUI()
{
foreach (var kv in Serie.extraComponentFieldNameDict)
{
var prop = FindProperty(kv.Value);
if (prop.arraySize > 0)
PropertyField(prop.GetArrayElementAtIndex(0));
}
}
private void PropertyFieldData()
{
m_DataFoldout = ChartEditorHelper.DrawHeader("Data", m_DataFoldout, false, null, null,
new HeaderMenuInfo("Import ECharts Data", () =>
{
PraseExternalDataEditor.UpdateData(chart, serie, null);
PraseExternalDataEditor.ShowWindow();
}));
if (!m_DataFoldout) return;
EditorGUI.indentLevel++;
var m_Datas = FindProperty("m_Data");
var m_DataDimension = FindProperty("m_ShowDataDimension");
var m_ShowDataName = FindProperty("m_ShowDataName");
PropertyField(m_ShowDataName);
PropertyField(m_DataDimension);
var listSize = m_Datas.arraySize;
listSize = EditorGUILayout.IntField("Size", listSize);
if (listSize < 0) listSize = 0;
if (m_DataDimension.intValue < 1) m_DataDimension.intValue = 1;
int dimension = m_DataDimension.intValue;
bool showName = m_ShowDataName.boolValue;
if (listSize != m_Datas.arraySize)
{
while (listSize > m_Datas.arraySize) m_Datas.arraySize++;
while (listSize < m_Datas.arraySize) m_Datas.arraySize--;
}
if (listSize > 30 && !XCSettings.editorShowAllListData)
{
int num = listSize > 10 ? 10 : listSize;
for (int i = 0; i < num; i++)
{
DrawSerieData(dimension, m_Datas, i, showName);
}
if (num >= 10)
{
ChartEditorHelper.DrawHeader("... ", false, false, null, null);
DrawSerieData(dimension, m_Datas, listSize - 1, showName);
}
}
else
{
for (int i = 0; i < m_Datas.arraySize; i++)
{
DrawSerieData(dimension, m_Datas, i, showName);
}
}
EditorGUI.indentLevel--;
}
protected void PropertyFiledMore(System.Action action)
{
m_MoreFoldout = ChartEditorHelper.DrawHeader(MORE, m_MoreFoldout, false, null, null);
if (m_MoreFoldout)
{
if (action != null) action();
}
}
private void DrawSerieData(int dimension, SerializedProperty m_Datas, int index, bool showName)
{
bool flag;
if (!m_DataElementFoldout.TryGetValue(index, out flag))
{
flag = false;
m_DataElementFoldout[index] = false;
}
var fieldCount = dimension + (showName ? 1 : 0);
m_DataElementFoldout[index] = ChartEditorHelper.DrawHeader("SerieData " + index, flag, false, null,
delegate (Rect drawRect)
{
//drawRect.width -= 2f;
var maxX = drawRect.xMax;
var currentWidth = drawRect.width;
var lastX = drawRect.x;
var lastWid = drawRect.width;
var lastFieldWid = EditorGUIUtility.fieldWidth;
var lastLabelWid = EditorGUIUtility.labelWidth;
var serieData = m_Datas.GetArrayElementAtIndex(index);
var sereName = serieData.FindPropertyRelative("m_Name");
var data = serieData.FindPropertyRelative("m_Data");
#if UNITY_2019_3_OR_NEWER
var gap = 2;
var namegap = 3;
#else
var gap = 0;
var namegap = 0;
#endif
if (fieldCount <= 1)
{
while (2 > data.arraySize)
{
var value = data.arraySize == 0 ? index : 0;
data.arraySize++;
data.GetArrayElementAtIndex(data.arraySize - 1).floatValue = value;
}
SerializedProperty element = data.GetArrayElementAtIndex(1);
var startX = drawRect.x + EditorGUIUtility.labelWidth - EditorGUI.indentLevel * 15 + gap;
drawRect.x = startX;
drawRect.xMax = maxX;
EditorGUI.PropertyField(drawRect, element, GUIContent.none);
}
else
{
var startX = drawRect.x + EditorGUIUtility.labelWidth - EditorGUI.indentLevel * 15 + gap;
var dataWidTotal = (currentWidth - (startX + 20.5f + 1));
var dataWid = dataWidTotal / fieldCount;
var xWid = dataWid - 2;
for (int i = 0; i < dimension; i++)
{
var dataCount = i < 1 ? 2 : i + 1;
while (dataCount > data.arraySize)
{
var value = data.arraySize == 0 ? index : 0;
data.arraySize++;
data.GetArrayElementAtIndex(data.arraySize - 1).floatValue = value;
}
drawRect.x = startX + i * xWid;
drawRect.width = dataWid + 25;
SerializedProperty element = data.GetArrayElementAtIndex(dimension <= 1 ? 1 : i);
EditorGUI.PropertyField(drawRect, element, GUIContent.none);
}
if (showName)
{
drawRect.x = startX + (fieldCount - 1) * xWid;
drawRect.width = dataWid + 40 + dimension * namegap - 2.5f;
EditorGUI.PropertyField(drawRect, sereName, GUIContent.none);
}
EditorGUIUtility.fieldWidth = lastFieldWid;
EditorGUIUtility.labelWidth = lastLabelWid;
}
});
if (m_DataElementFoldout[index])
{
if(!(serie is ISimplifiedSerie))
DrawSerieDataDetail(m_Datas, index);
}
}
private void DrawSerieDataDetail(SerializedProperty m_Datas, int index)
{
EditorGUI.indentLevel++;
var serieData = m_Datas.GetArrayElementAtIndex(index);
var sereName = serieData.FindPropertyRelative("m_Name");
var selected = serieData.FindPropertyRelative("m_Selected");
var m_Ignore = serieData.FindPropertyRelative("m_Ignore");
var m_IconStyle = serieData.FindPropertyRelative("m_IconStyles");
var m_Label = serieData.FindPropertyRelative("m_Labels");
var m_ItemStyle = serieData.FindPropertyRelative("m_ItemStyles");
var m_Emphasis = serieData.FindPropertyRelative("m_Emphases");
var m_Symbol = serieData.FindPropertyRelative("m_Symbols");
PropertyField(sereName);
PropertyField(selected);
PropertyField(m_Ignore);
var componentNum = m_IconStyle.arraySize + m_Label.arraySize + m_ItemStyle.arraySize + m_Emphasis.arraySize
+ m_Symbol.arraySize;
var title = "Component";
if (componentNum == 0) title += " (None)";
m_DataComponentFoldout = ChartEditorHelper.DrawHeader(title, m_DataComponentFoldout, false, null, null,
new HeaderMenuInfo("Add ItemStyle", () =>
{
serie.GetSerieData(index).GetOrAddComponent<ItemStyle>();
}, m_ItemStyle.arraySize == 0),
new HeaderMenuInfo("Add IconStyle", () =>
{
serie.GetSerieData(index).GetOrAddComponent<IconStyle>();
}, m_IconStyle.arraySize == 0),
new HeaderMenuInfo("Add Label", () =>
{
serie.GetSerieData(index).GetOrAddComponent<LabelStyle>();
}, m_Label.arraySize == 0),
new HeaderMenuInfo("Add Emphasis", () =>
{
serie.GetSerieData(index).GetOrAddComponent<Emphasis>();
}, m_Emphasis.arraySize == 0),
new HeaderMenuInfo("Add Symbol", () =>
{
serie.GetSerieData(index).GetOrAddComponent<SymbolStyle>();
}, m_Symbol.arraySize == 0),
new HeaderMenuInfo("Remove ItemStyle", () =>
{
serie.GetSerieData(index).RemoveComponent<ItemStyle>();
}, m_ItemStyle.arraySize > 0),
new HeaderMenuInfo("Remove IconStyle", () =>
{
serie.GetSerieData(index).RemoveComponent<IconStyle>();
}, m_IconStyle.arraySize > 0),
new HeaderMenuInfo("Remove Label", () =>
{
serie.GetSerieData(index).RemoveComponent<LabelStyle>();
}, m_Label.arraySize > 0),
new HeaderMenuInfo("Remove Emphasis", () =>
{
serie.GetSerieData(index).RemoveComponent<Emphasis>();
}, m_Emphasis.arraySize > 0),
new HeaderMenuInfo("Remove Symbol", () =>
{
serie.GetSerieData(index).RemoveComponent<SymbolStyle>();
}, m_Symbol.arraySize > 0),
new HeaderMenuInfo("Remove All", () =>
{
serie.GetSerieData(index).RemoveAllComponent();
}, m_Symbol.arraySize > 0));
if (m_DataComponentFoldout)
{
if (m_IconStyle.arraySize > 0)
PropertyField(m_IconStyle.GetArrayElementAtIndex(0));
if (m_Label.arraySize > 0)
PropertyField(m_Label.GetArrayElementAtIndex(0));
if (m_ItemStyle.arraySize > 0)
PropertyField(m_ItemStyle.GetArrayElementAtIndex(0));
if (m_Emphasis.arraySize > 0)
PropertyField(m_Emphasis.GetArrayElementAtIndex(0));
if (m_Symbol.arraySize > 0)
PropertyField(m_Symbol.GetArrayElementAtIndex(0));
}
EditorGUI.indentLevel--;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 6a03d2daaabd8465398b1ff06a9889cb
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,245 @@
using System;
using System.Collections.Generic;
using UnityEngine.Assertions;
using UnityEditor;
using System.Linq;
using System.Reflection;
namespace XCharts.Editor
{
public sealed class SerieListEditor
{
public BaseChart chart { get; private set; }
BaseChartEditor m_BaseEditor;
SerializedObject m_SerializedObject;
List<SerializedProperty> m_SeriesProperty;
SerializedProperty m_EnableProperty;
Dictionary<Type, Type> m_EditorTypes;
List<SerieBaseEditor> m_Editors;
public SerieListEditor(BaseChartEditor editor)
{
Assert.IsNotNull(editor);
m_BaseEditor = editor;
}
public void Init(BaseChart chart, SerializedObject serializedObject, List<SerializedProperty> componentProps)
{
Assert.IsNotNull(chart);
Assert.IsNotNull(serializedObject);
this.chart = chart;
m_SerializedObject = serializedObject;
m_SeriesProperty = componentProps;
m_Editors = new List<SerieBaseEditor>();
m_EditorTypes = new Dictionary<Type, Type>();
var editorTypes = RuntimeUtil.GetAllTypesDerivedFrom<SerieBaseEditor>()
.Where(t => t.IsDefined(typeof(SerieEditorAttribute), false) && !t.IsAbstract);
foreach (var editorType in editorTypes)
{
var attribute = editorType.GetAttribute<SerieEditorAttribute>();
m_EditorTypes.Add(attribute.serieType, editorType);
}
RefreshEditors();
}
public void UpdateSeriesProperty(List<SerializedProperty> componentProps)
{
m_SeriesProperty = componentProps;
RefreshEditors();
}
public void Clear()
{
if (m_Editors == null)
return;
foreach (var editor in m_Editors)
editor.OnDisable();
m_Editors.Clear();
m_EditorTypes.Clear();
}
public void OnGUI()
{
if (chart == null)
return;
for (int i = 0; i < m_Editors.Count; i++)
{
var editor = m_Editors[i];
string title = editor.GetDisplayTitle();
bool displayContent = ChartEditorHelper.DrawHeader(
title,
editor.baseProperty,
editor.showProperty,
editor.menus.ToArray());
if (displayContent)
{
editor.OnInternalInspectorGUI();
}
}
if (m_Editors.Count <= 0)
{
EditorGUILayout.HelpBox("No serie.", MessageType.Info);
}
}
void RefreshEditors()
{
foreach (var editor in m_Editors)
editor.OnDisable();
m_Editors.Clear();
for (int i = 0; i < chart.series.Count; i++)
{
if (chart.series[i] != null)
CreateEditor(chart.series[i], m_SeriesProperty[i]);
}
}
void CreateEditor(Serie serie, SerializedProperty property, int index = -1)
{
var id = index >= 0 ? index : m_Editors.Count;
var settingsType = serie.GetType();
Type editorType;
if (!m_EditorTypes.TryGetValue(settingsType, out editorType))
editorType = typeof(SerieBaseEditor);
var editor = (SerieBaseEditor)Activator.CreateInstance(editorType);
editor.Init(chart, serie, property, m_BaseEditor);
editor.menus.Clear();
editor.menus.Add(new HeaderMenuInfo("Clone", () =>
{
CloneSerie(editor.serie);
}));
editor.menus.Add(new HeaderMenuInfo("Remove", () =>
{
if (EditorUtility.DisplayDialog("", "Sure remove serie?", "Yes", "Cancel"))
RemoveSerieEditor(id);
}));
editor.menus.Add(new HeaderMenuInfo("Move Down", () =>
{
if (chart.MoveDownSerie(id))
{
m_SeriesProperty = m_BaseEditor.RefreshSeries();
RefreshEditors();
}
}));
editor.menus.Add(new HeaderMenuInfo("Move Up", () =>
{
if (chart.MoveUpSerie(id))
{
m_SeriesProperty = m_BaseEditor.RefreshSeries();
RefreshEditors();
}
}));
foreach (var type in GetCovertToSerie(editor.serie.GetType()))
{
editor.menus.Add(new HeaderMenuInfo("Covert to " + type.Name, () =>
{
CovertSerie(editor.serie, type);
}));
}
if (editor.serie.GetType().IsDefined(typeof(SerieExtraComponentAttribute), false))
{
var attribute = editor.serie.GetType().GetAttribute<SerieExtraComponentAttribute>();
foreach (var type in attribute.types)
{
var size = editor.FindProperty(Serie.extraComponentFieldNameDict[type]).arraySize;
editor.menus.Add(new HeaderMenuInfo("Add " + type.Name, () =>
{
editor.serie.AddExtraComponent(type);
RefreshEditors();
}, size == 0));
}
foreach (var type in attribute.types)
{
var size = editor.FindProperty(Serie.extraComponentFieldNameDict[type]).arraySize;
editor.menus.Add(new HeaderMenuInfo("Remove " + type.Name, () =>
{
editor.serie.RemoveExtraComponent(type);
RefreshEditors();
}, size > 0));
}
}
if (index < 0)
m_Editors.Add(editor);
else
m_Editors[index] = editor;
}
public void AddSerie(Type type)
{
m_SerializedObject.Update();
var serieName = chart.GenerateDefaultSerieName();
type.InvokeMember("AddDefaultSerie",
BindingFlags.InvokeMethod | BindingFlags.Static | BindingFlags.Public, null, null,
new object[] { chart, serieName });
m_SerializedObject.Update();
m_SerializedObject.ApplyModifiedProperties();
m_SeriesProperty = m_BaseEditor.RefreshSeries();
RefreshEditors();
EditorUtility.SetDirty(chart);
AssetDatabase.SaveAssets();
AssetDatabase.Refresh();
}
public void CovertSerie(Serie serie, Type type)
{
chart.CovertSerie(serie, type);
m_SeriesProperty = m_BaseEditor.RefreshSeries();
RefreshEditors();
}
public void CloneSerie(Serie serie)
{
var newSerie = serie.Clone();
newSerie.serieName = chart.GenerateDefaultSerieName();
chart.InsertSerie(newSerie);
m_SeriesProperty = m_BaseEditor.RefreshSeries();
RefreshEditors();
}
private void RemoveSerieEditor(int id)
{
m_Editors[id].OnDisable();
chart.RemoveSerie(m_Editors[id].serie);
m_Editors.RemoveAt(id);
m_SerializedObject.Update();
m_SerializedObject.ApplyModifiedProperties();
m_SeriesProperty = m_BaseEditor.RefreshSeries();
RefreshEditors();
EditorUtility.SetDirty(chart);
AssetDatabase.SaveAssets();
AssetDatabase.Refresh();
}
private List<Type> GetCovertToSerie(Type serie)
{
var list = new List<Type>();
var typeMap = RuntimeUtil.GetAllTypesDerivedFrom<Serie>();
foreach (var kvp in typeMap)
{
var type = kvp;
if (type.IsDefined(typeof(SerieConvertAttribute), false))
{
var attribute = type.GetAttribute<SerieConvertAttribute>();
if (attribute != null && attribute.Contains(serie))
list.Add(type);
}
}
list.Sort((a, b) => { return a.Name.CompareTo(b.Name); });
return list;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 5fbdf672386ce40bb803a8bb3bb2a3ca
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,18 @@
namespace XCharts.Editor
{
[SerieEditor(typeof(SimplifiedBar))]
public class SimplifiedBarEditor : SerieEditor<SimplifiedBar>
{
public override void OnCustomInspectorGUI()
{
PropertyField("m_XAxisIndex");
PropertyField("m_YAxisIndex");
PropertyField("m_BarWidth");
PropertyField("m_BarGap");
PropertyField("m_ItemStyle");
PropertyField("m_Animation");
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 99f8e53a5ab7c49e6b87aedee03cf856
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,17 @@
namespace XCharts.Editor
{
[SerieEditor(typeof(SimplifiedCandlestick))]
public class SimplifiedCandlestickEditor : SerieEditor<SimplifiedCandlestick>
{
public override void OnCustomInspectorGUI()
{
PropertyField("m_XAxisIndex");
PropertyField("m_YAxisIndex");
PropertyField("m_BarWidth");
PropertyField("m_ItemStyle");
PropertyField("m_Animation");
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 73d22e02d33e948d6981d537ba1f680e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,18 @@
namespace XCharts.Editor
{
[SerieEditor(typeof(SimplifiedLine))]
public class LineHPEditor : SerieEditor<SimplifiedLine>
{
public override void OnCustomInspectorGUI()
{
PropertyField("m_XAxisIndex");
PropertyField("m_YAxisIndex");
PropertyField("m_LineType");
PropertyField("m_LineStyle");
PropertyField("m_ItemStyle");
PropertyField("m_Animation");
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: cedf2a45756cd415cb5a74f3188ebd72
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: