Files
XCharts/Scripts/Editor/PropertyDrawers/LineArrowDrawer.cs
2019-09-19 19:26:05 +08:00

55 lines
2.7 KiB
C#

using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
namespace XCharts
{
[CustomPropertyDrawer(typeof(LineArrow), true)]
public class LineArrowStyleDrawer : PropertyDrawer
{
private Dictionary<string, bool> m_LineArrowToggle = new Dictionary<string, bool>();
public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label)
{
Rect drawRect = pos;
drawRect.height = EditorGUIUtility.singleLineHeight;
SerializedProperty show = prop.FindPropertyRelative("m_Show");
SerializedProperty m_Position = prop.FindPropertyRelative("m_Position");
SerializedProperty m_Width = prop.FindPropertyRelative("m_Width");
SerializedProperty m_Height = prop.FindPropertyRelative("m_Height");
SerializedProperty m_Offset = prop.FindPropertyRelative("m_Offset");
SerializedProperty m_Dent = prop.FindPropertyRelative("m_Dent");
ChartEditorHelper.MakeFoldout(ref drawRect, ref m_LineArrowToggle, prop, "Line Arrow", show, false);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
if (ChartEditorHelper.IsToggle(m_LineArrowToggle, prop))
{
++EditorGUI.indentLevel;
EditorGUI.PropertyField(drawRect, m_Position);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_Width);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_Height);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_Offset);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_Dent);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
--EditorGUI.indentLevel;
}
}
public override float GetPropertyHeight(SerializedProperty prop, GUIContent label)
{
float height = 0;
if (ChartEditorHelper.IsToggle(m_LineArrowToggle, prop))
{
height += 6 * EditorGUIUtility.singleLineHeight + 5 * EditorGUIUtility.standardVerticalSpacing;
}
else
{
height += 1 * EditorGUIUtility.singleLineHeight + 1 * EditorGUIUtility.standardVerticalSpacing;
}
return height;
}
}
}