8 using System.Collections.Generic;
18 [CustomEditor(typeof(BaseChart),
false)]
21 #if UNITY_2019_3_OR_NEWER
22 private const float k_IconWidth = 14;
23 private const float k_IconGap = 0f;
24 private const float k_IconXOffset = 10f;
25 private const float k_IconYOffset = -1.5f;
27 private const float k_IconWidth = 14;
28 private const float k_IconGap = 0f;
29 private const float k_IconXOffset = 4f;
30 private const float k_IconYOffset = -3f;
34 protected SerializedProperty m_Script;
35 protected SerializedProperty m_MultiComponentMode;
36 protected SerializedProperty m_EnableTextMeshPro;
37 protected SerializedProperty m_ChartWidth;
38 protected SerializedProperty m_ChartHeight;
39 protected SerializedProperty m_Settings;
40 protected SerializedProperty m_Theme;
41 protected SerializedProperty m_Background;
42 protected SerializedProperty m_Titles;
43 protected SerializedProperty m_Legends;
44 protected SerializedProperty m_Tooltips;
45 protected SerializedProperty m_Vessels;
46 protected SerializedProperty m_Radars;
47 protected SerializedProperty m_Series;
48 protected SerializedProperty m_Large;
49 protected SerializedProperty m_ChartName;
50 protected SerializedProperty m_DebugMode;
52 protected float m_DefaultLabelWidth;
53 protected float m_DefaultFieldWidth;
54 private int m_SeriesSize;
55 private Vector2 scrollPos;
56 private bool m_CheckWarning =
false;
57 private StringBuilder sb =
new StringBuilder();
59 private bool m_BaseFoldout;
60 private bool m_CustomFoldout;
61 protected bool m_ShowAllComponent;
62 protected Dictionary<string, bool> m_Flodouts =
new Dictionary<string, bool>();
64 protected virtual void OnEnable()
66 if (target ==
null)
return;
68 m_Script = serializedObject.FindProperty(
"m_Script");
69 m_MultiComponentMode = serializedObject.FindProperty(
"m_MultiComponentMode");
70 m_EnableTextMeshPro = serializedObject.FindProperty(
"m_EnableTextMeshPro");
71 m_ChartName = serializedObject.FindProperty(
"m_ChartName");
72 m_ChartWidth = serializedObject.FindProperty(
"m_ChartWidth");
73 m_ChartHeight = serializedObject.FindProperty(
"m_ChartHeight");
74 m_Theme = serializedObject.FindProperty(
"m_Theme");
75 m_Settings = serializedObject.FindProperty(
"m_Settings");
76 m_Background = serializedObject.FindProperty(
"m_Background");
77 m_Titles = serializedObject.FindProperty(
"m_Titles");
78 m_Legends = serializedObject.FindProperty(
"m_Legends");
79 m_Tooltips = serializedObject.FindProperty(
"m_Tooltips");
80 m_Vessels = serializedObject.FindProperty(
"m_Vessels");
81 m_Series = serializedObject.FindProperty(
"m_Series");
82 m_Radars = serializedObject.FindProperty(
"m_Radars");
84 m_Large = serializedObject.FindProperty(
"m_Large");
85 m_DebugMode = serializedObject.FindProperty(
"m_DebugMode");
88 public override void OnInspectorGUI()
90 if (m_Chart ==
null && target ==
null)
92 base.OnInspectorGUI();
95 serializedObject.Update();
96 m_DefaultLabelWidth = EditorGUIUtility.labelWidth;
97 m_DefaultFieldWidth = EditorGUIUtility.fieldWidth;
99 OnStartInspectorGUI();
100 OnMiddleInspectorGUI();
102 OnDebugInspectorGUI();
104 EditorGUILayout.Space();
105 serializedObject.ApplyModifiedProperties();
108 protected virtual void OnStartInspectorGUI()
111 EditorGUILayout.BeginHorizontal();
113 if (m_EnableTextMeshPro.boolValue)
117 EditorGUILayout.LabelField(version);
119 if (GUILayout.Button(
"Github"))
121 Application.OpenURL(
"https://github.com/monitor1394/unity-ugui-XCharts");
123 EditorGUILayout.EndHorizontal();
127 m_BaseFoldout = EditorGUILayout.Foldout(m_BaseFoldout,
"Base",
true);
130 EditorGUILayout.PropertyField(m_Script);
131 EditorGUILayout.PropertyField(m_ChartName);
132 var fileds = m_Chart.GetCustomChartInspectorShowFileds();
133 if (fileds !=
null && fileds.Length > 0)
135 foreach (var filed
in fileds)
137 EditorGUILayout.PropertyField(serializedObject.FindProperty(filed));
144 BlockField(m_Settings);
145 BlockField(m_Background);
147 m_ShowAllComponent = m_MultiComponentMode.boolValue;
148 BlockListField(m_ShowAllComponent, m_Titles);
149 BlockListField(m_ShowAllComponent, m_Legends);
150 BlockListField(m_ShowAllComponent, m_Tooltips);
151 BlockListField(m_ShowAllComponent,
SerieType.Liquid, m_Vessels);
152 BlockListField(m_ShowAllComponent,
SerieType.Radar, m_Radars);
155 protected virtual void OnMiddleInspectorGUI()
157 BlockField(m_Series);
160 protected virtual void OnEndInspectorGUI()
164 protected virtual void OnDebugInspectorGUI()
167 EditorGUILayout.PropertyField(m_DebugMode);
168 EditorGUILayout.PropertyField(m_MultiComponentMode);
169 EditorGUILayout.Space();
170 EditorGUILayout.Space();
171 MoreDebugInspector();
176 protected virtual void MoreDebugInspector()
180 protected void BlockStart()
182 if (
XChartsSettings.editorBlockEnable) EditorGUILayout.BeginVertical(EditorStyles.helpBox);
185 protected void BlockEnd()
190 protected void BlockField(params SerializedProperty[] props)
192 if (props.Length == 0)
return;
194 foreach (var prop
in props)
195 EditorGUILayout.PropertyField(prop,
true);
199 protected void BlockListField(
bool all, params SerializedProperty[] props)
201 if (props.Length == 0)
return;
203 foreach (var prop
in props)
207 var flag = m_Flodouts.ContainsKey(prop.displayName) && m_Flodouts[prop.displayName];
208 m_Flodouts[prop.displayName] = EditorGUILayout.Foldout(flag, prop.displayName,
true);
209 if (m_Flodouts[prop.displayName])
211 EditorGUI.indentLevel++;
212 var currRect = EditorGUILayout.GetControlRect(GUILayout.Height(0));
213 currRect.y -= EditorGUIUtility.singleLineHeight;
214 var rect1 =
new Rect(currRect.width + k_IconXOffset,
215 currRect.y + k_IconYOffset,
216 k_IconWidth, EditorGUIUtility.singleLineHeight);
219 prop.InsertArrayElementAtIndex(prop.arraySize > 0 ? prop.arraySize - 1 : 0);
220 var chart = prop.GetArrayElementAtIndex(0).serializedObject.targetObject as
BaseChart;
221 serializedObject.ApplyModifiedProperties();
222 chart.RemoveChartObject();
223 chart.RefreshAllComponent();
225 for (
int i = 0; i < prop.arraySize; i++)
227 EditorGUILayout.PropertyField(prop.GetArrayElementAtIndex(i),
true);
228 currRect = EditorGUILayout.GetControlRect(GUILayout.Height(0));
229 currRect.y -= EditorGUI.GetPropertyHeight(prop.GetArrayElementAtIndex(i));
230 rect1 =
new Rect(currRect.width + k_IconXOffset,
231 currRect.y + k_IconYOffset,
232 k_IconWidth, EditorGUIUtility.singleLineHeight);
233 var oldColor = GUI.contentColor;
234 GUI.contentColor = Color.black;
237 if (prop.arraySize == 1)
239 if (EditorUtility.DisplayDialog(
"Delete component",
"Confirm to delete last component?",
"Sure",
"Cancel"))
241 var chart = prop.GetArrayElementAtIndex(0).serializedObject.targetObject as
BaseChart;
242 prop.DeleteArrayElementAtIndex(i);
243 serializedObject.ApplyModifiedProperties();
244 chart.RemoveChartObject();
245 chart.RefreshAllComponent();
248 else if (i < prop.arraySize && i >= 0)
250 var chart = prop.GetArrayElementAtIndex(0).serializedObject.targetObject as
BaseChart;
251 prop.DeleteArrayElementAtIndex(i);
252 serializedObject.ApplyModifiedProperties();
253 chart.RemoveChartObject();
254 chart.RefreshAllComponent();
257 var rect2 =
new Rect(currRect.width + k_IconXOffset - k_IconWidth - k_IconGap,
258 currRect.y + k_IconYOffset,
259 k_IconWidth, EditorGUIUtility.singleLineHeight);
262 if (i < prop.arraySize - 1) prop.MoveArrayElement(i, i + 1);
264 var rect3 =
new Rect(currRect.width + k_IconXOffset - 2 * (k_IconWidth + k_IconGap),
265 currRect.y + k_IconYOffset,
266 k_IconWidth, EditorGUIUtility.singleLineHeight);
269 if (i > 0) prop.MoveArrayElement(i, i - 1);
271 GUI.contentColor = oldColor;
273 EditorGUI.indentLevel--;
276 else if (prop.arraySize > 0) EditorGUILayout.PropertyField(prop.GetArrayElementAtIndex(0),
true);
281 protected void BlockListField(
bool all,
SerieType serieType, params SerializedProperty[] props)
283 if (!m_Chart.ContainsSerie(serieType))
return;
284 BlockListField(all, props);
287 private void CheckWarning()
289 if (GUILayout.Button(
"Remove All Chart Object"))
291 m_Chart.RemoveChartObject();
299 EditorGUILayout.BeginHorizontal();
300 if (GUILayout.Button(
"Check Warning"))
302 m_CheckWarning =
true;
303 m_Chart.CheckWarning();
305 if (GUILayout.Button(
"Hide Warning"))
307 m_CheckWarning =
false;
309 EditorGUILayout.EndHorizontal();
311 sb.AppendFormat(
"v{0}",
XChartsMgr.fullVersion);
312 if (!
string.IsNullOrEmpty(m_Chart.warningInfo))
315 sb.Append(m_Chart.warningInfo);
320 sb.Append(
"Perfect! No warning!");
322 EditorGUILayout.HelpBox(sb.ToString(), MessageType.Warning);
326 if (GUILayout.Button(
"Check warning"))
328 m_CheckWarning =
true;
329 m_Chart.CheckWarning();
332 EditorGUILayout.Space();