10 using System.Collections.Generic;
 
   16 #if UNITY_2019_3_OR_NEWER 
   17         public const float INDENT_WIDTH = 15;
 
   18         public const float BOOL_WIDTH = 15;
 
   19         public const float ARROW_WIDTH = 20;
 
   20         public const float BLOCK_WIDTH = 4;
 
   21         public const float GAP_WIDTH = 2;
 
   23     public const float INDENT_WIDTH = 15;
 
   24     public const float BOOL_WIDTH = 15;
 
   25     public const float ARROW_WIDTH = 17.2f;
 
   26     public const float BLOCK_WIDTH = 0;
 
   27     public const float GAP_WIDTH = 0;
 
   32             public static readonly GUIStyle headerStyle = EditorStyles.boldLabel;
 
   33             public static readonly GUIStyle foldoutStyle = 
new GUIStyle(EditorStyles.foldout)
 
   35                 font = headerStyle.font,
 
   36                 fontStyle = headerStyle.fontStyle,
 
   38             public static readonly GUIContent iconAdd = 
new GUIContent(
"+", 
"Add");
 
   39             public static readonly GUIContent iconRemove = 
new GUIContent(
"-", 
"Remove");
 
   40             public static readonly GUIContent iconUp = 
new GUIContent(
"↑", 
"Up");
 
   41             public static readonly GUIContent iconDown = 
new GUIContent(
"↓", 
"Down");
 
   42             public static readonly GUIStyle invisibleButton = 
"InvisibleButton";
 
   45         public static void SecondField(Rect drawRect, SerializedProperty prop)
 
   47             RectOffset offset = 
new RectOffset(-(
int)EditorGUIUtility.labelWidth, 0, 0, 0);
 
   48             drawRect = offset.Add(drawRect);
 
   49             EditorGUI.PropertyField(drawRect, prop, GUIContent.none);
 
   50             drawRect = offset.Remove(drawRect);
 
   53         public static void MakeTwoField(ref Rect drawRect, 
float rectWidth, SerializedProperty arrayProp,
 
   56             while (arrayProp.arraySize < 2) arrayProp.arraySize++;
 
   57             var prop1 = arrayProp.GetArrayElementAtIndex(0);
 
   58             var prop2 = arrayProp.GetArrayElementAtIndex(1);
 
   59             MakeTwoField(ref drawRect, rectWidth, prop1, prop2, name);
 
   62         public static void MakeDivideList(ref Rect drawRect, 
float rectWidth, SerializedProperty arrayProp,
 
   63             string name, 
int showNum)
 
   65             while (arrayProp.arraySize < showNum) arrayProp.arraySize++;
 
   66             EditorGUI.LabelField(drawRect, name);
 
   67 #if UNITY_2019_3_OR_NEWER 
   72             var startX = drawRect.x + EditorGUIUtility.labelWidth - EditorGUI.indentLevel * INDENT_WIDTH + gap;
 
   73             var dataWidTotal = (rectWidth - (startX + INDENT_WIDTH + 1));
 
   74             EditorGUI.DrawRect(
new Rect(startX, drawRect.y, dataWidTotal, drawRect.height), Color.grey);
 
   75             var dataWid = dataWidTotal / showNum;
 
   76             var xWid = dataWid - gap;
 
   77             for (
int i = 0; i < 1; i++)
 
   79                 drawRect.x = startX + i * xWid;
 
   80                 drawRect.width = dataWid + (EditorGUI.indentLevel - 2) * 40.5f;
 
   81                 EditorGUI.PropertyField(drawRect, arrayProp.GetArrayElementAtIndex(i), GUIContent.none);
 
   83             drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
 
   86         public static void MakeTwoField(ref Rect drawRect, 
float rectWidth, SerializedProperty prop1,
 
   87             SerializedProperty prop2, 
string name)
 
   89             EditorGUI.LabelField(drawRect, name);
 
   90             var startX = drawRect.x + EditorGUIUtility.labelWidth - EditorGUI.indentLevel * INDENT_WIDTH + GAP_WIDTH;
 
   91             var diff = 14 + EditorGUI.indentLevel * 14;
 
   92             var offset = diff - INDENT_WIDTH;
 
   93             var tempWidth = (rectWidth - startX + diff) / 2;
 
   94             var centerXRect = 
new Rect(startX, drawRect.y, tempWidth, drawRect.height);
 
   95             var centerYRect = 
new Rect(centerXRect.x + tempWidth - offset, drawRect.y, tempWidth, drawRect.height);
 
   96             EditorGUI.PropertyField(centerXRect, prop1, GUIContent.none);
 
   97             EditorGUI.PropertyField(centerYRect, prop2, GUIContent.none);
 
   98             drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
 
  101         public static void MakeVector2(ref Rect drawRect, 
float rectWidth, SerializedProperty prop, 
string name)
 
  103             EditorGUI.LabelField(drawRect, name);
 
  104             var startX = drawRect.x + EditorGUIUtility.labelWidth - EditorGUI.indentLevel * INDENT_WIDTH + GAP_WIDTH;
 
  105             var diff = 14 + EditorGUI.indentLevel * 14;
 
  106             var offset = diff - INDENT_WIDTH;
 
  107             var tempWidth = (rectWidth - startX + diff) / 2;
 
  108             var centerXRect = 
new Rect(startX, drawRect.y, tempWidth, drawRect.height);
 
  109             var centerYRect = 
new Rect(centerXRect.x + tempWidth - offset, drawRect.y, tempWidth, drawRect.height);
 
  110             var x = EditorGUI.FloatField(centerXRect, prop.vector3Value.x);
 
  111             var y = EditorGUI.FloatField(centerYRect, prop.vector3Value.y);
 
  112             prop.vector3Value = 
new Vector3(x, y);
 
  113             drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
 
  116         public static void MakeJsonData(ref Rect drawRect, ref 
bool showTextArea, ref 
string inputString,
 
  117             SerializedProperty prop, 
float currentWidth, 
float diff = 0)
 
  119             SerializedProperty stringDataProp = prop.FindPropertyRelative(
"m_JsonData");
 
  120             SerializedProperty needParseProp = prop.FindPropertyRelative(
"m_DataFromJson");
 
  121             float defalutX = drawRect.x;
 
  122             drawRect.x = EditorGUIUtility.labelWidth + ARROW_WIDTH + diff;
 
  123             drawRect.width = currentWidth - EditorGUIUtility.labelWidth - GAP_WIDTH - diff;
 
  124             if (GUI.Button(drawRect, 
new GUIContent(
"Parse JsonData", 
"Parse data from input json")))
 
  126                 showTextArea = !showTextArea;
 
  127                 bool needParse = !showTextArea;
 
  130                     stringDataProp.stringValue = inputString;
 
  131                     needParseProp.boolValue = 
true;
 
  134             drawRect.x = defalutX;
 
  135             drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
 
  138                 drawRect.width = currentWidth;
 
  139                 drawRect.height = EditorGUIUtility.singleLineHeight * 4;
 
  140                 inputString = EditorGUI.TextArea(drawRect, inputString);
 
  141                 drawRect.y += EditorGUIUtility.singleLineHeight * 4 + EditorGUIUtility.standardVerticalSpacing;
 
  142                 drawRect.height = EditorGUIUtility.singleLineHeight;
 
  146         public static bool MakeFoldout(ref Rect drawRect, ref 
bool moduleToggle, 
string content,
 
  147             SerializedProperty prop = 
null, 
bool bold = 
false)
 
  149             float defaultWidth = drawRect.width;
 
  150             float defaultX = drawRect.x;
 
  151             var style = bold ? Styles.foldoutStyle : EditorStyles.foldout;
 
  152             drawRect.width = EditorGUIUtility.labelWidth - EditorGUI.indentLevel * INDENT_WIDTH;
 
  153             moduleToggle = EditorGUI.Foldout(drawRect, moduleToggle, content, 
true, style);
 
  154             MakeBool(drawRect, prop);
 
  155             drawRect.width = defaultWidth;
 
  156             drawRect.x = defaultX;
 
  160         public static bool MakeFoldout(ref Rect drawRect, Dictionary<string, float> heights,
 
  161             Dictionary<string, bool> moduleToggle, 
string key, 
string content, SerializedProperty prop, 
bool bold = 
false)
 
  163             float defaultWidth = drawRect.width;
 
  164             float defaultX = drawRect.x;
 
  165             var style = bold ? Styles.foldoutStyle : EditorStyles.foldout;
 
  166             drawRect.width = EditorGUIUtility.labelWidth;
 
  167             moduleToggle[key] = EditorGUI.Foldout(drawRect, moduleToggle[key], content, 
true, style);
 
  170                 if (prop.propertyType == SerializedPropertyType.Boolean)
 
  172                     MakeBool(drawRect, prop);
 
  176                     drawRect.x = EditorGUIUtility.labelWidth - EditorGUI.indentLevel * INDENT_WIDTH + ARROW_WIDTH;
 
  177                     drawRect.width = defaultWidth - drawRect.x + ARROW_WIDTH - 2;
 
  178                     if (XChartsSettings.editorBlockEnable)
 
  180                         drawRect.x += BLOCK_WIDTH;
 
  183                     EditorGUI.PropertyField(drawRect, prop, GUIContent.none);
 
  187             drawRect.width = defaultWidth;
 
  188             drawRect.x = defaultX;
 
  189             drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
 
  190             heights[key] += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
 
  191             return moduleToggle[key];
 
  194         public static void MakeBool(Rect drawRect, SerializedProperty boolProp, 
int index = 0, 
string name = 
null)
 
  196             float defaultWidth = drawRect.width;
 
  197             float defaultX = drawRect.x;
 
  198             float boolWidth = index * (BOOL_WIDTH + GAP_WIDTH);
 
  199             drawRect.x = EditorGUIUtility.labelWidth - EditorGUI.indentLevel * INDENT_WIDTH + ARROW_WIDTH + boolWidth;
 
  200             if (XChartsSettings.editorBlockEnable)
 
  202                 drawRect.x += BLOCK_WIDTH;
 
  204             drawRect.width = (EditorGUI.indentLevel + 1) * BOOL_WIDTH + index * 110;
 
  205             if (boolProp != 
null)
 
  207                 EditorGUI.PropertyField(drawRect, boolProp, GUIContent.none);
 
  208                 if (!
string.IsNullOrEmpty(name))
 
  210                     drawRect.x += BOOL_WIDTH;
 
  211                     drawRect.width = 200;
 
  212                     EditorGUI.LabelField(drawRect, name);
 
  215             drawRect.width = defaultWidth;
 
  216             drawRect.x = defaultX;
 
  219         public static bool MakeFoldout(ref Rect drawRect, ref 
float height, ref Dictionary<string, bool> moduleToggle,
 
  220             SerializedProperty prop, 
string moduleName, 
string showPropName, 
bool bold = 
false)
 
  222             var relativeProp = prop.FindPropertyRelative(showPropName);
 
  223             var flag = MakeFoldout(ref drawRect, ref moduleToggle, prop, moduleName, relativeProp, bold);
 
  224             drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
 
  225             height += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
 
  229         public static bool MakeFoldout(ref Rect drawRect, ref Dictionary<string, bool> moduleToggle, SerializedProperty prop,
 
  230             string moduleName, SerializedProperty showProp = 
null, 
bool bold = 
false)
 
  232             var key = prop.propertyPath;
 
  233             if (!moduleToggle.ContainsKey(key))
 
  235                 moduleToggle.Add(key, 
false);
 
  237             var toggle = moduleToggle[key];
 
  239             float defaultWidth = drawRect.width;
 
  240             float defaultX = drawRect.x;
 
  241 #if UNITY_2019_3_OR_NEWER 
  242             drawRect.width = EditorGUIUtility.labelWidth - EditorGUI.indentLevel * INDENT_WIDTH;
 
  244         drawRect.width = EditorGUIUtility.labelWidth;
 
  246             var displayName = 
string.IsNullOrEmpty(moduleName) ? prop.displayName : moduleName;
 
  247             var foldoutStyle = bold ? Styles.foldoutStyle : EditorStyles.foldout;
 
  248             toggle = EditorGUI.Foldout(drawRect, toggle, displayName, 
true, foldoutStyle);
 
  250             if (moduleToggle[key] != toggle)
 
  252                 moduleToggle[key] = toggle;
 
  254             if (showProp != 
null)
 
  256                 drawRect.x = EditorGUIUtility.labelWidth - EditorGUI.indentLevel * INDENT_WIDTH + ARROW_WIDTH;
 
  257                 if (showProp.propertyType == SerializedPropertyType.Boolean)
 
  259                     drawRect.width = (EditorGUI.indentLevel + 1) * BOOL_WIDTH;
 
  263                     drawRect.width = defaultWidth - drawRect.x + ARROW_WIDTH - GAP_WIDTH;
 
  265                 if (XChartsSettings.editorBlockEnable)
 
  267                     drawRect.x += BLOCK_WIDTH;
 
  269                 EditorGUI.PropertyField(drawRect, showProp, GUIContent.none);
 
  271             drawRect.width = defaultWidth;
 
  272             drawRect.x = defaultX;
 
  276         public static bool MakeListWithFoldout(ref Rect drawRect, SerializedProperty listProp, 
bool foldout,
 
  277             bool showOrder = 
false, 
bool showSize = 
true)
 
  280             return MakeListWithFoldout(ref drawRect, ref height, listProp, foldout, showOrder, showSize);
 
  283         public static bool MakeListWithFoldout(ref Rect drawRect, ref 
float height, SerializedProperty listProp,
 
  284             bool foldout, 
bool showOrder = 
false, 
bool showSize = 
true)
 
  286             var rawWidth = drawRect.width;
 
  287             drawRect.width = EditorGUIUtility.labelWidth + 10;
 
  288             bool flag = EditorGUI.Foldout(drawRect, foldout, listProp.displayName, 
true);
 
  289             height += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
 
  290             drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
 
  291             drawRect.width = rawWidth;
 
  294                 MakeList(ref drawRect, ref height, listProp, showOrder, showSize);
 
  299         public static void MakeList(ref Rect drawRect, SerializedProperty listProp, 
bool showOrder = 
false,
 
  300             bool showSize = 
true)
 
  303             MakeList(ref drawRect, ref height, listProp, showOrder, showSize);
 
  306         public static void MakeList(ref Rect drawRect, ref 
float height, SerializedProperty listProp,
 
  307             bool showOrder = 
false, 
bool showSize = 
true)
 
  309             EditorGUI.indentLevel++;
 
  310             var listSize = listProp.arraySize;
 
  317                     var temp = INDENT_WIDTH + GAP_WIDTH + iconGap;
 
  318                     var elementRect = 
new Rect(drawRect.x, drawRect.y, drawRect.width - iconWidth + 2, drawRect.height);
 
  319                     var iconRect = 
new Rect(drawRect.width - iconWidth + temp, drawRect.y, iconWidth, drawRect.height);
 
  320                     if (XChartsSettings.editorBlockEnable)
 
  322                         iconRect.x += BLOCK_WIDTH;
 
  324                     var oldColor = GUI.contentColor;
 
  325                     GUI.contentColor = Color.black;
 
  326                     if (GUI.Button(iconRect, Styles.iconAdd, Styles.invisibleButton))
 
  328                         if (listProp.displayName.Equals(
"Series"))
 
  330                             AddSerieEditor.chart = listProp.serializedObject.targetObject as BaseChart;
 
  331                             AddSerieEditor.ShowWindow();
 
  335                             listProp.arraySize++;
 
  338                     GUI.contentColor = oldColor;
 
  339                     listSize = listProp.arraySize;
 
  340                     listSize = EditorGUI.IntField(elementRect, 
"Size", listSize);
 
  344                     listSize = EditorGUI.IntField(drawRect, 
"Size", listSize);
 
  346                 if (listSize < 0) listSize = 0;
 
  347                 drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
 
  348                 height += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
 
  350                 if (listSize != listProp.arraySize)
 
  352                     while (listSize > listProp.arraySize) listProp.arraySize++;
 
  353                     while (listSize < listProp.arraySize) listProp.arraySize--;
 
  356             if (listSize > 30 && !XChartsSettings.editorShowAllListData)
 
  358                 SerializedProperty element;
 
  359                 int num = listSize > 10 ? 10 : listSize;
 
  360                 for (
int i = 0; i < num; i++)
 
  362                     element = listProp.GetArrayElementAtIndex(i);
 
  363                     EditorGUI.PropertyField(drawRect, element, 
new GUIContent(
"Element " + i));
 
  364                     drawRect.y += EditorGUI.GetPropertyHeight(element) + EditorGUIUtility.standardVerticalSpacing;
 
  365                     height += EditorGUI.GetPropertyHeight(element) + EditorGUIUtility.standardVerticalSpacing;
 
  369                     EditorGUI.LabelField(drawRect, 
"...");
 
  370                     drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
 
  371                     height += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
 
  372                     element = listProp.GetArrayElementAtIndex(listSize - 1);
 
  373                     EditorGUI.PropertyField(drawRect, element, 
new GUIContent(
"Element " + (listSize - 1)));
 
  374                     drawRect.y += EditorGUI.GetPropertyHeight(element) + EditorGUIUtility.standardVerticalSpacing;
 
  375                     height += EditorGUI.GetPropertyHeight(element) + EditorGUIUtility.standardVerticalSpacing;
 
  380                 for (
int i = 0; i < listProp.arraySize; i++)
 
  382                     SerializedProperty element = listProp.GetArrayElementAtIndex(i);
 
  385                         var temp = INDENT_WIDTH + GAP_WIDTH + iconGap;
 
  386                         var isSerie = 
"Serie".Equals(element.type);
 
  387                         var elementRect = isSerie
 
  388                             ? 
new Rect(drawRect.x, drawRect.y, drawRect.width + INDENT_WIDTH - 2 * iconGap, drawRect.height)
 
  389                             : new 
Rect(drawRect.x, drawRect.y, drawRect.width - 3 * iconWidth, drawRect.height);
 
  390                         EditorGUI.PropertyField(elementRect, element, 
new GUIContent(
"Element " + i));
 
  391                         var iconRect = 
new Rect(drawRect.width - 3 * iconWidth + temp, drawRect.y, iconWidth, drawRect.height);
 
  392                         if (XChartsSettings.editorBlockEnable)
 
  394                             iconRect.x += BLOCK_WIDTH;
 
  396                         var oldColor = GUI.contentColor;
 
  397                         GUI.contentColor = Color.black;
 
  398                         if (GUI.Button(iconRect, Styles.iconUp, Styles.invisibleButton))
 
  400                             if (i > 0) listProp.MoveArrayElement(i, i - 1);
 
  402                         iconRect = 
new Rect(drawRect.width - 2 * iconWidth + temp, drawRect.y, iconWidth, drawRect.height);
 
  403                         if (XChartsSettings.editorBlockEnable)
 
  405                             iconRect.x += BLOCK_WIDTH;
 
  407                         if (GUI.Button(iconRect, Styles.iconDown, Styles.invisibleButton))
 
  409                             if (i < listProp.arraySize - 1) listProp.MoveArrayElement(i, i + 1);
 
  411                         iconRect = 
new Rect(drawRect.width - iconWidth + temp, drawRect.y, iconWidth, drawRect.height);
 
  412                         if (XChartsSettings.editorBlockEnable)
 
  414                             iconRect.x += BLOCK_WIDTH;
 
  416                         if (GUI.Button(iconRect, Styles.iconRemove, Styles.invisibleButton))
 
  418                             if (i < listProp.arraySize && i >= 0) listProp.DeleteArrayElementAtIndex(i);
 
  422                             drawRect.y += EditorGUI.GetPropertyHeight(element) + EditorGUIUtility.standardVerticalSpacing;
 
  423                             height += EditorGUI.GetPropertyHeight(element) + EditorGUIUtility.standardVerticalSpacing;
 
  425                         GUI.contentColor = oldColor;
 
  429                         EditorGUI.PropertyField(drawRect, element, 
new GUIContent(
"Element " + i));
 
  430                         drawRect.y += EditorGUI.GetPropertyHeight(element) + EditorGUIUtility.standardVerticalSpacing;
 
  431                         height += EditorGUI.GetPropertyHeight(element) + EditorGUIUtility.standardVerticalSpacing;
 
  435             EditorGUI.indentLevel--;
 
  438         public static bool PropertyField(ref Rect drawRect, Dictionary<string, float> heights, 
string key,
 
  439             SerializedProperty prop)
 
  441             if (prop == 
null) 
return false;
 
  442             EditorGUI.PropertyField(drawRect, prop, 
true);
 
  443             var hig = EditorGUI.GetPropertyHeight(prop);
 
  449         public static bool PropertyFieldWithMinValue(ref Rect drawRect, Dictionary<string, float> heights, 
string key,
 
  450             SerializedProperty prop, 
float minValue)
 
  452             if (prop == 
null) 
return false;
 
  453             EditorGUI.PropertyField(drawRect, prop, 
true);
 
  454             if (prop.propertyType == SerializedPropertyType.Float && prop.floatValue < minValue)
 
  455                 prop.floatValue = minValue;
 
  456             if (prop.propertyType == SerializedPropertyType.Integer && prop.intValue < minValue)
 
  457                 prop.intValue = (int)minValue;
 
  458             var hig = EditorGUI.GetPropertyHeight(prop);
 
  464         public static bool PropertyFieldWithMaxValue(ref Rect drawRect, Dictionary<string, float> heights, 
string key,
 
  465             SerializedProperty prop, 
float maxValue)
 
  467             if (prop == 
null) 
return false;
 
  468             EditorGUI.PropertyField(drawRect, prop, 
true);
 
  469             if (prop.propertyType == SerializedPropertyType.Float && prop.floatValue > maxValue)
 
  470                 prop.floatValue = maxValue;
 
  471             if (prop.propertyType == SerializedPropertyType.Integer && prop.intValue > maxValue)
 
  472                 prop.intValue = (int)maxValue;
 
  473             var hig = EditorGUI.GetPropertyHeight(prop);
 
  479         public static bool PropertyField(ref Rect drawRect, Dictionary<string, float> heights, 
string key,
 
  480             SerializedProperty parentProp, 
string relativeName)
 
  482             return PropertyField(ref drawRect, heights, key, parentProp.FindPropertyRelative(relativeName));
 
  484         public static bool PropertyFieldWithMinValue(ref Rect drawRect, Dictionary<string, float> heights, 
string key,
 
  485             SerializedProperty parentProp, 
string relativeName, 
float minValue)
 
  487             var relativeProp = parentProp.FindPropertyRelative(relativeName);
 
  488             return PropertyFieldWithMinValue(ref drawRect, heights, key, relativeProp, minValue);
 
  490         public static bool PropertyFieldWithMaxValue(ref Rect drawRect, Dictionary<string, float> heights, 
string key,
 
  491             SerializedProperty parentProp, 
string relativeName, 
float maxValue)
 
  493             var relativeProp = parentProp.FindPropertyRelative(relativeName);
 
  494             return PropertyFieldWithMaxValue(ref drawRect, heights, key, relativeProp, maxValue);