优化Theme主题的自定义,切换主题时自定义配置不受影响

This commit is contained in:
monitor1394
2019-07-24 09:41:27 +08:00
parent cb6d0765ca
commit 78123b74ae
7 changed files with 13373 additions and 10923 deletions

View File

@@ -77,30 +77,9 @@ namespace XCharts
protected virtual void OnStartInspectorGUI()
{
EditorGUILayout.PropertyField(m_Script);
EditorGUILayout.BeginHorizontal();
EditorGUIUtility.labelWidth = 20;
EditorGUILayout.LabelField("Size");
EditorGUIUtility.fieldWidth = 1;
m_ChartWidth.floatValue = EditorGUILayout.FloatField(m_ChartWidth.floatValue);
m_ChartHeight.floatValue = EditorGUILayout.FloatField(m_ChartHeight.floatValue);
EditorGUILayout.EndHorizontal();
EditorGUILayout.BeginHorizontal();
EditorGUIUtility.labelWidth = m_DefaultLabelWidth;
EditorGUIUtility.fieldWidth = EditorGUIUtility.labelWidth - 5;
m_ThemeModuleToggle = EditorGUILayout.Foldout(m_ThemeModuleToggle,
new GUIContent("Theme", "the theme of chart\n主题"),
ChartEditorHelper.foldoutStyle);
EditorGUILayout.PropertyField(m_Theme, GUIContent.none);
EditorGUILayout.EndHorizontal();
EditorGUIUtility.labelWidth = m_DefaultLabelWidth;
EditorGUIUtility.fieldWidth = m_DefaultFieldWidth;
if (m_ThemeModuleToggle)
{
EditorGUILayout.PropertyField(m_ThemeInfo, true);
}
EditorGUILayout.PropertyField(m_ChartWidth);
EditorGUILayout.PropertyField(m_ChartHeight);
EditorGUILayout.PropertyField(m_ThemeInfo, true);
EditorGUILayout.PropertyField(m_Title, true);
EditorGUILayout.PropertyField(m_Legend, true);
EditorGUILayout.PropertyField(m_Tooltip, true);

View File

@@ -9,30 +9,15 @@ namespace XCharts
{
ReorderableList m_ColorPaletteList;
bool m_ColorPaletteFoldout;
private void InitReorderableList(SerializedProperty prop)
{
if (m_ColorPaletteList == null)
{
SerializedProperty colorPalette = prop.FindPropertyRelative("m_ColorPalette");
m_ColorPaletteList = new ReorderableList(colorPalette.serializedObject, colorPalette, false, false, true, true);
m_ColorPaletteList.elementHeight = EditorGUIUtility.singleLineHeight;
m_ColorPaletteList.drawHeaderCallback += delegate (Rect rect)
{
EditorGUI.LabelField(rect, colorPalette.displayName);
};
m_ColorPaletteList.drawElementCallback = delegate (Rect rect, int index, bool isActive, bool isFocused)
{
EditorGUI.PropertyField(rect, colorPalette.GetArrayElementAtIndex(index), true);
};
}
}
bool m_ThemeModuleToggle = false;
public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label)
{
Rect drawRect = pos;
var defaultWidth = drawRect.width;
var defaultX = drawRect.x;
drawRect.height = EditorGUIUtility.singleLineHeight;
SerializedProperty m_Theme = prop.FindPropertyRelative("m_Theme");
SerializedProperty m_Font = prop.FindPropertyRelative("m_Font");
SerializedProperty m_BackgroundColor = prop.FindPropertyRelative("m_BackgroundColor");
SerializedProperty m_TextColor = prop.FindPropertyRelative("m_TextColor");
@@ -52,74 +37,297 @@ namespace XCharts
SerializedProperty m_DataZoomTextColor = prop.FindPropertyRelative("m_DataZoomTextColor");
SerializedProperty m_ColorPalette = prop.FindPropertyRelative("m_ColorPalette");
++EditorGUI.indentLevel;
EditorGUI.PropertyField(drawRect, m_Font);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_BackgroundColor);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_TextColor);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_SubTextColor);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_LegendTextColor);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_LegendUnableColor);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_AxisTextColor);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_AxisLineColor);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_AxisSplitLineColor);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_TooltipBackgroundColor);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_TooltipFlagAreaColor);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_TooltipTextColor);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_TooltipLabelColor);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_TooltipLineColor);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_DataZoomLineColor);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_DataZoomSelectedColor);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_DataZoomTextColor);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
SerializedProperty m_CustomFont = prop.FindPropertyRelative("m_CustomFont");
SerializedProperty m_CustomBackgroundColor = prop.FindPropertyRelative("m_CustomBackgroundColor");
SerializedProperty m_CustomTextColor = prop.FindPropertyRelative("m_CustomTextColor");
SerializedProperty m_CustomSubTextColor = prop.FindPropertyRelative("m_CustomTitleSubTextColor");
SerializedProperty m_CustomLegendTextColor = prop.FindPropertyRelative("m_CustomLegendTextColor");
SerializedProperty m_CustomLegendUnableColor = prop.FindPropertyRelative("m_CustomLegendUnableColor");
SerializedProperty m_CustomAxisTextColor = prop.FindPropertyRelative("m_CustomAxisTextColor");
SerializedProperty m_CustomAxisLineColor = prop.FindPropertyRelative("m_CustomAxisLineColor");
SerializedProperty m_CustomAxisSplitLineColor = prop.FindPropertyRelative("m_CustomAxisSplitLineColor");
SerializedProperty m_CustomTooltipBackgroundColor = prop.FindPropertyRelative("m_CustomTooltipBackgroundColor");
SerializedProperty m_CustomTooltipFlagAreaColor = prop.FindPropertyRelative("m_CustomTooltipFlagAreaColor");
SerializedProperty m_CustomTooltipTextColor = prop.FindPropertyRelative("m_CustomTooltipTextColor");
SerializedProperty m_CustomTooltipLabelColor = prop.FindPropertyRelative("m_CustomTooltipLabelColor");
SerializedProperty m_CustomTooltipLineColor = prop.FindPropertyRelative("m_CustomTooltipLineColor");
SerializedProperty m_CustomDataZoomLineColor = prop.FindPropertyRelative("m_CustomDataZoomLineColor");
SerializedProperty m_CustomDataZoomSelectedColor = prop.FindPropertyRelative("m_CustomDataZoomSelectedColor");
SerializedProperty m_CustomDataZoomTextColor = prop.FindPropertyRelative("m_CustomDataZoomTextColor");
SerializedProperty m_CustomColorPalette = prop.FindPropertyRelative("m_CustomColorPalette");
m_ColorPaletteFoldout = EditorGUI.Foldout(drawRect, m_ColorPaletteFoldout, "ColorPalette");
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
if (m_ColorPaletteFoldout)
ChartEditorHelper.MakeFoldout(ref drawRect, ref m_ThemeModuleToggle, "Theme");
drawRect.x = EditorGUIUtility.labelWidth - (EditorGUI.indentLevel - 1) * 15 - 2;
drawRect.width = EditorGUIUtility.currentViewWidth - EditorGUIUtility.labelWidth - (m_ThemeModuleToggle ? 80 : 18);
EditorGUI.PropertyField(drawRect, m_Theme, GUIContent.none);
if (m_ThemeModuleToggle)
{
EditorGUI.indentLevel++;
for (int i = 0; i < m_ColorPalette.arraySize; i++)
drawRect.x = EditorGUIUtility.currentViewWidth - 65;
drawRect.width = 45;
if (GUI.Button(drawRect, new GUIContent("Reset", "Reset to theme default color")))
{
SerializedProperty element = m_ColorPalette.GetArrayElementAtIndex(i);
EditorGUI.PropertyField(drawRect, element);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
}
EditorGUI.indentLevel--;
}
m_CustomFont.objectReferenceValue = null;
m_CustomBackgroundColor.colorValue = Color.clear;
m_CustomTextColor.colorValue = Color.clear;
m_CustomSubTextColor.colorValue = Color.clear;
m_CustomLegendTextColor.colorValue = Color.clear;
m_CustomLegendUnableColor.colorValue = Color.clear;
m_CustomAxisTextColor.colorValue = Color.clear;
m_CustomAxisLineColor.colorValue = Color.clear;
m_CustomAxisSplitLineColor.colorValue = Color.clear;
m_CustomTooltipBackgroundColor.colorValue = Color.clear;
m_CustomTooltipFlagAreaColor.colorValue = Color.clear;
m_CustomTooltipTextColor.colorValue = Color.clear;
m_CustomTooltipLabelColor.colorValue = Color.clear;
m_CustomTooltipLineColor.colorValue = Color.clear;
m_CustomDataZoomLineColor.colorValue = Color.clear;
m_CustomDataZoomSelectedColor.colorValue = Color.clear;
m_CustomDataZoomTextColor.colorValue = Color.clear;
for (int i = 0; i < m_CustomColorPalette.arraySize; i++)
{
m_CustomColorPalette.GetArrayElementAtIndex(i).colorValue = Color.clear;
}
--EditorGUI.indentLevel;
ThemeInfo defaultThemeInfo = ThemeInfo.Default;
switch (m_Theme.enumValueIndex)
{
case ((int)Theme.Default): defaultThemeInfo = ThemeInfo.Default; break;
case ((int)Theme.Light): defaultThemeInfo = ThemeInfo.Light; break;
case ((int)Theme.Dark): defaultThemeInfo = ThemeInfo.Dark; break;
}
m_Font.objectReferenceValue = defaultThemeInfo.font;
m_BackgroundColor.colorValue = defaultThemeInfo.backgroundColor;
m_TextColor.colorValue = defaultThemeInfo.textColor;
m_SubTextColor.colorValue = defaultThemeInfo.titleSubTextColor;
m_LegendTextColor.colorValue = defaultThemeInfo.legendTextColor;
m_LegendUnableColor.colorValue = defaultThemeInfo.legendUnableColor;
m_AxisTextColor.colorValue = defaultThemeInfo.axisTextColor;
m_AxisLineColor.colorValue = defaultThemeInfo.axisLineColor;
m_AxisSplitLineColor.colorValue = defaultThemeInfo.axisSplitLineColor;
m_TooltipBackgroundColor.colorValue = defaultThemeInfo.tooltipBackgroundColor;
m_TooltipFlagAreaColor.colorValue = defaultThemeInfo.tooltipFlagAreaColor;
m_TooltipTextColor.colorValue = defaultThemeInfo.tooltipTextColor;
m_TooltipLabelColor.colorValue = defaultThemeInfo.tooltipLabelColor;
m_TooltipLineColor.colorValue = defaultThemeInfo.tooltipLineColor;
m_DataZoomLineColor.colorValue = defaultThemeInfo.dataZoomLineColor;
m_DataZoomSelectedColor.colorValue = defaultThemeInfo.dataZoomSelectedColor;
m_DataZoomTextColor.colorValue = defaultThemeInfo.dataZoomTextColor;
for (int i = 0; i < m_ColorPalette.arraySize; i++)
{
m_ColorPalette.GetArrayElementAtIndex(i).colorValue = defaultThemeInfo.GetColor(i);
}
}
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
drawRect.x = defaultX;
drawRect.width = defaultWidth;
++EditorGUI.indentLevel;
var font = m_Font.objectReferenceValue as Font;
EditorGUI.PropertyField(drawRect, m_Font);
if (font != m_Font.objectReferenceValue)
{
m_CustomFont.objectReferenceValue = m_Font.objectReferenceValue;
}
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.BeginChangeCheck();
var color = m_CustomBackgroundColor.colorValue != Color.clear ? m_CustomBackgroundColor : m_BackgroundColor;
EditorGUI.PropertyField(drawRect, color, new GUIContent("Background Color"));
if (EditorGUI.EndChangeCheck())
{
m_CustomBackgroundColor.colorValue = color.colorValue;
}
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.BeginChangeCheck();
color = m_CustomTextColor.colorValue != Color.clear ? m_CustomTextColor : m_TextColor;
EditorGUI.PropertyField(drawRect, color, new GUIContent("Text Color"));
if (EditorGUI.EndChangeCheck())
{
m_CustomTextColor.colorValue = color.colorValue;
}
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.BeginChangeCheck();
color = m_CustomSubTextColor.colorValue != Color.clear ? m_CustomSubTextColor : m_SubTextColor;
EditorGUI.PropertyField(drawRect, color, new GUIContent("SubText Color"));
if (EditorGUI.EndChangeCheck())
{
m_CustomSubTextColor.colorValue = color.colorValue;
}
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.BeginChangeCheck();
color = m_CustomLegendTextColor.colorValue != Color.clear ? m_CustomLegendTextColor : m_LegendTextColor;
EditorGUI.PropertyField(drawRect, color, new GUIContent("LegendText Color"));
if (EditorGUI.EndChangeCheck())
{
m_CustomLegendTextColor.colorValue = color.colorValue;
}
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.BeginChangeCheck();
color = m_CustomLegendUnableColor.colorValue != Color.clear ? m_CustomLegendUnableColor : m_LegendUnableColor;
EditorGUI.PropertyField(drawRect, color, new GUIContent("LegendUnable Color"));
if (EditorGUI.EndChangeCheck())
{
m_CustomLegendUnableColor.colorValue = color.colorValue;
}
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.BeginChangeCheck();
color = m_CustomAxisTextColor.colorValue != Color.clear ? m_CustomAxisTextColor : m_AxisTextColor;
EditorGUI.PropertyField(drawRect, color, new GUIContent("AxisText Color"));
if (EditorGUI.EndChangeCheck())
{
m_CustomAxisTextColor.colorValue = color.colorValue;
}
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.BeginChangeCheck();
color = m_CustomAxisLineColor.colorValue != Color.clear ? m_CustomAxisLineColor : m_AxisLineColor;
EditorGUI.PropertyField(drawRect, color, new GUIContent("AxisLine Color"));
if (EditorGUI.EndChangeCheck())
{
m_CustomAxisLineColor.colorValue = color.colorValue;
}
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.BeginChangeCheck();
color = m_CustomAxisSplitLineColor.colorValue != Color.clear ? m_CustomAxisSplitLineColor : m_AxisSplitLineColor;
EditorGUI.PropertyField(drawRect, color, new GUIContent("AxisSplitLine Color"));
if (EditorGUI.EndChangeCheck())
{
m_CustomAxisSplitLineColor.colorValue = color.colorValue;
}
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.BeginChangeCheck();
color = m_CustomTooltipBackgroundColor.colorValue != Color.clear ? m_CustomTooltipBackgroundColor : m_TooltipBackgroundColor;
EditorGUI.PropertyField(drawRect, color, new GUIContent("Tooltip Background Color"));
if (EditorGUI.EndChangeCheck())
{
m_CustomTooltipBackgroundColor.colorValue = color.colorValue;
}
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.BeginChangeCheck();
color = m_CustomTooltipFlagAreaColor.colorValue != Color.clear ? m_CustomTooltipFlagAreaColor : m_TooltipFlagAreaColor;
EditorGUI.PropertyField(drawRect, color, new GUIContent("Tooltip FlagArea Color"));
if (EditorGUI.EndChangeCheck())
{
m_CustomTooltipFlagAreaColor.colorValue = color.colorValue;
}
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.BeginChangeCheck();
color = m_CustomTooltipTextColor.colorValue != Color.clear ? m_CustomTooltipTextColor : m_TooltipTextColor;
EditorGUI.PropertyField(drawRect, color, new GUIContent("Tooltip Text Color"));
if (EditorGUI.EndChangeCheck())
{
m_CustomTooltipTextColor.colorValue = color.colorValue;
}
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.BeginChangeCheck();
color = m_CustomTooltipLabelColor.colorValue != Color.clear ? m_CustomTooltipLabelColor : m_TooltipLabelColor;
EditorGUI.PropertyField(drawRect, color, new GUIContent("Tooltip Label Color"));
if (EditorGUI.EndChangeCheck())
{
m_CustomTooltipLabelColor.colorValue = color.colorValue;
}
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.BeginChangeCheck();
color = m_CustomTooltipLineColor.colorValue != Color.clear ? m_CustomTooltipLineColor : m_TooltipLineColor;
EditorGUI.PropertyField(drawRect, color, new GUIContent("Tooltip Line Color"));
if (EditorGUI.EndChangeCheck())
{
m_CustomTooltipLineColor.colorValue = color.colorValue;
}
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.BeginChangeCheck();
color = m_CustomDataZoomLineColor.colorValue != Color.clear ? m_CustomDataZoomLineColor : m_DataZoomLineColor;
EditorGUI.PropertyField(drawRect, color, new GUIContent("DataZoom Line Color"));
if (EditorGUI.EndChangeCheck())
{
m_CustomDataZoomLineColor.colorValue = color.colorValue;
}
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.BeginChangeCheck();
color = m_CustomDataZoomSelectedColor.colorValue != Color.clear ? m_CustomDataZoomSelectedColor : m_DataZoomSelectedColor;
EditorGUI.PropertyField(drawRect, color, new GUIContent("DataZoom Selected Color"));
if (EditorGUI.EndChangeCheck())
{
m_CustomDataZoomSelectedColor.colorValue = color.colorValue;
}
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.BeginChangeCheck();
color = m_CustomDataZoomTextColor.colorValue != Color.clear ? m_CustomDataZoomTextColor : m_DataZoomTextColor;
EditorGUI.PropertyField(drawRect, color, new GUIContent("DataZoom Text Color"));
if (EditorGUI.EndChangeCheck())
{
m_CustomDataZoomTextColor.colorValue = color.colorValue;
}
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
m_ColorPaletteFoldout = EditorGUI.Foldout(drawRect, m_ColorPaletteFoldout, "ColorPalette");
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
if (m_ColorPaletteFoldout)
{
EditorGUI.indentLevel++;
for (int i = 0; i < m_ColorPalette.arraySize; i++)
{
while (i > m_CustomColorPalette.arraySize - 1)
{
m_CustomColorPalette.InsertArrayElementAtIndex(m_CustomColorPalette.arraySize);
}
var customElement = m_CustomColorPalette.GetArrayElementAtIndex(i);
color = customElement.colorValue != Color.clear ?
customElement :
m_ColorPalette.GetArrayElementAtIndex(i);
EditorGUI.BeginChangeCheck();
EditorGUI.PropertyField(drawRect, color);
if (EditorGUI.EndChangeCheck())
{
customElement.colorValue = color.colorValue;
}
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
}
EditorGUI.indentLevel--;
}
--EditorGUI.indentLevel;
}
}
public override float GetPropertyHeight(SerializedProperty prop, GUIContent label)
{
float height = 0;
int propertyCount = 17;
if (m_ColorPaletteFoldout)
if (!m_ThemeModuleToggle)
{
SerializedProperty m_ColorPalette = prop.FindPropertyRelative("m_ColorPalette");
propertyCount += m_ColorPalette.arraySize + 1;
return EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
}
else
{
propertyCount += 1;
float height = 0;
int propertyCount = 18;
if (m_ColorPaletteFoldout)
{
SerializedProperty m_ColorPalette = prop.FindPropertyRelative("m_ColorPalette");
propertyCount += m_ColorPalette.arraySize + 1;
}
else
{
propertyCount += 1;
}
height += propertyCount * EditorGUIUtility.singleLineHeight + (propertyCount - 1) * EditorGUIUtility.standardVerticalSpacing;
return height;
}
height += propertyCount * EditorGUIUtility.singleLineHeight + (propertyCount - 1) * EditorGUIUtility.standardVerticalSpacing;
return height;
}
}
}