2019-10-22 04:09:04 +08:00
|
|
|
|
/******************************************/
|
|
|
|
|
|
/* */
|
|
|
|
|
|
/* Copyright (c) 2018 monitor1394 */
|
|
|
|
|
|
/* https://github.com/monitor1394 */
|
|
|
|
|
|
/* */
|
|
|
|
|
|
/******************************************/
|
|
|
|
|
|
|
|
|
|
|
|
using System.Collections.Generic;
|
2019-07-14 14:34:18 +08:00
|
|
|
|
using UnityEditor;
|
2019-05-11 04:33:54 +08:00
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
|
|
namespace XCharts
|
|
|
|
|
|
{
|
|
|
|
|
|
[CustomPropertyDrawer(typeof(Axis), true)]
|
|
|
|
|
|
public class AxisDrawer : PropertyDrawer
|
|
|
|
|
|
{
|
2019-07-14 14:34:18 +08:00
|
|
|
|
private List<bool> m_AxisModuleToggle = new List<bool>();
|
|
|
|
|
|
private List<bool> m_DataFoldout = new List<bool>();
|
2019-05-11 04:33:54 +08:00
|
|
|
|
private int m_DataSize = 0;
|
|
|
|
|
|
private bool m_ShowJsonDataArea = false;
|
|
|
|
|
|
private string m_JsonDataAreaText;
|
2019-07-14 14:34:18 +08:00
|
|
|
|
|
2019-05-11 04:33:54 +08:00
|
|
|
|
|
2019-07-13 16:38:38 +08:00
|
|
|
|
protected virtual string GetDisplayName(string displayName)
|
2019-05-11 04:33:54 +08:00
|
|
|
|
{
|
2019-07-13 16:38:38 +08:00
|
|
|
|
return displayName;
|
2019-05-11 04:33:54 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label)
|
|
|
|
|
|
{
|
|
|
|
|
|
Rect drawRect = pos;
|
|
|
|
|
|
drawRect.height = EditorGUIUtility.singleLineHeight;
|
|
|
|
|
|
|
|
|
|
|
|
SerializedProperty m_Show = prop.FindPropertyRelative("m_Show");
|
|
|
|
|
|
SerializedProperty m_Type = prop.FindPropertyRelative("m_Type");
|
2020-01-15 19:41:21 +08:00
|
|
|
|
SerializedProperty m_LogBaseE = prop.FindPropertyRelative("m_LogBaseE");
|
|
|
|
|
|
SerializedProperty m_LogBase = prop.FindPropertyRelative("m_LogBase");
|
2019-05-11 04:33:54 +08:00
|
|
|
|
SerializedProperty m_SplitNumber = prop.FindPropertyRelative("m_SplitNumber");
|
2019-09-17 18:30:45 +08:00
|
|
|
|
SerializedProperty m_Interval = prop.FindPropertyRelative("m_Interval");
|
2019-07-03 18:45:48 +08:00
|
|
|
|
SerializedProperty m_AxisLabel = prop.FindPropertyRelative("m_AxisLabel");
|
2019-05-11 04:33:54 +08:00
|
|
|
|
SerializedProperty m_BoundaryGap = prop.FindPropertyRelative("m_BoundaryGap");
|
|
|
|
|
|
SerializedProperty m_Data = prop.FindPropertyRelative("m_Data");
|
2019-07-09 22:20:50 +08:00
|
|
|
|
SerializedProperty m_AxisLine = prop.FindPropertyRelative("m_AxisLine");
|
2019-06-29 07:22:57 +08:00
|
|
|
|
SerializedProperty m_AxisName = prop.FindPropertyRelative("m_AxisName");
|
2019-05-11 04:33:54 +08:00
|
|
|
|
SerializedProperty m_AxisTick = prop.FindPropertyRelative("m_AxisTick");
|
2019-06-30 18:34:09 +08:00
|
|
|
|
SerializedProperty m_SplitArea = prop.FindPropertyRelative("m_SplitArea");
|
2020-02-11 20:37:34 +08:00
|
|
|
|
SerializedProperty m_SplitLine = prop.FindPropertyRelative("m_SplitLine");
|
2019-05-16 09:39:58 +08:00
|
|
|
|
SerializedProperty m_MinMaxType = prop.FindPropertyRelative("m_MinMaxType");
|
|
|
|
|
|
SerializedProperty m_Min = prop.FindPropertyRelative("m_Min");
|
|
|
|
|
|
SerializedProperty m_Max = prop.FindPropertyRelative("m_Max");
|
2020-03-29 15:46:01 +08:00
|
|
|
|
SerializedProperty m_CeilRate = prop.FindPropertyRelative("m_CeilRate");
|
2020-04-18 08:19:17 +08:00
|
|
|
|
SerializedProperty m_Inverse = prop.FindPropertyRelative("m_Inverse");
|
2019-05-11 04:33:54 +08:00
|
|
|
|
|
2019-07-14 14:34:18 +08:00
|
|
|
|
int index = InitToggle(prop);
|
|
|
|
|
|
bool toggle = m_AxisModuleToggle[index];
|
|
|
|
|
|
m_AxisModuleToggle[index] = ChartEditorHelper.MakeFoldout(ref drawRect, ref toggle,
|
|
|
|
|
|
GetDisplayName(prop.displayName), m_Show);
|
2019-05-11 04:33:54 +08:00
|
|
|
|
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
2019-07-14 14:34:18 +08:00
|
|
|
|
if (m_AxisModuleToggle[index])
|
2019-05-11 04:33:54 +08:00
|
|
|
|
{
|
2019-05-16 09:39:58 +08:00
|
|
|
|
Axis.AxisType type = (Axis.AxisType)m_Type.enumValueIndex;
|
2019-05-11 04:33:54 +08:00
|
|
|
|
EditorGUI.indentLevel++;
|
|
|
|
|
|
EditorGUI.PropertyField(drawRect, m_Type);
|
|
|
|
|
|
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
2020-01-15 19:41:21 +08:00
|
|
|
|
if (type == Axis.AxisType.Log)
|
|
|
|
|
|
{
|
|
|
|
|
|
EditorGUI.PropertyField(drawRect, m_LogBaseE);
|
|
|
|
|
|
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
|
|
|
|
|
EditorGUI.PropertyField(drawRect, m_LogBase);
|
|
|
|
|
|
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
|
|
|
|
|
}
|
2019-05-16 09:39:58 +08:00
|
|
|
|
if (type == Axis.AxisType.Value)
|
|
|
|
|
|
{
|
|
|
|
|
|
EditorGUI.PropertyField(drawRect, m_MinMaxType);
|
|
|
|
|
|
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
|
|
|
|
|
Axis.AxisMinMaxType minMaxType = (Axis.AxisMinMaxType)m_MinMaxType.enumValueIndex;
|
|
|
|
|
|
switch (minMaxType)
|
|
|
|
|
|
{
|
|
|
|
|
|
case Axis.AxisMinMaxType.Default:
|
|
|
|
|
|
break;
|
|
|
|
|
|
case Axis.AxisMinMaxType.MinMax:
|
|
|
|
|
|
break;
|
|
|
|
|
|
case Axis.AxisMinMaxType.Custom:
|
|
|
|
|
|
EditorGUI.indentLevel++;
|
|
|
|
|
|
EditorGUI.PropertyField(drawRect, m_Min);
|
|
|
|
|
|
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
|
|
|
|
|
EditorGUI.PropertyField(drawRect, m_Max);
|
|
|
|
|
|
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
|
|
|
|
|
EditorGUI.indentLevel--;
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
2020-03-29 15:46:01 +08:00
|
|
|
|
EditorGUI.PropertyField(drawRect, m_CeilRate);
|
|
|
|
|
|
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
2020-04-18 08:19:17 +08:00
|
|
|
|
EditorGUI.PropertyField(drawRect, m_Inverse);
|
|
|
|
|
|
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
2019-05-16 09:39:58 +08:00
|
|
|
|
}
|
2019-05-11 04:33:54 +08:00
|
|
|
|
EditorGUI.PropertyField(drawRect, m_SplitNumber);
|
|
|
|
|
|
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
2019-09-17 18:30:45 +08:00
|
|
|
|
EditorGUI.PropertyField(drawRect, m_Interval);
|
|
|
|
|
|
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
2019-05-11 04:33:54 +08:00
|
|
|
|
EditorGUI.PropertyField(drawRect, m_BoundaryGap);
|
|
|
|
|
|
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
2019-07-09 22:20:50 +08:00
|
|
|
|
EditorGUI.PropertyField(drawRect, m_AxisLine);
|
|
|
|
|
|
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
|
|
|
|
|
drawRect.y += EditorGUI.GetPropertyHeight(m_AxisLine);
|
2019-06-29 07:22:57 +08:00
|
|
|
|
EditorGUI.PropertyField(drawRect, m_AxisName);
|
|
|
|
|
|
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
|
|
|
|
|
drawRect.y += EditorGUI.GetPropertyHeight(m_AxisName);
|
2019-05-11 04:33:54 +08:00
|
|
|
|
EditorGUI.PropertyField(drawRect, m_AxisTick);
|
|
|
|
|
|
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
|
|
|
|
|
drawRect.y += EditorGUI.GetPropertyHeight(m_AxisTick);
|
2019-07-03 18:45:48 +08:00
|
|
|
|
EditorGUI.PropertyField(drawRect, m_AxisLabel);
|
|
|
|
|
|
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
|
|
|
|
|
drawRect.y += EditorGUI.GetPropertyHeight(m_AxisLabel);
|
2020-02-11 20:37:34 +08:00
|
|
|
|
EditorGUI.PropertyField(drawRect, m_SplitLine);
|
|
|
|
|
|
drawRect.y += EditorGUI.GetPropertyHeight(m_SplitLine);
|
2019-06-30 18:34:09 +08:00
|
|
|
|
EditorGUI.PropertyField(drawRect, m_SplitArea);
|
|
|
|
|
|
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
|
|
|
|
|
drawRect.y += EditorGUI.GetPropertyHeight(m_SplitArea);
|
2019-06-21 09:34:33 +08:00
|
|
|
|
|
2019-05-11 04:33:54 +08:00
|
|
|
|
if (type == Axis.AxisType.Category)
|
|
|
|
|
|
{
|
|
|
|
|
|
drawRect.width = EditorGUIUtility.labelWidth + 10;
|
2019-07-14 14:34:18 +08:00
|
|
|
|
m_DataFoldout[index] = EditorGUI.Foldout(drawRect, m_DataFoldout[index], "Data");
|
2019-07-24 23:38:23 +08:00
|
|
|
|
ChartEditorHelper.MakeJsonData(ref drawRect, ref m_ShowJsonDataArea, ref m_JsonDataAreaText, prop, pos.width);
|
2019-05-11 04:33:54 +08:00
|
|
|
|
drawRect.width = pos.width;
|
2019-07-14 14:34:18 +08:00
|
|
|
|
if (m_DataFoldout[index])
|
2019-05-11 04:33:54 +08:00
|
|
|
|
{
|
|
|
|
|
|
ChartEditorHelper.MakeList(ref drawRect, ref m_DataSize, m_Data);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
EditorGUI.indentLevel--;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override float GetPropertyHeight(SerializedProperty prop, GUIContent label)
|
|
|
|
|
|
{
|
2019-07-14 14:34:18 +08:00
|
|
|
|
int index = InitToggle(prop);
|
|
|
|
|
|
if (!m_AxisModuleToggle[index])
|
2019-05-11 04:33:54 +08:00
|
|
|
|
{
|
|
|
|
|
|
return EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
SerializedProperty m_Type = prop.FindPropertyRelative("m_Type");
|
|
|
|
|
|
SerializedProperty m_AxisTick = prop.FindPropertyRelative("m_AxisTick");
|
2019-07-09 22:20:50 +08:00
|
|
|
|
SerializedProperty m_AxisLine = prop.FindPropertyRelative("m_AxisLine");
|
2019-06-29 07:22:57 +08:00
|
|
|
|
SerializedProperty m_AxisName = prop.FindPropertyRelative("m_AxisName");
|
2019-07-03 18:45:48 +08:00
|
|
|
|
SerializedProperty m_AxisLabel = prop.FindPropertyRelative("m_AxisLabel");
|
2019-06-30 18:34:09 +08:00
|
|
|
|
SerializedProperty m_SplitArea = prop.FindPropertyRelative("m_SplitArea");
|
2020-02-11 20:37:34 +08:00
|
|
|
|
SerializedProperty m_SplitLine = prop.FindPropertyRelative("m_SplitLine");
|
2019-05-11 04:33:54 +08:00
|
|
|
|
float height = 0;
|
2020-02-11 20:37:34 +08:00
|
|
|
|
height += 10 * EditorGUIUtility.singleLineHeight + 9 * EditorGUIUtility.standardVerticalSpacing;
|
2019-05-11 04:33:54 +08:00
|
|
|
|
Axis.AxisType type = (Axis.AxisType)m_Type.enumValueIndex;
|
|
|
|
|
|
if (type == Axis.AxisType.Category)
|
|
|
|
|
|
{
|
2019-07-14 14:34:18 +08:00
|
|
|
|
if (m_DataFoldout[index])
|
2019-05-11 04:33:54 +08:00
|
|
|
|
{
|
|
|
|
|
|
SerializedProperty m_Data = prop.FindPropertyRelative("m_Data");
|
|
|
|
|
|
int num = m_Data.arraySize + 2;
|
2019-10-09 02:37:05 +08:00
|
|
|
|
if (num > 30) num = 14;
|
2019-05-11 04:33:54 +08:00
|
|
|
|
height += num * EditorGUIUtility.singleLineHeight + (num - 1) * EditorGUIUtility.standardVerticalSpacing;
|
|
|
|
|
|
height += EditorGUIUtility.standardVerticalSpacing;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
height += 1 * EditorGUIUtility.singleLineHeight + 1 * EditorGUIUtility.standardVerticalSpacing;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (m_ShowJsonDataArea)
|
|
|
|
|
|
{
|
|
|
|
|
|
height += EditorGUIUtility.singleLineHeight * 3 + EditorGUIUtility.standardVerticalSpacing;
|
|
|
|
|
|
}
|
2019-06-21 09:34:33 +08:00
|
|
|
|
}
|
|
|
|
|
|
else if (type == Axis.AxisType.Value)
|
2019-05-16 09:39:58 +08:00
|
|
|
|
{
|
2020-04-18 08:19:17 +08:00
|
|
|
|
height += 3 * EditorGUIUtility.singleLineHeight + 2 * EditorGUIUtility.standardVerticalSpacing;
|
2019-05-16 09:39:58 +08:00
|
|
|
|
SerializedProperty m_MinMaxType = prop.FindPropertyRelative("m_MinMaxType");
|
2019-06-21 09:34:33 +08:00
|
|
|
|
if (m_MinMaxType.enumValueIndex == (int)Axis.AxisMinMaxType.Custom)
|
2019-05-16 09:39:58 +08:00
|
|
|
|
{
|
|
|
|
|
|
height += EditorGUIUtility.singleLineHeight * 2 + EditorGUIUtility.standardVerticalSpacing;
|
|
|
|
|
|
}
|
2019-05-11 04:33:54 +08:00
|
|
|
|
}
|
2020-01-15 19:41:21 +08:00
|
|
|
|
else if (type == Axis.AxisType.Log)
|
|
|
|
|
|
{
|
|
|
|
|
|
height += 2 * EditorGUIUtility.singleLineHeight + 1 * EditorGUIUtility.standardVerticalSpacing;
|
|
|
|
|
|
SerializedProperty m_MinMaxType = prop.FindPropertyRelative("m_MinMaxType");
|
|
|
|
|
|
if (m_MinMaxType.enumValueIndex == (int)Axis.AxisMinMaxType.Custom)
|
|
|
|
|
|
{
|
|
|
|
|
|
height += EditorGUIUtility.singleLineHeight * 2 + EditorGUIUtility.standardVerticalSpacing;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2019-06-29 07:22:57 +08:00
|
|
|
|
height += EditorGUI.GetPropertyHeight(m_AxisName);
|
2019-07-09 22:20:50 +08:00
|
|
|
|
height += EditorGUI.GetPropertyHeight(m_AxisLine);
|
2019-05-11 04:33:54 +08:00
|
|
|
|
height += EditorGUI.GetPropertyHeight(m_AxisTick);
|
2019-07-03 18:45:48 +08:00
|
|
|
|
height += EditorGUI.GetPropertyHeight(m_AxisLabel);
|
2019-06-30 18:34:09 +08:00
|
|
|
|
height += EditorGUI.GetPropertyHeight(m_SplitArea);
|
2020-02-11 20:37:34 +08:00
|
|
|
|
height += EditorGUI.GetPropertyHeight(m_SplitLine);
|
2019-05-11 04:33:54 +08:00
|
|
|
|
return height;
|
|
|
|
|
|
}
|
2019-07-14 14:34:18 +08:00
|
|
|
|
}
|
2019-06-21 09:34:33 +08:00
|
|
|
|
|
2019-07-14 14:34:18 +08:00
|
|
|
|
private int InitToggle(SerializedProperty prop)
|
|
|
|
|
|
{
|
|
|
|
|
|
int index = 0;
|
2020-01-15 19:41:21 +08:00
|
|
|
|
int.TryParse(prop.displayName.Split(' ')[1], out index);
|
2019-07-14 14:34:18 +08:00
|
|
|
|
if (index >= m_DataFoldout.Count)
|
|
|
|
|
|
{
|
|
|
|
|
|
m_DataFoldout.Add(false);
|
|
|
|
|
|
}
|
|
|
|
|
|
if (index >= m_AxisModuleToggle.Count)
|
|
|
|
|
|
{
|
|
|
|
|
|
m_AxisModuleToggle.Add(false);
|
|
|
|
|
|
}
|
|
|
|
|
|
return index;
|
2019-05-11 04:33:54 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|