优化Editor参数编辑,兼容Unity2019.3及以上版本

This commit is contained in:
monitor1394
2020-03-26 09:13:46 +08:00
parent b82a20f6eb
commit 7eace387c6
6 changed files with 93 additions and 50 deletions

View File

@@ -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;

View File

@@ -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
{

View File

@@ -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)
{

View File

@@ -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())
{