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

This commit is contained in:
monitor1394
2019-07-24 09:41:27 +08:00
parent 00158aed82
commit 53acc084f8
8 changed files with 13374 additions and 10923 deletions

View File

@@ -1,5 +1,4 @@
using System.Linq;
using System.Collections.Generic;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
@@ -156,7 +155,6 @@ public class Demo : MonoBehaviour
m_ScrollRect.content = selectedModule.panel.GetComponent<RectTransform>();
m_Title.text = string.IsNullOrEmpty(selectedModule.title) ?
selectedModule.name : selectedModule.title;
SelecteTheme(m_SelectedTheme);
}
void InitThemeButton()
@@ -173,7 +171,7 @@ public class Demo : MonoBehaviour
m_LightThemeButton.onClick.AddListener(delegate () { SelecteTheme(Theme.Light); });
m_DarkThemeButton.onClick.AddListener(delegate () { SelecteTheme(Theme.Dark); });
SelecteTheme(Theme.Default);
//SelecteTheme(Theme.Default);
}
void SelecteTheme(Theme theme)

File diff suppressed because it is too large Load Diff

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

View File

@@ -21,7 +21,6 @@ namespace XCharts
[SerializeField] protected float m_ChartWidth;
[SerializeField] protected float m_ChartHeight;
[SerializeField] protected Theme m_Theme = Theme.Default;
[SerializeField] protected ThemeInfo m_ThemeInfo;
[SerializeField] protected Title m_Title = Title.defaultTitle;
[SerializeField] protected Legend m_Legend = Legend.defaultLegend;
@@ -291,7 +290,7 @@ namespace XCharts
/// <param name="theme">theme</param>
public void UpdateTheme(Theme theme)
{
this.m_Theme = theme;
m_ThemeInfo.theme = theme;
OnThemeChanged();
RefreshChart();
}
@@ -310,7 +309,7 @@ namespace XCharts
m_ChartHeight = rectTransform.sizeDelta.y;
m_CheckWidth = m_ChartWidth;
m_CheckHeight = m_ChartHeight;
m_CheckTheme = m_Theme;
m_CheckTheme = m_ThemeInfo.theme;
InitTitle();
InitLegend();
InitTooltip();
@@ -495,9 +494,9 @@ namespace XCharts
private void CheckTheme()
{
if (m_CheckTheme != m_Theme)
if (m_CheckTheme != m_ThemeInfo.theme)
{
m_CheckTheme = m_Theme;
m_CheckTheme = m_ThemeInfo.theme;
OnThemeChanged();
}
}
@@ -596,7 +595,7 @@ namespace XCharts
protected virtual void OnThemeChanged()
{
switch (m_Theme)
switch (m_ThemeInfo.theme)
{
case Theme.Dark:
m_ThemeInfo.Copy(ThemeInfo.Dark);

View File

@@ -7,7 +7,7 @@ namespace XCharts
{
public enum Theme
{
Default = 1,
Default,
Light,
Dark
}
@@ -15,6 +15,7 @@ namespace XCharts
[Serializable]
public class ThemeInfo : IEquatable<ThemeInfo>
{
[SerializeField] private Theme m_Theme = Theme.Default;
[SerializeField] private Font m_Font;
[SerializeField] private Color32 m_BackgroundColor;
[SerializeField] private Color32 m_TextColor;
@@ -34,33 +35,128 @@ namespace XCharts
[SerializeField] private Color32 m_DataZoomSelectedColor;
[SerializeField] private Color32[] m_ColorPalette;
public Font font { get { return m_Font; } set { m_Font = value; } }
public Color32 backgroundColor { get { return m_BackgroundColor; } set { m_BackgroundColor = value; } }
public Color32 textColor { get { return m_TextColor; } set { m_TextColor = value; } }
public Color32 titleSubTextColor { get { return m_TitleSubTextColor; } set { m_TitleSubTextColor = value; } }
public Color32 legendTextColor { get { return m_LegendTextColor; } set { m_LegendTextColor = value; } }
public Color32 legendUnableColor { get { return m_LegendUnableColor; } set { m_LegendUnableColor = value; } }
public Color32 axisTextColor { get { return m_AxisTextColor; } set { m_AxisTextColor = value; } }
public Color32 axisLineColor { get { return m_AxisLineColor; } set { m_AxisLineColor = value; } }
public Color32 axisSplitLineColor { get { return m_AxisSplitLineColor; } set { m_AxisSplitLineColor = value; } }
public Color32 tooltipBackgroundColor { get { return m_TooltipBackgroundColor; } set { m_TooltipBackgroundColor = value; } }
public Color32 tooltipFlagAreaColor { get { return m_TooltipFlagAreaColor; } set { m_TooltipFlagAreaColor = value; } }
public Color32 tooltipTextColor { get { return m_TooltipTextColor; } set { m_TooltipTextColor = value; } }
public Color32 tooltipLabelColor { get { return m_TooltipLabelColor; } set { m_TooltipLabelColor = value; } }
public Color32 tooltipLineColor { get { return m_TooltipLineColor; } set { m_TooltipLineColor = value; } }
public Color32 dataZoomTextColor { get { return m_DataZoomTextColor; } set { m_DataZoomTextColor = value; } }
public Color32 dataZoomLineColor { get { return m_DataZoomLineColor; } set { m_DataZoomLineColor = value; } }
public Color32 dataZoomSelectedColor { get { return m_DataZoomSelectedColor; } set { m_DataZoomSelectedColor = value; } }
public Color32[] colorPalette { get { return m_ColorPalette; } set { m_ColorPalette = value; } }
[SerializeField] private Font m_CustomFont;
[SerializeField] private Color32 m_CustomBackgroundColor;
[SerializeField] private Color32 m_CustomTextColor;
[SerializeField] private Color32 m_CustomTitleSubTextColor;
[SerializeField] private Color32 m_CustomLegendTextColor;
[SerializeField] private Color32 m_CustomLegendUnableColor;
[SerializeField] private Color32 m_CustomAxisTextColor;
[SerializeField] private Color32 m_CustomAxisLineColor;
[SerializeField] private Color32 m_CustomAxisSplitLineColor;
[SerializeField] private Color32 m_CustomTooltipBackgroundColor;
[SerializeField] private Color32 m_CustomTooltipFlagAreaColor;
[SerializeField] private Color32 m_CustomTooltipTextColor;
[SerializeField] private Color32 m_CustomTooltipLabelColor;
[SerializeField] private Color32 m_CustomTooltipLineColor;
[SerializeField] private Color32 m_CustomDataZoomTextColor;
[SerializeField] private Color32 m_CustomDataZoomLineColor;
[SerializeField] private Color32 m_CustomDataZoomSelectedColor;
[SerializeField] private List<Color32> m_CustomColorPalette = new List<Color32>(13);
public Theme theme { get { return m_Theme; } set { m_Theme = value; } }
public Font font
{
get { return m_CustomFont != null ? m_CustomFont : m_Font; }
set { m_CustomFont = value; }
}
public Color32 backgroundColor
{
get { return m_CustomBackgroundColor != Color.clear ? m_CustomBackgroundColor : m_BackgroundColor; }
set { m_CustomBackgroundColor = value; }
}
public Color32 textColor
{
get { return m_CustomTextColor != Color.clear ? m_CustomTextColor : m_TextColor; }
set { m_CustomTextColor = value; }
}
public Color32 titleSubTextColor
{
get { return m_CustomTitleSubTextColor != Color.clear ? m_CustomTitleSubTextColor : m_TitleSubTextColor; }
set { m_CustomTitleSubTextColor = value; }
}
public Color32 legendTextColor
{
get { return m_CustomLegendTextColor != Color.clear ? m_CustomLegendTextColor : m_LegendTextColor; }
set { m_CustomLegendTextColor = value; }
}
public Color32 legendUnableColor
{
get { return m_CustomLegendUnableColor != Color.clear ? m_CustomLegendUnableColor : m_LegendUnableColor; }
set { m_CustomLegendUnableColor = value; }
}
public Color32 axisTextColor
{
get { return m_CustomAxisTextColor != Color.clear ? m_CustomAxisTextColor : m_AxisTextColor; }
set { m_CustomAxisTextColor = value; }
}
public Color32 axisLineColor
{
get { return m_CustomAxisLineColor != Color.clear ? m_CustomAxisLineColor : m_AxisLineColor; }
set { m_CustomAxisLineColor = value; }
}
public Color32 axisSplitLineColor
{
get { return m_CustomAxisSplitLineColor != Color.clear ? m_CustomAxisSplitLineColor : m_AxisSplitLineColor; }
set { m_CustomAxisSplitLineColor = value; }
}
public Color32 tooltipBackgroundColor
{
get { return m_CustomTooltipBackgroundColor != Color.clear ? m_CustomTooltipBackgroundColor : m_TooltipBackgroundColor; }
set { m_CustomTooltipBackgroundColor = value; }
}
public Color32 tooltipFlagAreaColor
{
get { return m_CustomTooltipFlagAreaColor != Color.clear ? m_CustomTooltipFlagAreaColor : m_TooltipFlagAreaColor; }
set { m_CustomTooltipFlagAreaColor = value; }
}
public Color32 tooltipTextColor
{
get { return m_CustomTooltipTextColor != Color.clear ? m_CustomTooltipTextColor : m_TooltipTextColor; }
set { m_CustomTooltipTextColor = value; }
}
public Color32 tooltipLabelColor
{
get { return m_CustomTooltipLabelColor != Color.clear ? m_CustomTooltipLabelColor : m_TooltipLabelColor; }
set { m_CustomTooltipLabelColor = value; }
}
public Color32 tooltipLineColor
{
get { return m_CustomTooltipLineColor != Color.clear ? m_CustomTooltipLineColor : m_TooltipLineColor; }
set { m_CustomTooltipLineColor = value; }
}
public Color32 dataZoomTextColor
{
get { return m_CustomDataZoomTextColor != Color.clear ? m_CustomDataZoomTextColor : m_DataZoomTextColor; }
set { m_CustomDataZoomTextColor = value; }
}
public Color32 dataZoomLineColor
{
get { return m_CustomDataZoomLineColor != Color.clear ? m_CustomDataZoomLineColor : m_DataZoomLineColor; }
set { m_CustomDataZoomLineColor = value; }
}
public Color32 dataZoomSelectedColor
{
get { return m_CustomDataZoomSelectedColor != Color.clear ? m_CustomDataZoomSelectedColor : m_DataZoomSelectedColor; }
set { m_CustomDataZoomSelectedColor = value; }
}
public List<Color32> colorPalette { set { m_CustomColorPalette = value; } }
public Color32 GetColor(int index)
{
if (index < 0)
if (index < 0) index = 0;
var customIndex = index >= m_CustomColorPalette.Count ? index : index % m_CustomColorPalette.Count;
if (customIndex < m_CustomColorPalette.Count && m_CustomColorPalette[customIndex] != Color.clear)
{
index = 0;
return m_CustomColorPalette[customIndex];
}
else
{
var newIndex = index >= m_ColorPalette.Length ? index : index % m_ColorPalette.Length;
if (newIndex < m_ColorPalette.Length)
return m_ColorPalette[newIndex];
else return Color.clear;
}
index = index % m_ColorPalette.Length;
return m_ColorPalette[index];
}
Dictionary<int, string> _colorDic = new Dictionary<int, string>();
@@ -81,6 +177,7 @@ namespace XCharts
public void Copy(ThemeInfo theme)
{
m_Theme = theme.theme;
m_Font = theme.m_Font;
m_BackgroundColor = theme.m_BackgroundColor;
m_LegendUnableColor = theme.m_LegendUnableColor;
@@ -104,12 +201,38 @@ namespace XCharts
}
}
public void Reset()
{
m_Theme = Theme.Default;
m_Font = null;
m_BackgroundColor = Color.clear;
m_LegendUnableColor = Color.clear;
m_TextColor = Color.clear;
m_TitleSubTextColor = Color.clear;
m_LegendTextColor = Color.clear;
m_AxisTextColor = Color.clear;
m_AxisLineColor = Color.clear;
m_AxisSplitLineColor = Color.clear;
m_TooltipBackgroundColor = Color.clear;
m_TooltipTextColor = Color.clear;
m_TooltipLabelColor = Color.clear;
m_TooltipLineColor = Color.clear;
m_DataZoomLineColor = Color.clear;
m_DataZoomSelectedColor = Color.clear;
m_DataZoomTextColor = Color.clear;
for (int i = 0; i < m_CustomColorPalette.Count; i++)
{
m_CustomColorPalette[i] = Color.clear;
}
}
public static ThemeInfo Default
{
get
{
return new ThemeInfo()
{
m_Theme = Theme.Default,
m_Font = Resources.GetBuiltinResource<Font>("Arial.ttf"),
m_BackgroundColor = new Color32(255, 255, 255, 255),
m_LegendUnableColor = GetColor("#cccccc"),
@@ -140,6 +263,19 @@ namespace XCharts
new Color32(110, 112, 116, 255),
new Color32(84, 101, 112, 255),
new Color32(196, 204, 211, 255)
},
m_CustomColorPalette = new List<Color32>{
Color.clear,
Color.clear,
Color.clear,
Color.clear,
Color.clear,
Color.clear,
Color.clear,
Color.clear,
Color.clear,
Color.clear,
Color.clear
}
};
}
@@ -151,6 +287,7 @@ namespace XCharts
{
return new ThemeInfo()
{
m_Theme = Theme.Light,
m_Font = Resources.GetBuiltinResource<Font>("Arial.ttf"),
m_BackgroundColor = new Color32(255, 255, 255, 255),
m_LegendUnableColor = GetColor("#cccccc"),
@@ -183,6 +320,21 @@ namespace XCharts
new Color32(157, 150, 245, 255),
new Color32(131, 120, 234, 255),
new Color32(150, 191, 255, 255)
},
m_CustomColorPalette = new List<Color32>{
Color.clear,
Color.clear,
Color.clear,
Color.clear,
Color.clear,
Color.clear,
Color.clear,
Color.clear,
Color.clear,
Color.clear,
Color.clear,
Color.clear,
Color.clear
}
};
}
@@ -194,6 +346,7 @@ namespace XCharts
{
return new ThemeInfo()
{
m_Theme = Theme.Dark,
m_Font = Resources.GetBuiltinResource<Font>("Arial.ttf"),
m_LegendUnableColor = GetColor("#cccccc"),
m_BackgroundColor = new Color32(34, 34, 34, 255),
@@ -224,6 +377,19 @@ namespace XCharts
new Color32(114, 137, 171, 255),
new Color32(145, 202, 140, 255),
new Color32(244, 159, 66, 255)
},
m_CustomColorPalette = new List<Color32>{
Color.clear,
Color.clear,
Color.clear,
Color.clear,
Color.clear,
Color.clear,
Color.clear,
Color.clear,
Color.clear,
Color.clear,
Color.clear
}
};
}

View File

@@ -142,7 +142,7 @@ namespace XCharts
{
base.OnThemeChanged();
m_Radar.backgroundColorList.Clear();
switch (m_Theme)
switch (m_ThemeInfo.theme)
{
case Theme.Dark:
m_Radar.backgroundColorList.Add(ThemeInfo.GetColor("#6f6f6f"));

View File

@@ -23,6 +23,7 @@ QQ交流群XCharts交流群202030963
## 更新日志
* 2019.07.23)优化`Theme`主题的自定义,切换主题时自定义配置不受影响
* 2019.07.22)增加`EffectScatter`类型的散点图
* 2019.07.21)增加`ScatterChart`散点图
* 2019.07.21)增加`SerieData`支持多维数据配置