暫無描述
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

SerieBaseEditor.cs 5.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEditor;
  4. using UnityEngine;
  5. using UnityEngine.Assertions;
  6. using XCharts.Runtime;
  7. namespace XCharts.Editor
  8. {
  9. public class SerieBaseEditor
  10. {
  11. internal BaseChart chart { get; private set; }
  12. internal Serie serie { get; private set; }
  13. //Editor m_Inspector;
  14. internal SerializedProperty baseProperty;
  15. internal SerializedProperty showProperty;
  16. internal List<HeaderMenuInfo> menus = new List<HeaderMenuInfo>();
  17. internal List<HeaderMenuInfo> serieDataMenus = new List<HeaderMenuInfo>();
  18. protected Dictionary<string, Type> m_CoordOptionsDic;
  19. protected List<string> m_CoordOptionsNames;
  20. private string m_DisplayName;
  21. internal void Init(BaseChart chart, Serie target, SerializedProperty property, UnityEditor.Editor inspector)
  22. {
  23. this.chart = chart;
  24. this.serie = target;
  25. this.baseProperty = property;
  26. m_DisplayName = string.Format("Serie {0}: {1}", serie.index, serie.GetType().Name);
  27. //m_Inspector = inspector;
  28. showProperty = baseProperty.FindPropertyRelative("m_Show");
  29. if (showProperty == null)
  30. showProperty = baseProperty.FindPropertyRelative("m_Enable");
  31. OnEnable();
  32. if (serie.GetType().IsDefined(typeof(CoordOptionsAttribute), false))
  33. {
  34. var attribute = serie.GetType().GetAttribute<CoordOptionsAttribute>();
  35. m_CoordOptionsDic = new Dictionary<string, Type>();
  36. m_CoordOptionsNames = new List<string>();
  37. if (attribute.type0 != null)
  38. {
  39. m_CoordOptionsDic[attribute.type0.Name] = attribute.type0;
  40. m_CoordOptionsNames.Add(attribute.type0.Name);
  41. }
  42. if (attribute.type1 != null)
  43. {
  44. m_CoordOptionsDic[attribute.type1.Name] = attribute.type1;
  45. m_CoordOptionsNames.Add(attribute.type1.Name);
  46. }
  47. if (attribute.type2 != null)
  48. {
  49. m_CoordOptionsDic[attribute.type2.Name] = attribute.type2;
  50. m_CoordOptionsNames.Add(attribute.type2.Name);
  51. }
  52. if (attribute.type3 != null)
  53. {
  54. m_CoordOptionsDic[attribute.type3.Name] = attribute.type3;
  55. m_CoordOptionsNames.Add(attribute.type3.Name);
  56. }
  57. }
  58. }
  59. public virtual void OnEnable()
  60. { }
  61. public virtual void OnDisable()
  62. { }
  63. internal void OnInternalInspectorGUI()
  64. {
  65. OnInspectorGUI();
  66. EditorGUILayout.Space();
  67. }
  68. public virtual void OnInspectorGUI()
  69. { }
  70. protected virtual void DrawExtendeds()
  71. { }
  72. public virtual string GetDisplayTitle()
  73. {
  74. // var title = string.Format("serie {0}: {1}", serie.index, serie.GetType().Name);
  75. // return ObjectNames.NicifyVariableName(title);
  76. return m_DisplayName;
  77. }
  78. internal SerializedProperty FindProperty(string path)
  79. {
  80. return baseProperty.FindPropertyRelative(path);
  81. }
  82. protected SerializedProperty PropertyField(string path)
  83. {
  84. Assert.IsNotNull(path);
  85. var property = FindProperty(path);
  86. Assert.IsNotNull(property, "Can't find:" + path);
  87. var title = ChartEditorHelper.GetContent(property.displayName);
  88. PropertyField(property, title);
  89. return property;
  90. }
  91. protected void PropertyField(SerializedProperty property)
  92. {
  93. Assert.IsNotNull(property);
  94. var title = ChartEditorHelper.GetContent(property.displayName);
  95. PropertyField(property, title);
  96. }
  97. protected void PropertyField(SerializedProperty property, GUIContent title)
  98. {
  99. EditorGUILayout.PropertyField(property, title);
  100. }
  101. protected void PropertyListField(string relativePropName, bool showOrder = true)
  102. {
  103. //TODO:
  104. PropertyField(relativePropName);
  105. }
  106. protected void PropertyTwoFiled(string relativePropName)
  107. {
  108. var m_DrawRect = GUILayoutUtility.GetRect(1f, 17f);
  109. var prop = FindProperty(relativePropName);
  110. ChartEditorHelper.MakeTwoField(ref m_DrawRect, m_DrawRect.width, prop, prop.displayName);
  111. }
  112. protected void PropertyFieldLimitMin(string relativePropName, double min)
  113. {
  114. var prop = PropertyField(relativePropName);
  115. switch (prop.propertyType)
  116. {
  117. case SerializedPropertyType.Float:
  118. if (prop.floatValue < min)
  119. prop.floatValue = (float) min;
  120. break;
  121. case SerializedPropertyType.Integer:
  122. if (prop.intValue < min)
  123. prop.intValue = (int) min;
  124. break;
  125. }
  126. }
  127. protected void PropertyFieldLimitMax(string relativePropName, int max)
  128. {
  129. var prop = PropertyField(relativePropName);
  130. switch (prop.propertyType)
  131. {
  132. case SerializedPropertyType.Float:
  133. if (prop.floatValue > max)
  134. prop.floatValue = (float) max;
  135. break;
  136. case SerializedPropertyType.Integer:
  137. if (prop.intValue > max)
  138. prop.intValue = (int) max;
  139. break;
  140. }
  141. }
  142. }
  143. }