17 [CustomPropertyDrawer(typeof(ChartTheme),
true)]
20 public override string ClassName {
get {
return "Theme"; } }
21 public override void OnGUI(
Rect pos, SerializedProperty prop, GUIContent label)
23 base.OnGUI(pos, prop, label);
24 var defaultWidth = pos.width;
27 if (MakeFoldout(prop,
""))
29 var btnRect =
new Rect(m_DrawRect);
30 btnRect.x = defaultX + defaultWidth - 2 * btnWidth - 2;
31 btnRect.y = m_DrawRect.y - EditorGUIUtility.singleLineHeight - 3;
32 btnRect.width = btnWidth;
33 var chart = prop.serializedObject.targetObject as
BaseChart;
34 if (GUI.Button(btnRect,
new GUIContent(
"Reset",
"Reset to theme default color")))
37 chart.RefreshAllComponent();
39 btnRect.x = defaultX + defaultWidth - btnWidth;
40 btnRect.width = btnWidth;
41 if (GUI.Button(btnRect,
new GUIContent(
"Export",
"Export theme to asset for a new theme")))
46 ++EditorGUI.indentLevel;
47 var chartNameList = XThemeMgr.GetAllThemeNames();
48 var lastIndex = chartNameList.IndexOf(chart.theme.themeName);
49 var y = pos.y + EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
50 var selectedIndex = EditorGUI.Popup(
new Rect(pos.x, y, pos.width, EditorGUIUtility.singleLineHeight),
51 "Theme", lastIndex, chartNameList.ToArray());
52 AddSingleLineHeight();
53 if (lastIndex != selectedIndex)
55 XThemeMgr.SwitchTheme(chart, chartNameList[selectedIndex]);
58 PropertyField(prop,
"m_TMPFont");
59 if(chart.theme.tmpFont ==
null && !
string.IsNullOrEmpty(chart.theme.tmpFontName))
61 var msg =
string.Format(
"Can't find theme font asset:{0} in project.", chart.theme.tmpFontName);
62 EditorGUILayout.HelpBox(msg, MessageType.Error);
65 PropertyField(prop,
"m_Font");
66 if (chart.theme.font ==
null && !
string.IsNullOrEmpty(chart.theme.fontName))
68 var msg =
string.Format(
"Can't find theme font asset:{0} in project.", chart.theme.fontName);
69 EditorGUILayout.HelpBox(msg, MessageType.Error);
72 PropertyField(prop,
"m_ContrastColor");
73 PropertyField(prop,
"m_BackgroundColor");
74 PropertyField(prop,
"m_ColorPalette");
75 PropertyField(prop,
"m_Common");
76 PropertyField(prop,
"m_Title");
77 PropertyField(prop,
"m_SubTitle");
78 PropertyField(prop,
"m_Legend");
79 PropertyField(prop,
"m_Axis");
80 PropertyField(prop,
"m_RadiusAxis");
81 PropertyField(prop,
"m_AngleAxis");
82 PropertyField(prop,
"m_Polar");
83 PropertyField(prop,
"m_Gauge");
84 PropertyField(prop,
"m_Radar");
85 PropertyField(prop,
"m_Tooltip");
86 PropertyField(prop,
"m_DataZoom");
87 PropertyField(prop,
"m_VisualMap");
88 PropertyField(prop,
"m_Serie");
89 --EditorGUI.indentLevel;
93 private void AddPropertyField(
Rect pos, SerializedProperty prop, ref
float y)
95 float height = EditorGUI.GetPropertyHeight(prop,
new GUIContent(prop.displayName),
true);
96 EditorGUI.PropertyField(
new Rect(pos.x, y, pos.width, height), prop,
true);
97 y += height + EditorGUIUtility.standardVerticalSpacing;
98 m_Heights[m_KeyName] += height + EditorGUIUtility.standardVerticalSpacing;
106 private string m_ChartName;
110 window.minSize =
new Vector2(600, 50);
111 window.maxSize =
new Vector2(600, 50);
115 void OnInspectorUpdate()
128 GUILayout.Label(
"Input a new name for theme:");
129 m_ChartName = GUILayout.TextField(m_ChartName);
132 GUILayout.Label(
"Export path:");
133 if (
string.IsNullOrEmpty(m_ChartName))
135 GUILayout.Label(
"Need input a new name.");
139 GUILayout.Label(XThemeMgr.GetThemeAssetPath(m_ChartName));
143 if (GUILayout.Button(
"Export"))
145 if (
string.IsNullOrEmpty(m_ChartName))
147 ShowNotification(
new GUIContent(
"ERROR:Need input a new name!"));
149 else if (XThemeMgr.ContainsTheme(m_ChartName))
151 ShowNotification(
new GUIContent(
"ERROR:The name you entered is already in use!"));
153 else if (IsAssetsExist(XThemeMgr.GetThemeAssetPath(m_ChartName)))
155 ShowNotification(
new GUIContent(
"ERROR:The asset is exist! \npath="
156 + XThemeMgr.GetThemeAssetPath(m_ChartName)));
160 XThemeMgr.ExportTheme(target.
theme, m_ChartName);
161 ShowNotification(
new GUIContent(
"SUCCESS:The theme is exported. \npath="
162 + XThemeMgr.GetThemeAssetPath(m_ChartName)));
167 private bool IsAssetsExist(
string path)
169 return File.Exists(Application.dataPath +
"/../" + path);