diff --git a/Assets/XCharts/CHANGELOG.md b/Assets/XCharts/CHANGELOG.md index 34a75c9a..84e1bc0e 100644 --- a/Assets/XCharts/CHANGELOG.md +++ b/Assets/XCharts/CHANGELOG.md @@ -1,6 +1,7 @@ # 更新日志 +* (2020.03.24) 优化`Editor`参数编辑,兼容`Unity2019.3`及以上版本 * (2020.03.24) 增加`Serie`在`inspector`上可进行调整顺序、添加和删除操作 * (2020.03.23) 修复`Title`的`textStyle`和`subTextStyle`无效的问题 * (2020.03.22) 增加`BarChart`通过`barType`参数设置`胶囊柱状图` diff --git a/Assets/XCharts/Editor/PropertyDrawers/SerieDrawer.cs b/Assets/XCharts/Editor/PropertyDrawers/SerieDrawer.cs index b2ed082e..9b7f7e1f 100644 --- a/Assets/XCharts/Editor/PropertyDrawers/SerieDrawer.cs +++ b/Assets/XCharts/Editor/PropertyDrawers/SerieDrawer.cs @@ -81,9 +81,10 @@ namespace XCharts var toggle = ChartEditorHelper.MakeFoldout(ref drawRect, ref m_SerieModuleToggle, prop, moduleName, show); if (!toggle) { - var orderButton = 47; - drawRect.x = EditorGUIUtility.labelWidth - (EditorGUI.indentLevel - 1) * 15 - 2 + 20; - drawRect.width = pos.width - drawRect.x + 15 - orderButton; + var orderButton = 46; + var gap = 4; + drawRect.x += EditorGUIUtility.labelWidth + gap; + drawRect.width = pos.width - drawRect.x + ChartEditorHelper.BOOL_WIDTH - orderButton; EditorGUI.PropertyField(drawRect, type, GUIContent.none); drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; } @@ -309,13 +310,20 @@ namespace XCharts EditorGUI.indentLevel++; float nameWid = 45; +#if UNITY_2019_3_OR_NEWER + var gap = 2; + var namegap = 3; +#else + var gap = 0; + var namegap = 0; +#endif EditorGUI.PropertyField(new Rect(drawRect.x, drawRect.y, pos.width - 2 * nameWid - 2, pos.height), m_DataDimension); - var nameRect = new Rect(pos.width - 2 * nameWid + 14, drawRect.y, nameWid, pos.height); + var nameRect = new Rect(pos.width - 2 * nameWid + 14 + gap, drawRect.y, nameWid - gap, pos.height); if (GUI.Button(nameRect, new GUIContent("Name"))) { m_ShowDataName.boolValue = !m_ShowDataName.boolValue; } - var iconRect = new Rect(pos.width - nameWid + 14, drawRect.y, nameWid, pos.height); + var iconRect = new Rect(pos.width - nameWid + 14, drawRect.y, nameWid + namegap, pos.height); if (GUI.Button(iconRect, new GUIContent("More..."))) { m_ShowDataIcon.boolValue = !m_ShowDataIcon.boolValue; @@ -403,8 +411,15 @@ namespace XCharts } else { +#if UNITY_2019_3_OR_NEWER + var gap = 2; + var namegap = 3; +#else + var gap = 0; + var namegap = 0; +#endif EditorGUI.LabelField(drawRect, "Element " + index); - var startX = drawRect.x + EditorGUIUtility.labelWidth - EditorGUI.indentLevel * 15; + var startX = drawRect.x + EditorGUIUtility.labelWidth - EditorGUI.indentLevel * 15 + gap; var dataWidTotal = (currentWidth - (startX + 20.5f + 1)); var dataWid = dataWidTotal / fieldCount; var xWid = dataWid - 4; @@ -422,7 +437,7 @@ namespace XCharts if (showName) { drawRect.x = startX + (fieldCount - 1) * xWid; - drawRect.width = dataWid + 40; + drawRect.width = dataWid + 40 + dimension * namegap; EditorGUI.PropertyField(drawRect, sereName, GUIContent.none); } @@ -445,13 +460,13 @@ namespace XCharts EditorGUI.PropertyField(drawRect, m_Icon); drawRect.y += EditorGUI.GetPropertyHeight(m_Icon); EditorGUI.PropertyField(drawRect, m_Label); - ChartEditorHelper.MakeBool(ref drawRect, m_EnableLabel, 1, "(enable)"); + ChartEditorHelper.MakeBool(drawRect, m_EnableLabel, 1, "(enable)"); drawRect.y += EditorGUI.GetPropertyHeight(m_Label); EditorGUI.PropertyField(drawRect, m_ItemStyle); - ChartEditorHelper.MakeBool(ref drawRect, m_EnableItemStyle, 1, "(enable)"); + ChartEditorHelper.MakeBool(drawRect, m_EnableItemStyle, 1, "(enable)"); drawRect.y += EditorGUI.GetPropertyHeight(m_ItemStyle); EditorGUI.PropertyField(drawRect, m_Emphasis); - ChartEditorHelper.MakeBool(ref drawRect, m_EnableEmphasis, 1, "(enable)"); + ChartEditorHelper.MakeBool(drawRect, m_EnableEmphasis, 1, "(enable)"); drawRect.y += EditorGUI.GetPropertyHeight(m_Emphasis); EditorGUI.indentLevel -= 2; diff --git a/Assets/XCharts/Editor/PropertyDrawers/SerieLabelDrawer.cs b/Assets/XCharts/Editor/PropertyDrawers/SerieLabelDrawer.cs index 66b31e87..608a115e 100644 --- a/Assets/XCharts/Editor/PropertyDrawers/SerieLabelDrawer.cs +++ b/Assets/XCharts/Editor/PropertyDrawers/SerieLabelDrawer.cs @@ -53,21 +53,14 @@ namespace XCharts EditorGUI.PropertyField(drawRect, m_Position); drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - EditorGUI.LabelField(drawRect, "Offset"); - var startX = drawRect.x + EditorGUIUtility.labelWidth - EditorGUI.indentLevel * 15; - var tempWidth = (drawRect.width - startX + 52) / 2; - var centerXRect = new Rect(startX, drawRect.y, tempWidth, drawRect.height); - var centerYRect = new Rect(centerXRect.x + tempWidth - 38, drawRect.y, tempWidth, drawRect.height); - var x = EditorGUI.FloatField(centerXRect, m_Offset.vector3Value.x); - var y = EditorGUI.FloatField(centerYRect, m_Offset.vector3Value.y); - m_Offset.vector3Value = new Vector3(x, y); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; + EditorGUI.PropertyField(drawRect, m_Offset); + drawRect.y += EditorGUI.GetPropertyHeight(m_Offset); EditorGUI.PropertyField(drawRect, m_Margin); drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; EditorGUI.PropertyField(drawRect, m_Formatter); drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - + EditorGUI.PropertyField(drawRect, m_Color); drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; EditorGUI.PropertyField(drawRect, m_BackgroundColor); @@ -115,7 +108,8 @@ namespace XCharts float height = 0; if (ChartEditorHelper.IsToggle(m_SerieLabelToggle, prop)) { - height += 24 * EditorGUIUtility.singleLineHeight + 23 * EditorGUIUtility.standardVerticalSpacing; + height += 23 * EditorGUIUtility.singleLineHeight + 22 * EditorGUIUtility.standardVerticalSpacing; + height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_Offset")); } else { diff --git a/Assets/XCharts/Editor/PropertyDrawers/SettingsDrawer.cs b/Assets/XCharts/Editor/PropertyDrawers/SettingsDrawer.cs index 0280de69..b7c24aef 100644 --- a/Assets/XCharts/Editor/PropertyDrawers/SettingsDrawer.cs +++ b/Assets/XCharts/Editor/PropertyDrawers/SettingsDrawer.cs @@ -29,7 +29,6 @@ namespace XCharts SerializedProperty m_PieSelectedOffset = prop.FindPropertyRelative("m_PieSelectedOffset"); ChartEditorHelper.MakeFoldout(ref drawRect, ref m_SettingsModuleToggle, "Settings"); - EditorGUI.LabelField(drawRect, "Settings", EditorStyles.boldLabel); drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; if (m_SettingsModuleToggle) { diff --git a/Assets/XCharts/Editor/PropertyDrawers/ThemeInfoDrawer.cs b/Assets/XCharts/Editor/PropertyDrawers/ThemeInfoDrawer.cs index b4fea4e7..1dcadc9f 100644 --- a/Assets/XCharts/Editor/PropertyDrawers/ThemeInfoDrawer.cs +++ b/Assets/XCharts/Editor/PropertyDrawers/ThemeInfoDrawer.cs @@ -67,14 +67,16 @@ namespace XCharts SerializedProperty m_CustomVisualMapBorderColor = prop.FindPropertyRelative("m_CustomVisualMapBorderColor"); SerializedProperty m_CustomColorPalette = prop.FindPropertyRelative("m_CustomColorPalette"); + var btnWidth = 45; ChartEditorHelper.MakeFoldout(ref drawRect, ref m_ThemeModuleToggle, "Theme"); - drawRect.x = EditorGUIUtility.labelWidth - (EditorGUI.indentLevel - 1) * 15 - 2; - drawRect.width = defaultWidth - EditorGUIUtility.labelWidth - (m_ThemeModuleToggle ? 45 : 0); + drawRect.x += EditorGUIUtility.labelWidth + ChartEditorHelper.GAP_WIDTH; + drawRect.width = defaultWidth - EditorGUIUtility.labelWidth - ChartEditorHelper.GAP_WIDTH + - (m_ThemeModuleToggle ? btnWidth + 3 : 0); EditorGUI.PropertyField(drawRect, m_Theme, GUIContent.none); if (m_ThemeModuleToggle) { - drawRect.x = defaultWidth - 30; - drawRect.width = 45; + drawRect.x = defaultX + defaultWidth - btnWidth; + drawRect.width = btnWidth; if (GUI.Button(drawRect, new GUIContent("Reset", "Reset to theme default color"))) { m_CustomFont.objectReferenceValue = null; @@ -139,7 +141,7 @@ namespace XCharts ++EditorGUI.indentLevel; EditorGUI.BeginChangeCheck(); - var font =m_CustomFont.objectReferenceValue != null?m_CustomFont: m_Font; + var font = m_CustomFont.objectReferenceValue != null ? m_CustomFont : m_Font; EditorGUI.PropertyField(drawRect, font); if (EditorGUI.EndChangeCheck()) { diff --git a/Assets/XCharts/Editor/Utility/ChartEditorHelper.cs b/Assets/XCharts/Editor/Utility/ChartEditorHelper.cs index ede3996e..06e1ef3c 100644 --- a/Assets/XCharts/Editor/Utility/ChartEditorHelper.cs +++ b/Assets/XCharts/Editor/Utility/ChartEditorHelper.cs @@ -4,6 +4,17 @@ using System.Collections.Generic; public class ChartEditorHelper { +#if UNITY_2019_3_OR_NEWER + public const float INDENT_WIDTH = 15; + public const float BOOL_WIDTH = 15; + public const float ARROW_WIDTH = 20; + public const float GAP_WIDTH =2; +#else + public const float INDENT_WIDTH = 15; + public const float BOOL_WIDTH = 15; + public const float ARROW_WIDTH = 13; + public const float GAP_WIDTH = 0; +#endif public static GUIStyle headerStyle = EditorStyles.boldLabel; public static GUIStyle foldoutStyle = new GUIStyle(EditorStyles.foldout) { @@ -31,9 +42,9 @@ public class ChartEditorHelper public static void MakeTwoField(ref Rect drawRect, float rectWidth, SerializedProperty prop1, SerializedProperty prop2, string name) { EditorGUI.LabelField(drawRect, name); - var startX = drawRect.x + EditorGUIUtility.labelWidth - EditorGUI.indentLevel * 15; + var startX = drawRect.x + EditorGUIUtility.labelWidth - EditorGUI.indentLevel * INDENT_WIDTH + GAP_WIDTH; var diff = 14 + EditorGUI.indentLevel * 14; - var offset = diff - 15; + var offset = diff - INDENT_WIDTH; var tempWidth = (rectWidth - startX + diff) / 2; var centerXRect = new Rect(startX, drawRect.y, tempWidth, drawRect.height); var centerYRect = new Rect(centerXRect.x + tempWidth - offset, drawRect.y, tempWidth, drawRect.height); @@ -42,14 +53,29 @@ public class ChartEditorHelper drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; } + public static void MakeVector2(ref Rect drawRect, float rectWidth, SerializedProperty prop, string name) + { + EditorGUI.LabelField(drawRect, name); + var startX = drawRect.x + EditorGUIUtility.labelWidth - EditorGUI.indentLevel * INDENT_WIDTH + GAP_WIDTH; + var diff = 14 + EditorGUI.indentLevel * 14; + var offset = diff - INDENT_WIDTH; + var tempWidth = (rectWidth - startX + diff) / 2; + var centerXRect = new Rect(startX, drawRect.y, tempWidth, drawRect.height); + var centerYRect = new Rect(centerXRect.x + tempWidth - offset, drawRect.y, tempWidth, drawRect.height); + var x = EditorGUI.FloatField(centerXRect, prop.vector3Value.x); + var y = EditorGUI.FloatField(centerYRect, prop.vector3Value.y); + prop.vector3Value = new Vector3(x, y); + drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; + } + public static void MakeJsonData(ref Rect drawRect, ref bool showTextArea, ref string inputString, SerializedProperty prop, float currentWidth, float diff = 0) { SerializedProperty stringDataProp = prop.FindPropertyRelative("m_JsonData"); SerializedProperty needParseProp = prop.FindPropertyRelative("m_DataFromJson"); float defalutX = drawRect.x; - drawRect.x = EditorGUIUtility.labelWidth + 14 + diff; - drawRect.width = currentWidth - EditorGUIUtility.labelWidth - diff; + drawRect.x = EditorGUIUtility.labelWidth + ARROW_WIDTH + diff; + drawRect.width = currentWidth - EditorGUIUtility.labelWidth - GAP_WIDTH - diff; if (GUI.Button(drawRect, new GUIContent("Parse JsonData", "Parse data from input json"))) { showTextArea = !showTextArea; @@ -77,27 +103,28 @@ public class ChartEditorHelper { float defaultWidth = drawRect.width; float defaultX = drawRect.x; - drawRect.width = EditorGUIUtility.labelWidth; + drawRect.width = EditorGUIUtility.labelWidth - EditorGUI.indentLevel * INDENT_WIDTH; moduleToggle = EditorGUI.Foldout(drawRect, moduleToggle, content, bold ? foldoutStyle : EditorStyles.foldout); - MakeBool(ref drawRect, prop); + MakeBool(drawRect, prop); drawRect.width = defaultWidth; drawRect.x = defaultX; return moduleToggle; } - public static void MakeBool(ref Rect drawRect, SerializedProperty boolProp, int index = 0, string name = null) + public static void MakeBool(Rect drawRect, SerializedProperty boolProp, int index = 0, string name = null) { float defaultWidth = drawRect.width; float defaultX = drawRect.x; - drawRect.x = EditorGUIUtility.labelWidth - (EditorGUI.indentLevel - 1) * 15 - 2 + index * 30; - drawRect.width = 20 + EditorGUI.indentLevel * 20; + float boolWidth = index * (BOOL_WIDTH + GAP_WIDTH); + drawRect.x = EditorGUIUtility.labelWidth - EditorGUI.indentLevel * INDENT_WIDTH + ARROW_WIDTH + boolWidth; + drawRect.width = (EditorGUI.indentLevel + 1) * BOOL_WIDTH + index * 110; if (boolProp != null) { EditorGUI.PropertyField(drawRect, boolProp, GUIContent.none); - drawRect.x += 13; - drawRect.width = 200; if (!string.IsNullOrEmpty(name)) { + drawRect.x += BOOL_WIDTH; + drawRect.width = 200; EditorGUI.LabelField(drawRect, name); } } @@ -117,24 +144,28 @@ public class ChartEditorHelper float defaultWidth = drawRect.width; float defaultX = drawRect.x; - drawRect.width = EditorGUIUtility.labelWidth - 5; +#if UNITY_2019_3_OR_NEWER + drawRect.width = EditorGUIUtility.labelWidth - EditorGUI.indentLevel * INDENT_WIDTH; +#else + drawRect.width = EditorGUIUtility.labelWidth; +#endif var displayName = string.IsNullOrEmpty(moduleName) ? prop.displayName : moduleName; - toggle = EditorGUI.Foldout(drawRect, toggle, displayName, bold ? foldoutStyle : EditorStyles.foldout); + if (moduleToggle[key] != toggle) { moduleToggle[key] = toggle; } - drawRect.x = EditorGUIUtility.labelWidth - (EditorGUI.indentLevel - 1) * 15 - 2; if (showProp != null) { + drawRect.x = EditorGUIUtility.labelWidth - EditorGUI.indentLevel * INDENT_WIDTH + ARROW_WIDTH; if (showProp.propertyType == SerializedPropertyType.Boolean) { - drawRect.width = 100; + drawRect.width = (EditorGUI.indentLevel + 1) * BOOL_WIDTH; } else { - drawRect.width = defaultWidth - drawRect.x + 15; + drawRect.width = defaultWidth - drawRect.x + ARROW_WIDTH - GAP_WIDTH; } EditorGUI.PropertyField(drawRect, showProp, GUIContent.none); } @@ -150,9 +181,9 @@ public class ChartEditorHelper 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); + var temp = INDENT_WIDTH + GAP_WIDTH; + var elementRect = new Rect(drawRect.x, drawRect.y, drawRect.width - nameWid - 1, drawRect.height); + var iconRect = new Rect(drawRect.width - nameWid + temp, drawRect.y, nameWid, drawRect.height); if (GUI.Button(iconRect, new GUIContent("+", "add"))) { listProp.InsertArrayElementAtIndex(listProp.arraySize); @@ -201,20 +232,21 @@ public class ChartEditorHelper if (showOrder) { var nameWid = 15; + var temp = INDENT_WIDTH + GAP_WIDTH; var isSerie = "Serie".Equals(element.type); - var elementRect = isSerie ? drawRect : new Rect(drawRect.x, drawRect.y, drawRect.width - 2 * 15, drawRect.height); + var elementRect = isSerie ? drawRect : new Rect(drawRect.x, drawRect.y, drawRect.width - 2 * nameWid, drawRect.height); EditorGUI.PropertyField(elementRect, element, new GUIContent("Element " + i)); - var iconRect = new Rect(drawRect.width - 3 * nameWid + 14, drawRect.y, nameWid, drawRect.height); + var iconRect = new Rect(drawRect.width - 3 * nameWid + temp, 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); + iconRect = new Rect(drawRect.width - 2 * nameWid + temp, 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); + iconRect = new Rect(drawRect.width - nameWid + temp, drawRect.y, nameWid, drawRect.height); if (GUI.Button(iconRect, new GUIContent("-", "delete"))) { if (i < listProp.arraySize && i >= 0) listProp.DeleteArrayElementAtIndex(i);