AxisEditor.cs 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. using UnityEditor;
  2. using UnityEngine;
  3. using XCharts.Runtime;
  4. namespace XCharts.Editor
  5. {
  6. [ComponentEditor(typeof(Axis))]
  7. public class AxisEditor : MainComponentEditor<Axis>
  8. {
  9. public override void OnInspectorGUI()
  10. {
  11. var m_Type = baseProperty.FindPropertyRelative("m_Type");
  12. var m_LogBase = baseProperty.FindPropertyRelative("m_LogBase");
  13. var m_MinMaxType = baseProperty.FindPropertyRelative("m_MinMaxType");
  14. var type = (Axis.AxisType) m_Type.enumValueIndex;
  15. EditorGUI.indentLevel++;
  16. if (component is ParallelAxis)
  17. {
  18. PropertyField("m_ParallelIndex");
  19. }
  20. else if (!(component is SingleAxis))
  21. {
  22. PropertyField("m_GridIndex");
  23. PropertyField("m_PolarIndex");
  24. }
  25. PropertyField("m_Type");
  26. PropertyField("m_Position");
  27. PropertyField("m_Offset");
  28. if (type == Axis.AxisType.Log)
  29. {
  30. PropertyField("m_LogBaseE");
  31. EditorGUI.BeginChangeCheck();
  32. PropertyField("m_LogBase");
  33. if (m_LogBase.floatValue <= 0 || m_LogBase.floatValue == 1)
  34. {
  35. m_LogBase.floatValue = 10;
  36. }
  37. EditorGUI.EndChangeCheck();
  38. }
  39. if (type == Axis.AxisType.Value || type == Axis.AxisType.Time)
  40. {
  41. PropertyField("m_MinMaxType");
  42. Axis.AxisMinMaxType minMaxType = (Axis.AxisMinMaxType) m_MinMaxType.enumValueIndex;
  43. switch (minMaxType)
  44. {
  45. case Axis.AxisMinMaxType.Default:
  46. break;
  47. case Axis.AxisMinMaxType.MinMax:
  48. break;
  49. case Axis.AxisMinMaxType.Custom:
  50. EditorGUI.indentLevel++;
  51. PropertyField("m_Min");
  52. PropertyField("m_Max");
  53. EditorGUI.indentLevel--;
  54. break;
  55. }
  56. PropertyField("m_CeilRate");
  57. if (type == Axis.AxisType.Value)
  58. {
  59. PropertyField("m_Inverse");
  60. }
  61. }
  62. PropertyField("m_SplitNumber");
  63. if (type == Axis.AxisType.Category)
  64. {
  65. //PropertyField("m_InsertDataToHead");
  66. PropertyField("m_MaxCache");
  67. PropertyField("m_BoundaryGap");
  68. }
  69. else
  70. {
  71. PropertyField("m_Interval");
  72. }
  73. DrawExtendeds();
  74. PropertyField("m_AxisLine");
  75. PropertyField("m_AxisName");
  76. PropertyField("m_AxisTick");
  77. PropertyField("m_AxisLabel");
  78. PropertyField("m_SplitLine");
  79. PropertyField("m_SplitArea");
  80. PropertyField("m_IndicatorLabel");
  81. if (type != Axis.AxisType.Category)
  82. {
  83. PropertyField("m_MinorTick");
  84. PropertyField("m_MinorSplitLine");
  85. }
  86. PropertyListField("m_Icons", true);
  87. if (type == Axis.AxisType.Category)
  88. {
  89. PropertyListField("m_Data", true, new HeaderMenuInfo("Import ECharts Axis Data", () =>
  90. {
  91. PraseExternalDataEditor.UpdateData(chart, null, component as Axis);
  92. PraseExternalDataEditor.ShowWindow();
  93. }));
  94. }
  95. EditorGUI.indentLevel--;
  96. }
  97. }
  98. [ComponentEditor(typeof(XAxis))]
  99. public class XAxisEditor : AxisEditor { }
  100. [ComponentEditor(typeof(YAxis))]
  101. public class YAxisEditor : AxisEditor { }
  102. [ComponentEditor(typeof(SingleAxis))]
  103. public class SingleAxisEditor : AxisEditor
  104. {
  105. protected override void DrawExtendeds()
  106. {
  107. base.DrawExtendeds();
  108. PropertyField("m_Orient");
  109. PropertyField("m_Left");
  110. PropertyField("m_Right");
  111. PropertyField("m_Top");
  112. PropertyField("m_Bottom");
  113. PropertyField("m_Width");
  114. PropertyField("m_Height");
  115. }
  116. }
  117. [ComponentEditor(typeof(AngleAxis))]
  118. public class AngleAxisEditor : AxisEditor
  119. {
  120. protected override void DrawExtendeds()
  121. {
  122. base.DrawExtendeds();
  123. PropertyField("m_StartAngle");
  124. PropertyField("m_Clockwise");
  125. }
  126. }
  127. [ComponentEditor(typeof(RadiusAxis))]
  128. public class RadiusAxisEditor : AxisEditor { }
  129. [ComponentEditor(typeof(ParallelAxis))]
  130. public class ParallelAxisEditor : AxisEditor { }
  131. [CustomPropertyDrawer(typeof(AxisLabel), true)]
  132. public class AxisLabelDrawer : BasePropertyDrawer
  133. {
  134. public override string ClassName { get { return "AxisLabel"; } }
  135. public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label)
  136. {
  137. base.OnGUI(pos, prop, label);
  138. if (MakeComponentFoldout(prop, "m_Show", true))
  139. {
  140. ++EditorGUI.indentLevel;
  141. PropertyField(prop, "m_Inside");
  142. PropertyField(prop, "m_Interval");
  143. PropertyField(prop, "m_ShowAsPositiveNumber");
  144. PropertyField(prop, "m_OnZero");
  145. PropertyField(prop, "m_ShowStartLabel");
  146. PropertyField(prop, "m_ShowEndLabel");
  147. PropertyField(prop, "m_Rotate");
  148. PropertyField(prop, "m_Offset");
  149. PropertyField(prop, "m_Distance");
  150. PropertyField(prop, "m_Formatter");
  151. PropertyField(prop, "m_NumericFormatter");
  152. PropertyField(prop, "m_Width");
  153. PropertyField(prop, "m_Height");
  154. PropertyField(prop, "m_Icon");
  155. PropertyField(prop, "m_Background");
  156. PropertyField(prop, "m_TextStyle");
  157. PropertyField(prop, "m_TextPadding");
  158. PropertyField(prop, "m_TextLimit");
  159. --EditorGUI.indentLevel;
  160. }
  161. }
  162. }
  163. [CustomPropertyDrawer(typeof(AxisName), true)]
  164. public class AxisNameDrawer : BasePropertyDrawer
  165. {
  166. public override string ClassName { get { return "AxisName"; } }
  167. public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label)
  168. {
  169. base.OnGUI(pos, prop, label);
  170. if (MakeComponentFoldout(prop, "m_Show", true))
  171. {
  172. ++EditorGUI.indentLevel;
  173. PropertyField(prop, "m_Name");
  174. PropertyField(prop, "m_OnZero");
  175. PropertyField(prop, "m_LabelStyle");
  176. --EditorGUI.indentLevel;
  177. }
  178. }
  179. }
  180. [CustomPropertyDrawer(typeof(AxisSplitArea), true)]
  181. public class AxisSplitAreaDrawer : BasePropertyDrawer
  182. {
  183. public override string ClassName { get { return "SplitArea"; } }
  184. public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label)
  185. {
  186. base.OnGUI(pos, prop, label);
  187. if (MakeComponentFoldout(prop, "m_Show", true))
  188. {
  189. ++EditorGUI.indentLevel;
  190. PropertyField(prop, "m_Color");
  191. --EditorGUI.indentLevel;
  192. }
  193. }
  194. }
  195. }