2using System.Collections;
11 private const float LINE_HEIGHT = 18;
12 private const float SPACING = 4;
14 public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
16 EditorGUI.BeginProperty(position, label, property);
20 var inspectorWidth = position.width;
22 var indent = EditorGUI.indentLevel;
23 EditorGUI.indentLevel = 0;
25 var items =
property.FindPropertyRelative(
"_items");
26 var titles =
new string[] {
"Transform",
"",
"",
""};
27 var props =
new string[] {
"transform",
"^",
"v",
"-"};
28 var widths =
new float[] {.7f, .1f, .1f, .1f};
29 var lineHeight = 18.0f;
30 var changedLength =
false;
32 if (items.arraySize > 0)
34 for (
int i = 0; i < items.arraySize; i++)
36 var item = items.GetArrayElementAtIndex(i);
39 for (
int n = 0; n < props.Length; ++n)
41 float w = widths[n] * inspectorWidth;
43 Rect rect =
new Rect(rowX, y, w, lineHeight);
48 EditorGUI.LabelField(rect, titles[n]);
54 EditorGUI.ObjectField(rect, item.objectReferenceValue, typeof(Transform),
true);
58 if (GUI.Button(rect, props[n]))
63 items.DeleteArrayElementAtIndex(i);
64 items.DeleteArrayElementAtIndex(i);
70 items.MoveArrayElement(i, i + 1);
75 if (i < items.arraySize - 1)
77 items.MoveArrayElement(i, i - 1);
87 y += lineHeight + SPACING;
96 var addButtonRect =
new Rect((x + position.width) - widths[widths.Length - 1] * inspectorWidth, y, widths[widths.Length - 1] * inspectorWidth, lineHeight);
97 if (GUI.Button(addButtonRect,
"+"))
99 items.InsertArrayElementAtIndex(items.arraySize);
102 y += lineHeight + SPACING;
105 var addAllButtonRect =
new Rect(x, y, inspectorWidth, lineHeight);
106 if (GUI.Button(addAllButtonRect,
"Assign using all child objects"))
108 var circuit =
property.FindPropertyRelative(
"_circuit").objectReferenceValue as
WaypointCircuit;
109 var children =
new Transform[circuit.transform.childCount];
111 foreach (Transform child
in circuit.transform)
113 children[n++] = child;
116 Array.Sort(children,
new TransformNameComparer());
118 for (n = 0; n < children.Length; ++n)
120 circuit._waypointList._items[n] = children[n];
124 y += lineHeight + SPACING;
126 var renameButtonRect =
new Rect(x, y, inspectorWidth, lineHeight);
127 if (GUI.Button(renameButtonRect,
"Auto Rename numerically from this order"))
129 var circuit =
property.FindPropertyRelative(
"_circuit").objectReferenceValue as
WaypointCircuit;
131 foreach (var child
in circuit._waypointList._items)
133 child.name =
"Waypoint " + (n++).ToString(
"000");
137 y += lineHeight + SPACING;
139 EditorGUI.indentLevel = indent;
140 EditorGUI.EndProperty();
145 var items =
property.FindPropertyRelative(
"_items");
146 const float lineAndSpace = LINE_HEIGHT + SPACING;
147 return 40 + (items.arraySize * lineAndSpace) + lineAndSpace;
150 private class TransformNameComparer : IComparer
152 public int Compare(
object x,
object y)
154 return String.Compare(((Transform) x)?.name, ((Transform) y)?.name, StringComparison.Ordinal);
WaypointList _waypointList
override float GetPropertyHeight(SerializedProperty property, GUIContent label)
override void OnGUI(Rect position, SerializedProperty property, GUIContent label)