8 using System.Collections.Generic;
14 [CustomPropertyDrawer(typeof(Settings),
true)]
17 protected int m_Index;
18 protected int m_DataSize;
19 protected float m_DefaultWidth;
20 protected string m_DisplayName;
21 protected string m_KeyName;
22 protected Rect m_DrawRect;
23 protected Dictionary<string, float> m_Heights =
new Dictionary<string, float>();
24 protected Dictionary<string, bool> m_PropToggles =
new Dictionary<string, bool>();
25 protected Dictionary<string, bool> m_DataToggles =
new Dictionary<string, bool>();
27 public virtual string ClassName {
get {
return ""; } }
28 public virtual List<string> IngorePropertys {
get {
return new List<string> { }; } }
30 public override void OnGUI(
Rect pos, SerializedProperty prop, GUIContent label)
33 m_DrawRect.height = EditorGUIUtility.singleLineHeight;
34 m_DefaultWidth = pos.width;
35 var list = prop.displayName.Split(
' ');
38 if (!
int.TryParse(list[list.Length - 1], out m_Index))
41 m_DisplayName = prop.displayName;
42 m_KeyName = prop.propertyPath +
"_" + m_Index;
46 m_DisplayName = ClassName +
" " + m_Index;
47 m_KeyName = prop.propertyPath +
"_" + m_Index;
52 m_DisplayName = prop.displayName;
54 if (!m_PropToggles.ContainsKey(m_KeyName))
56 m_PropToggles.Add(m_KeyName,
false);
58 if (!m_DataToggles.ContainsKey(m_KeyName))
60 m_DataToggles.Add(m_KeyName,
false);
62 if (!m_Heights.ContainsKey(m_KeyName))
64 m_Heights.Add(m_KeyName, 0);
68 m_Heights[m_KeyName] = 0;
72 private string GetKeyName(SerializedProperty prop)
75 var list = prop.displayName.Split(
' ');
78 int.TryParse(list[list.Length - 1], out index);
80 return prop.propertyPath +
"_" + index;
83 protected void AddSingleLineHeight()
85 m_Heights[m_KeyName] += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
86 m_DrawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
89 protected void AddHeight(
float height)
91 m_Heights[m_KeyName] += height;
92 m_DrawRect.y += height;
95 protected void PropertyListField(SerializedProperty prop,
string relativePropName,
bool showOrder =
true)
97 if (IngorePropertys.Contains(relativePropName))
return;
98 var height = m_Heights[m_KeyName];
99 var toggleKeyName = m_KeyName + relativePropName;
100 m_DataToggles[toggleKeyName] =
ChartEditorHelper.MakeListWithFoldout(ref m_DrawRect, ref height,
101 prop.FindPropertyRelative(relativePropName),
102 m_DataToggles.ContainsKey(toggleKeyName) && m_DataToggles[toggleKeyName], showOrder);
103 m_Heights[m_KeyName] = height;
106 protected void PropertyField(SerializedProperty prop,
string relativePropName)
108 if (IngorePropertys.Contains(relativePropName))
return;
109 if (!
ChartEditorHelper.PropertyField(ref m_DrawRect, m_Heights, m_KeyName, prop, relativePropName))
111 Debug.LogError(
"PropertyField ERROR:" + prop.displayName +
", " + relativePropName);
115 protected void PropertyFieldLimitMin(SerializedProperty prop,
string relativePropName,
float minValue)
117 if (IngorePropertys.Contains(relativePropName))
return;
118 if (!
ChartEditorHelper.PropertyFieldWithMinValue(ref m_DrawRect, m_Heights, m_KeyName, prop,
119 relativePropName, minValue))
121 Debug.LogError(
"PropertyField ERROR:" + prop.displayName +
", " + relativePropName);
124 protected void PropertyFieldLimitMax(SerializedProperty prop,
string relativePropName,
float maxValue)
126 if (IngorePropertys.Contains(relativePropName))
return;
127 if (!
ChartEditorHelper.PropertyFieldWithMaxValue(ref m_DrawRect, m_Heights, m_KeyName, prop,
128 relativePropName, maxValue))
130 Debug.LogError(
"PropertyField ERROR:" + prop.displayName +
", " + relativePropName);
134 protected void PropertyField(SerializedProperty prop, SerializedProperty relativeProp)
136 if (!
ChartEditorHelper.PropertyField(ref m_DrawRect, m_Heights, m_KeyName, relativeProp))
138 Debug.LogError(
"PropertyField ERROR:" + prop.displayName +
", " + relativeProp);
142 protected void PropertyTwoFiled(SerializedProperty prop,
string relativeListProp,
string labelName =
null)
144 PropertyTwoFiled(prop, prop.FindPropertyRelative(relativeListProp), labelName);
146 protected void PropertyTwoFiled(SerializedProperty prop, SerializedProperty relativeListProp,
147 string labelName =
null)
149 if (
string.IsNullOrEmpty(labelName))
151 labelName = relativeListProp.displayName;
153 ChartEditorHelper.MakeTwoField(ref m_DrawRect, m_DefaultWidth, relativeListProp, labelName);
154 m_Heights[m_KeyName] += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
157 protected bool MakeFoldout(SerializedProperty prop,
string relativePropName)
159 if (
string.IsNullOrEmpty(relativePropName))
161 return ChartEditorHelper.MakeFoldout(ref m_DrawRect, m_Heights, m_PropToggles, m_KeyName,
162 m_DisplayName,
null);
166 var relativeProp = prop.FindPropertyRelative(relativePropName);
167 return ChartEditorHelper.MakeFoldout(ref m_DrawRect, m_Heights, m_PropToggles, m_KeyName,
168 m_DisplayName, relativeProp);
172 protected virtual void DrawExtendeds(SerializedProperty prop)
176 public override float GetPropertyHeight(SerializedProperty prop, GUIContent label)
178 var key = GetKeyName(prop);
179 if (m_Heights.ContainsKey(key))
return m_Heights[key] + GetExtendedHeight();
180 else return EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
183 protected virtual float GetExtendedHeight()