增加Serieinspector上可进行调整顺序、添加和删除操作

This commit is contained in:
monitor1394
2020-03-24 09:08:14 +08:00
parent 6692a2dc06
commit b82a20f6eb
4 changed files with 57 additions and 9 deletions

View File

@@ -1,6 +1,7 @@
# 更新日志 # 更新日志
* (2020.03.24) 增加`Serie``inspector`上可进行调整顺序、添加和删除操作
* (2020.03.23) 修复`Title``textStyle``subTextStyle`无效的问题 * (2020.03.23) 修复`Title``textStyle``subTextStyle`无效的问题
* (2020.03.22) 增加`BarChart`通过`barType`参数设置`胶囊柱状图` * (2020.03.22) 增加`BarChart`通过`barType`参数设置`胶囊柱状图`
* (2020.03.21) 增加`BarChart``HeatmapChart`可通过`ignore`参数设置忽略数据的支持 * (2020.03.21) 增加`BarChart``HeatmapChart`可通过`ignore`参数设置忽略数据的支持

View File

@@ -81,8 +81,9 @@ namespace XCharts
var toggle = ChartEditorHelper.MakeFoldout(ref drawRect, ref m_SerieModuleToggle, prop, moduleName, show); var toggle = ChartEditorHelper.MakeFoldout(ref drawRect, ref m_SerieModuleToggle, prop, moduleName, show);
if (!toggle) if (!toggle)
{ {
var orderButton = 47;
drawRect.x = EditorGUIUtility.labelWidth - (EditorGUI.indentLevel - 1) * 15 - 2 + 20; drawRect.x = EditorGUIUtility.labelWidth - (EditorGUI.indentLevel - 1) * 15 - 2 + 20;
drawRect.width = pos.width - drawRect.x + 15; drawRect.width = pos.width - drawRect.x + 15 - orderButton;
EditorGUI.PropertyField(drawRect, type, GUIContent.none); EditorGUI.PropertyField(drawRect, type, GUIContent.none);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
} }
@@ -249,7 +250,7 @@ namespace XCharts
drawRect.y += EditorGUI.GetPropertyHeight(m_Emphasis); drawRect.y += EditorGUI.GetPropertyHeight(m_Emphasis);
break; break;
case SerieType.Heatmap: case SerieType.Heatmap:
EditorGUI.PropertyField(drawRect, m_Ignore); EditorGUI.PropertyField(drawRect, m_Ignore);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_IgnoreValue); EditorGUI.PropertyField(drawRect, m_IgnoreValue);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
@@ -359,6 +360,7 @@ namespace XCharts
DrawDataElement(ref drawRect, dimension, m_Datas, showName, showIcon, showSelected, i, pos.width); DrawDataElement(ref drawRect, dimension, m_Datas, showName, showIcon, showSelected, i, pos.width);
} }
} }
drawRect.y += EditorGUIUtility.standardVerticalSpacing;
EditorGUI.indentLevel--; EditorGUI.indentLevel--;
} }
--EditorGUI.indentLevel; --EditorGUI.indentLevel;
@@ -460,7 +462,7 @@ namespace XCharts
{ {
float height = 0; float height = 0;
int index = InitToggle(prop); int index = InitToggle(prop);
if (!m_SerieModuleToggle[prop.propertyPath]) if (!m_SerieModuleToggle.ContainsKey(prop.propertyPath) || !m_SerieModuleToggle[prop.propertyPath])
{ {
return EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; return EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
} }
@@ -553,6 +555,7 @@ namespace XCharts
{ {
height += (num) * EditorGUIUtility.singleLineHeight + (num - 1) * EditorGUIUtility.standardVerticalSpacing; height += (num) * EditorGUIUtility.singleLineHeight + (num - 1) * EditorGUIUtility.standardVerticalSpacing;
} }
height += EditorGUIUtility.standardVerticalSpacing;
if (prop.FindPropertyRelative("m_ShowDataIcon").boolValue) if (prop.FindPropertyRelative("m_ShowDataIcon").boolValue)
{ {
for (int i = 0; i < num; i++) for (int i = 0; i < num; i++)

View File

@@ -27,11 +27,10 @@ namespace XCharts
drawRect.width = EditorGUIUtility.labelWidth + 10; drawRect.width = EditorGUIUtility.labelWidth + 10;
ChartEditorHelper.MakeFoldout(ref drawRect, ref m_SeriesModuleToggle, "Series"); ChartEditorHelper.MakeFoldout(ref drawRect, ref m_SeriesModuleToggle, "Series");
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
//ChartEditorHelper.MakeJsonData(ref drawRect, ref m_ShowJsonDataArea, ref m_JsonDataAreaText, prop);
drawRect.width = pos.width; drawRect.width = pos.width;
if (m_SeriesModuleToggle) if (m_SeriesModuleToggle)
{ {
ChartEditorHelper.MakeList(ref drawRect, ref m_DataSize, m_Series); ChartEditorHelper.MakeList(ref drawRect, ref m_DataSize, m_Series, true);
} }
} }

View File

@@ -143,11 +143,27 @@ public class ChartEditorHelper
return toggle; return toggle;
} }
public static void MakeList(ref Rect drawRect, ref int listSize, SerializedProperty listProp, SerializedProperty large = null) public static void MakeList(ref Rect drawRect, ref int listSize, SerializedProperty listProp, bool showOrder = false)
{ {
EditorGUI.indentLevel++; EditorGUI.indentLevel++;
listSize = listProp.arraySize; listSize = listProp.arraySize;
listSize = EditorGUI.IntField(drawRect, "Size", listSize); if (showOrder)
{
var nameWid = 15;
var elementRect = new Rect(drawRect.x, drawRect.y, drawRect.width - nameWid, drawRect.height);
//listSize = EditorGUI.IntField(elementRect, "Size", listSize);
var iconRect = new Rect(drawRect.width - nameWid + 14, drawRect.y, nameWid, drawRect.height);
if (GUI.Button(iconRect, new GUIContent("+", "add")))
{
listProp.InsertArrayElementAtIndex(listProp.arraySize);
}
listSize = listProp.arraySize;
listSize = EditorGUI.IntField(elementRect, "Size", listSize);
}
else
{
listSize = EditorGUI.IntField(drawRect, "Size", listSize);
}
if (listSize < 0) listSize = 0; if (listSize < 0) listSize = 0;
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
@@ -182,8 +198,37 @@ public class ChartEditorHelper
for (int i = 0; i < listProp.arraySize; i++) for (int i = 0; i < listProp.arraySize; i++)
{ {
SerializedProperty element = listProp.GetArrayElementAtIndex(i); SerializedProperty element = listProp.GetArrayElementAtIndex(i);
EditorGUI.PropertyField(drawRect, element, new GUIContent("Element " + i)); if (showOrder)
drawRect.y += EditorGUI.GetPropertyHeight(element) + EditorGUIUtility.standardVerticalSpacing; {
var nameWid = 15;
var isSerie = "Serie".Equals(element.type);
var elementRect = isSerie ? drawRect : new Rect(drawRect.x, drawRect.y, drawRect.width - 2 * 15, drawRect.height);
EditorGUI.PropertyField(elementRect, element, new GUIContent("Element " + i));
var iconRect = new Rect(drawRect.width - 3 * nameWid + 14, drawRect.y, nameWid, drawRect.height);
if (GUI.Button(iconRect, new GUIContent("↑", "up")))
{
if (i > 0) listProp.MoveArrayElement(i, i - 1);
}
iconRect = new Rect(drawRect.width - 2 * nameWid + 14, drawRect.y, nameWid, drawRect.height);
if (GUI.Button(iconRect, new GUIContent("↓", "down")))
{
if (i < listProp.arraySize - 1) listProp.MoveArrayElement(i, i + 1);
}
iconRect = new Rect(drawRect.width - nameWid + 14, drawRect.y, nameWid, drawRect.height);
if (GUI.Button(iconRect, new GUIContent("-", "delete")))
{
if (i < listProp.arraySize && i >= 0) listProp.DeleteArrayElementAtIndex(i);
}
else
{
drawRect.y += EditorGUI.GetPropertyHeight(element) + EditorGUIUtility.standardVerticalSpacing;
}
}
else
{
EditorGUI.PropertyField(drawRect, element, new GUIContent("Element " + i));
drawRect.y += EditorGUI.GetPropertyHeight(element) + EditorGUIUtility.standardVerticalSpacing;
}
} }
} }
EditorGUI.indentLevel--; EditorGUI.indentLevel--;