public override void OnGUI(Rect position, PersistentProperty property, GUIContent label) { var rect = position; rect.height = EditorGUIUtility.singleLineHeight; var propLength = property.Find("Length"); PersistentGUI.BeginShowMixedValue(propLength.hasMultipleDifferentValues); EditorGUI.BeginChangeCheck(); var length = EditorGUI.DelayedIntField(rect, label, propLength.GetValue <int>()); if (EditorGUI.EndChangeCheck()) { length = Mathf.Max(0, length); property.ResizeArray(length); } PersistentGUI.EndShowMixedValue(); rect.y += EditorGUIUtility.singleLineHeight; rect.y += EditorGUIUtility.standardVerticalSpacing; var elType = property.type.GetElementType(); if (property.length == 1 && PersistentGUI.IsDefaultPropertyType(elType)) { EditorGUI.indentLevel += 1; var array = property.GetValue <Array>(); for (int i = 0; i < array.Length; i++) { EditorGUI.BeginChangeCheck(); var itemLabel = new GUIContent("Element " + i); var itemValue = PersistentGUI.DefaultTypeField(rect, itemLabel, array.GetValue(i)); if (EditorGUI.EndChangeCheck()) { var newArray = Array.CreateInstance(elType, array.Length); Array.Copy(array, newArray, array.Length); newArray.SetValue(itemValue, i); property.SetValue(newArray); } rect.y += PersistentGUI.GetDefaultTypeHeight(itemLabel, elType); rect.y += EditorGUIUtility.standardVerticalSpacing; } EditorGUI.indentLevel -= 1; } else { PersistentGUI.BeginColor(Color.yellow); EditorGUI.LabelField(rect, new GUIContent("Array's element is not editable.")); PersistentGUI.EndColor(); } }
public static void BoundsField(Rect position, GUIContent label, PersistentProperty property) { var flag = LabelHasContent(label); if (flag) { var controlID = GUIUtility.GetControlID(s_PropertyHash, FocusType.Keyboard, position); position = MultiFieldPrefixLabel(position, controlID, label, 3); if (EditorGUIUtility.wideMode) { position.y += EditorGUIUtility.singleLineHeight; } } position.height = EditorGUIUtility.singleLineHeight; position = DrawBoundsFieldLabelsAndAdjustPositionForValues(position, EditorGUIUtility.wideMode && flag); MultiPropertyField(position, new GUIContent[] { new GUIContent("X"), new GUIContent("Y"), new GUIContent("Z") }, property.Find(new string[] { "center.x", "center.y", "center.z" })); position.y += EditorGUIUtility.singleLineHeight; MultiPropertyField(position, new GUIContent[] { new GUIContent("X"), new GUIContent("Y"), new GUIContent("Z") }, property.Find(new string[] { "extents.x", "extents.y", "extents.z" })); }
public static void RectField(Rect position, GUIContent label, PersistentProperty property) { MultiPropertyField2x2(position, label, new[] { new GUIContent("X"), new GUIContent("Y"), new GUIContent("W"), new GUIContent("H") }, property.Find(new[] { "x", "y", "width", "height" })); }
public static void Vector4Field(Rect position, GUIContent label, PersistentProperty property) { MultiPropertyField(position, label, new[] { new GUIContent("X"), new GUIContent("Y"), new GUIContent("Z"), new GUIContent("W") }, property.Find(new[] { "x", "y", "z", "w" })); }