//todo account for decorators eventually public static float GetHeight(SerializedPropertyX property, GUIContent label, bool includeChildren) { ExtendedPropertyDrawer drawer = Reflector.GetExtendedPropertyDrawerFor(property.type); if (drawer != null) { return drawer.GetPropertyHeight(property, label); } else if (!includeChildren || property.type.IsPrimitive || property.type.IsEnum || property.type == typeof(string) || Array.IndexOf(BuildInTypes, property.type) != -1) { return GetSinglePropertyHeight(property.type, label); } else if (property.type.IsArray) { if (property.isExpanded) { float height = 32f; for (int i = 0; i < property.ChildCount; i++) { SerializedPropertyX child = property.GetChildAt(i); height += GetHeight(child, child.label, child.isExpanded); } return height; } return 16f; } else { float height = 16f; for (int i = 0; i < property.ChildCount; i++) { SerializedPropertyX child = property.GetChildAt(i); height += GetHeight(child, child.label, child.isExpanded); } return height; } }
public override void Render() { if (targetItem == null) { return; } SerializedPropertyX castMode = rootProperty.FindProperty("castMode"); SerializedPropertyX ignoreGCD = rootProperty.FindProperty("IgnoreGCD"); SerializedPropertyX castTime = rootProperty.FindProperty("castTime").FindProperty("baseValue"); SerializedPropertyX channelTime = rootProperty.FindProperty("channelTime").FindProperty("baseValue"); SerializedPropertyX channelTicks = rootProperty.FindProperty("channelTicks").FindProperty("baseValue"); SerializedPropertyX charges = rootProperty.FindProperty("charges"); GUILayout.BeginHorizontal(); EditorGUILayoutX.PropertyField(castMode, false); ignoreGCD.Value = EditorGUILayout.ToggleLeft("Ignore GCD", (bool)ignoreGCD.Value); GUILayout.EndHorizontal(); int castVal = (int)castMode.Value; if (castVal != (int)CastMode.Instant) { if (castVal != (int)CastMode.Channel) { castTime.Value = EditorGUILayout.FloatField(new GUIContent("Cast Time"), (float)castTime.Value); } if (castVal != (int)CastMode.Cast) { channelTime.Value = EditorGUILayout.FloatField(new GUIContent("Channel Time"), (float)channelTime.Value); channelTicks.Value = EditorGUILayout.IntField(new GUIContent("Channel Ticks"), (int)channelTicks.Value); } } EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Charges (" + charges.ArraySize + ")"); if (GUILayout.Button("+", GUILayout.Width(25f))) { charges.ArraySize++; } EditorGUILayout.EndHorizontal(); EditorGUI.indentLevel++; for (int i = 0; i < charges.ArraySize; i++) { EditorGUILayout.BeginHorizontal(); SerializedPropertyX chargeProp = charges.GetChildAt(i); SerializedPropertyX cooldown = chargeProp.FindProperty("cooldown").FindProperty("baseValue"); cooldown.Value = EditorGUILayout.FloatField(new GUIContent("Cooldown"), (float)cooldown.Value); GUI.enabled = charges.ArraySize > 1; if (GUILayout.Button("-", GUILayout.Width(25f), GUILayout.Height(15f))) { charges.DeleteArrayElementAt(i); } GUI.enabled = true; EditorGUILayout.EndHorizontal(); } EditorGUI.indentLevel--; }
public void ChildSetToOrphanedWhenDeletingArrayElement() { string[] strings = new string[] { "one", "two" }; SerializedPropertyX property = new SerializedPropertyX("name", typeof(string[]), strings); SerializedPropertyX child = property.GetChildAt(1); Assert.IsFalse(child.IsOrphaned); property.DeleteArrayElementAt(1); Assert.IsTrue(child.IsOrphaned); }
public void CanSwaListElements() { SerializedPropertyX property = new SerializedPropertyX("name", typeof(List <string>)); property.Value = new List <string> { "hello", "there" }; var child1 = property.GetChildAt(0); var child2 = property.GetChildAt(1); property.SwapArrayElements(0, 1); Assert.AreEqual(property.GetValue <List <string> >()[1], "hello"); Assert.AreEqual(property.GetValue <List <string> >()[0], "there"); Assert.AreEqual(property.GetChildAt(1), child1); Assert.AreEqual(property.GetChildAt(0), child2); Assert.AreEqual(property.ChildCount, 2); }
public void ChildrenSetToOrphanedWhenDecreasingListSize() { List <string> strings = new List <string>(new string[] { "one", "two" }); SerializedPropertyX property = new SerializedPropertyX("name", typeof(List <string>), strings); SerializedPropertyX child = property.GetChildAt(1); Assert.IsFalse(child.IsOrphaned); property.ArraySize--; Assert.IsTrue(child.IsOrphaned); }
public static void DrawProperties(SerializedPropertyX root) { for (int i = 0; i < root.ChildCount; i++) { SerializedPropertyX property = root.GetChildAt(i); if (property.IsDrawable) { PropertyField(property, property.label, property.isExpanded); } } }
public SerializedPropertyX GetChildAt(int idx) { if (isCircular) { return(circularRef.GetChildAt(idx)); } if (children == null || idx < 0 || idx >= children.Count) { return(null); } return(children[idx]); }
public override void Render() { if (rootProperty == null) { return; } SerializedPropertyX isPlayer = rootProperty.FindProperty("isPlayer"); SerializedPropertyX items = rootProperty.FindProperty("items"); SerializedPropertyX abilities = rootProperty.FindProperty("abilities"); SerializedPropertyX prefab = rootProperty.FindProperty("prefab"); GUILayout.BeginVertical(); isPlayer.Value = EditorGUILayout.Toggle(new GUIContent("Player"), (bool)isPlayer.Value); EditorGUILayoutX.PropertyField(prefab); EditorGUILayout.LabelField("Items (" + items.ArraySize + ")"); if (GUILayout.Button("+", GUILayout.Width(20f), GUILayout.Height(15f))) { items.ArraySize++; } EditorGUI.indentLevel++; for (int i = 0; i < items.ArraySize; i++) { GUILayout.BeginHorizontal(); if (GUILayout.Button("-", GUILayout.Width(20f), GUILayout.Height(15f))) { items.DeleteArrayElementAt(i); } EditorGUILayoutX.PropertyField(items.GetChildAt(i)); GUILayout.EndHorizontal(); } EditorGUI.indentLevel--; EditorGUILayout.LabelField("Abilities (" + abilities.ArraySize + ")"); if (GUILayout.Button("+", GUILayout.Width(20f), GUILayout.Height(15f))) { abilities.ArraySize++; } EditorGUI.indentLevel++; for (int i = 0; i < abilities.ArraySize; i++) { GUILayout.BeginHorizontal(); if (GUILayout.Button("-", GUILayout.Width(20f), GUILayout.Height(15f))) { abilities.DeleteArrayElementAt(i); } EditorGUILayoutX.PropertyField(abilities.GetChildAt(i)); GUILayout.EndHorizontal(); } EditorGUI.indentLevel--; GUILayout.EndVertical(); }
protected virtual void RenderBody(SerializedPropertyX property, RenderData data, int index) { EditorGUI.indentLevel++; for (int i = 0; i < property.ChildCount; i++) { SerializedPropertyX child = property.GetChildAt(i); if (skipRenderingFields.IndexOf(child.name) != -1) { continue; } EditorGUILayoutX.PropertyField(child, child.label, child.isExpanded); } EditorGUI.indentLevel--; }
//todo account for decorators eventually public static float GetHeight(SerializedPropertyX property, GUIContent label, bool includeChildren) { ExtendedPropertyDrawer drawer = Reflector.GetExtendedPropertyDrawerFor(property.type); if (drawer != null) { return(drawer.GetPropertyHeight(property, label)); } else if (!includeChildren || property.type.IsPrimitive || property.type.IsEnum || property.type == typeof(string) || Array.IndexOf(BuildInTypes, property.type) != -1) { return(GetSinglePropertyHeight(property.type, label)); } else if (property.type.IsArray) { if (property.isExpanded) { float height = 32f; for (int i = 0; i < property.ChildCount; i++) { SerializedPropertyX child = property.GetChildAt(i); height += GetHeight(child, child.label, child.isExpanded); } return(height); } return(16f); } else { float height = 16f; for (int i = 0; i < property.ChildCount; i++) { SerializedPropertyX child = property.GetChildAt(i); height += GetHeight(child, child.label, child.isExpanded); } return(height); } }
public void ChildrenProperlySetToOrphanedWhenValueSet() { SerializedPropertyX property = new SerializedPropertyX("name", typeof(TestThingContainer)); List <SerializedPropertyX> children = new List <SerializedPropertyX>(); for (int i = 0; i < property.ChildCount; i++) { children.Add(property.GetChildAt(i)); } property.Value = new TestThingContainer(); for (int i = 0; i < children.Count; i++) { Assert.IsTrue(children[i].IsOrphaned); } Assert.IsTrue(children.Count > 0); }
public override void SetTargetProperty(SerializedPropertyX rootProperty) { this.rootProperty = rootProperty; if (rootProperty == null) { listRoot = null; renderData = null; return; } listRoot = rootProperty[ListRootName]; int count = listRoot.ChildCount; renderData = new List <RenderData>(count); for (int i = 0; i < count; i++) { renderData.Add(CreateDataInstance(listRoot.GetChildAt(i), true)); } }
public void DefaultSetTargetProperty(SerializedPropertyX rootProperty, SerializedPropertyX listRoot) { this.rootProperty = rootProperty; if (rootProperty == null) { listRoot = null; renderData = null; return; } this.listRoot = listRoot; int count = listRoot.ChildCount; renderData = new List <RenderData>(count); for (int i = 0; i < count; i++) { renderData.Add(CreateDataInstance(listRoot.GetChildAt(i), true)); } }
public void DefaultRenderBody(SerializedPropertyX property, RenderData data, int index) { EditorGUI.indentLevel++; if (Reflector.GetCustomPropertyDrawerFor(property) != null) { EditorGUILayoutX.PropertyField(property, property.label, property.isExpanded); return; } for (int i = 0; i < property.ChildCount; i++) { SerializedPropertyX child = property.GetChildAt(i); if (skipRenderingFields.IndexOf(child.name) != -1) { continue; } EditorGUILayoutX.PropertyField(child, child.label, child.isExpanded); } EditorGUI.indentLevel--; }
public override void CreateRollButton() { if (GUILayout.Button("Roll Random")) { SerializedPropertyX baseParams = rootProperty.FindProperty("parameters").FindProperty("baseParameters"); System.Random rand = new System.Random(); int sum = 0; for (int i = 2; i < baseParams.ChildCount; i++) { SerializedPropertyX childProp = baseParams.GetChildAt(i).FindProperty("baseValue"); var low = Math.Min(rand.Next(7, 15), rand.Next(3, 18)); var high = Math.Max(rand.Next(9, 17), rand.Next(6, 18)); var randomRoll = (int)rand.Next(low, Mathf.Clamp(high, low, 18)); childProp.Value = randomRoll; sum += randomRoll; } Debug.Log("Total:" + sum); } }
public static void PropertyField(SerializedPropertyX property, GUIContent label, bool includeChildren, params GUILayoutOption[] options) { Type type = property.type; ExtendedPropertyDrawer drawer = Reflector.GetExtendedPropertyDrawerFor(property.type); if (drawer != null) { drawer.OnGUI(GetControlRect(property), property, label); return; } if (type.IsSubclassOf(typeof(UnityEngine.Object))) { property.Value = EditorGUILayout.ObjectField(label, (UnityEngine.Object)property.Value, type, true, options); } else if (type.IsArray) { if (property.Value == null) { property.Value = Array.CreateInstance(type.GetElementType(), 1); } property.isExpanded = EditorGUILayout.Foldout(property.isExpanded, label.text); if (property.isExpanded) { EditorGUI.indentLevel++; property.ArraySize = EditorGUILayout.IntField(new GUIContent("Size"), property.ArraySize); for (int i = 0; i < property.ArraySize; i++) { SerializedPropertyX child = property.GetChildAt(i); PropertyField(child, child.label, child.isExpanded, options); } EditorGUI.indentLevel--; } } else if (type.IsEnum) { property.Value = EditorGUILayout.EnumMaskField(label, (Enum)property.Value, options); } else if (type == typeof(Color)) { property.Value = EditorGUILayout.ColorField(label, (Color)property.Value); } else if (type == typeof(Bounds)) { Bounds b = (Bounds)property.Value; property.Value = EditorGUILayout.BoundsField(label, b, options); } else if (type == typeof(AnimationCurve)) { if (property.Value == null) { property.Value = new AnimationCurve(); } property.Value = EditorGUILayout.CurveField(label, (AnimationCurve)property.Value, options); } else if (type == typeof(double)) { property.Value = EditorGUILayout.DoubleField(label, (double)property.Value); } else if (type == typeof(float)) { property.Value = EditorGUILayout.FloatField(label, (float)property.Value); } else if (type == typeof(int)) { property.Value = EditorGUILayout.IntField(label, (int)property.Value, options); } else if (type == typeof(long)) { property.Value = EditorGUILayout.LongField(label, (long)property.Value, options); } else if (type == typeof(Rect)) { property.Value = EditorGUILayout.RectField(label, (Rect)property.Value, options); } else if (type == typeof(bool)) { property.Value = EditorGUILayout.Toggle(label, (bool)property.Value, options); } else if (type == typeof(Vector2)) { property.Value = EditorGUILayout.Vector2Field(label, (Vector2)property.Value, options); } else if (type == typeof(Vector3)) { property.Value = EditorGUILayout.Vector3Field(label, (Vector3)property.Value, options); } else if (type == typeof(Vector4)) { property.Value = EditorGUILayout.Vector4Field(label.text, (Vector4)property.Value, options); } else if (type == typeof(string)) { property.Value = EditorGUILayout.TextField(label, (string)property.Value, options); } else { property.isExpanded = EditorGUILayout.Foldout(property.isExpanded, label); if (property.isExpanded) { EditorGUI.indentLevel++; for (int i = 0; i < property.ChildCount; i++) { SerializedPropertyX child = property.GetChildAt(i); PropertyField(child, child.label, child.isExpanded, options); } EditorGUI.indentLevel--; } } }
public static void PropertyField(SerializedPropertyX property, GUIContent label, bool includeChildren, params GUILayoutOption[] options) { Type type = property.type; ExtendedPropertyDrawer drawer = Reflector.GetExtendedPropertyDrawerFor(property.type); if (drawer != null) { drawer.OnGUI(GetControlRect(property), property, label); return; } if (type.IsSubclassOf(typeof(UnityEngine.Object))) { property.Value = EditorGUILayout.ObjectField(label, (UnityEngine.Object)property.Value, type, true, options); } else if (type.IsArray) { if (property.Value == null) { property.Value = Array.CreateInstance(type.GetElementType(), 1); } property.isExpanded = EditorGUILayout.Foldout(property.isExpanded, label.text); if (property.isExpanded) { EditorGUI.indentLevel++; property.ArraySize = EditorGUILayout.IntField(new GUIContent("Size"), property.ArraySize); for (int i = 0; i < property.ArraySize; i++) { SerializedPropertyX child = property.GetChildAt(i); PropertyField(child, child.label, child.isExpanded, options); } EditorGUI.indentLevel--; } } else if (type.IsEnum) { property.Value = EditorGUILayout.EnumMaskField(label, (Enum)property.Value, options); } else if (type == typeof(Color)) { property.Value = EditorGUILayout.ColorField(label, (Color)property.Value); } else if (type == typeof(Bounds)) { Bounds b = (Bounds)property.Value; property.Value = EditorGUILayout.BoundsField(label, b, options); } else if (type == typeof(AnimationCurve)) { if (property.Value == null) property.Value = new AnimationCurve(); property.Value = EditorGUILayout.CurveField(label, (AnimationCurve)property.Value, options); } else if (type == typeof(double)) { property.Value = EditorGUILayout.DoubleField(label, (double)property.Value); } else if (type == typeof(float)) { property.Value = EditorGUILayout.FloatField(label, (float)property.Value); } else if (type == typeof(int)) { property.Value = EditorGUILayout.IntField(label, (int)property.Value, options); } else if (type == typeof(long)) { property.Value = EditorGUILayout.LongField(label, (long)property.Value, options); } else if (type == typeof(Rect)) { property.Value = EditorGUILayout.RectField(label, (Rect)property.Value, options); } else if (type == typeof(bool)) { property.Value = EditorGUILayout.Toggle(label, (bool)property.Value, options); } else if (type == typeof(Vector2)) { property.Value = EditorGUILayout.Vector2Field(label, (Vector2)property.Value, options); } else if (type == typeof(Vector3)) { property.Value = EditorGUILayout.Vector3Field(label, (Vector3)property.Value, options); } else if (type == typeof(Vector4)) { property.Value = EditorGUILayout.Vector4Field(label.text, (Vector4)property.Value, options); } else if (type == typeof(string)) { property.Value = EditorGUILayout.TextField(label, (string)property.Value, options); } else { property.isExpanded = EditorGUILayout.Foldout(property.isExpanded, label); if (property.isExpanded) { EditorGUI.indentLevel++; for (int i = 0; i < property.ChildCount; i++) { SerializedPropertyX child = property.GetChildAt(i); PropertyField(child, child.label, child.isExpanded, options); } EditorGUI.indentLevel--; } } }
public static void DrawProperties(SerializedPropertyX root) { for (int i = 0; i < root.ChildCount; i++) { SerializedPropertyX property = root.GetChildAt(i); PropertyField(property, property.label, property.isExpanded); } }
//TODO --- Deprecate EditorGUIX in favor of the EditorGUILayoutX, manual rects are dumb //public static void PropertyField(Rect position, SerializedPropertyX property) { // PropertyField(position, property, property.label, true); //} //public static void PropertyField(SerializedPropertyX property, GUIContent label, bool includeChildren = true) { // var drawer = Reflector.GetCustomPropertyDrawerFor(property); // if (drawer != null) { // drawer.OnGUI(property, label); // } // else { // PropertyFieldExtendedValue(position, property, label); // } //} private static void PropertyFieldExtendedValue(Rect position, SerializedPropertyX property, GUIContent label = null, GUIStyle style = null) { Type type = property.type; if (type.IsSubclassOf(typeof(UnityEngine.Object))) { property.Value = EditorGUI.ObjectField(position, label, (UnityEngine.Object)property.Value, type, true); } else if (type.IsArray) { if (property.Value == null) { property.Value = Array.CreateInstance(type.GetElementType(), 1); } property.isExpanded = EditorGUI.Foldout(position, property.isExpanded, label); if (property.isExpanded) { position.y += 16f; position.height -= 16f; EditorGUI.indentLevel++; Array array = (Array)property.Value; int length = array.Length; int newLength = EditorGUI.IntField(position, new GUIContent("Size"), length); if (newLength < 0) { newLength = 0; } if (length != newLength) { var newArray = Array.CreateInstance(type.GetElementType(), newLength); for (int i = 0; i < newLength; i++) { if (i == array.Length) { break; } newArray.SetValue(array.GetValue(i), i); } array.CopyTo(newArray, 0); array = newArray; } position.y += 16f; position.height -= 16f; Type elementType = array.GetType().GetElementType(); for (int i = 0; i < array.Length; i++) { if (array.GetValue(i) == null) { array.SetValue(CreateInstance(elementType), i); } //array.SetValue(PropertyFieldExtendedValue(position, elementType, array.GetValue(i), new GUIContent("Element " + i), null), i); //position.y += 48f; //needs to be += getheight } EditorGUI.indentLevel--; } } else if (type.IsEnum) { if (style == null) { style = EditorStyles.popup; //todo unity default is popup field } property.Value = EditorGUI.EnumPopup(position, label, (Enum)property.Value, style); } else if (type == typeof(Color)) { property.Value = EditorGUI.ColorField(position, label, (Color)property.Value); } else if (type == typeof(Bounds)) { Bounds b = (Bounds)property.Value; position = EditorGUI.PrefixLabel(position, label); position.x -= 48f; EditorGUI.LabelField(position, new GUIContent("Center:")); position.x += 53f; position.width -= 5f; b.center = EditorGUI.Vector3Field(position, GUIContent.none, b.center); position.y += 16f; position.x -= 53f; EditorGUI.LabelField(position, new GUIContent("Extents:")); position.x += 53f; b.extents = EditorGUI.Vector3Field(position, GUIContent.none, b.extents); property.Value = b; } else if (type == typeof(AnimationCurve)) { if (property.Value == null) { property.Value = new AnimationCurve(); } position.width = 200f; property.Value = EditorGUI.CurveField(position, label, (AnimationCurve)property.Value); } else if (type == typeof(double)) { if (style == null) { style = EditorStyles.numberField; } property.Value = EditorGUI.DoubleField(position, label, (double)property.Value, style); } else if (type == typeof(float)) { if (style == null) { style = EditorStyles.numberField; } property.Value = EditorGUI.FloatField(position, label, (float)property.Value, style); } else if (type == typeof(int)) { if (style == null) { style = EditorStyles.numberField; } property.Value = EditorGUI.IntField(position, label, (int)property.Value, style); } else if (type == typeof(long)) { if (style == null) { style = EditorStyles.numberField; } property.Value = EditorGUI.LongField(position, label, (long)property.Value, style); } else if (type == typeof(Rect)) { property.Value = EditorGUI.RectField(position, label, (Rect)property.Value); } else if (type == typeof(bool)) { if (style == null) { style = EditorStyles.toggle; } property.Value = EditorGUI.Toggle(position, label, (bool)property.Value, style); } else if (type == typeof(Vector2)) { property.Value = EditorGUI.Vector2Field(position, label, (Vector2)property.Value); } else if (type == typeof(Vector3)) { property.Value = EditorGUI.Vector3Field(position, label, (Vector3)property.Value); } else if (type == typeof(Vector4)) { property.Value = EditorGUI.Vector4Field(position, label.text, (Vector4)property.Value); } else if (type == typeof(string)) { if (style == null) { style = EditorStyles.textField; } property.Value = EditorGUI.TextField(position, label, (string)property.Value, style); } else { property.isExpanded = EditorGUI.Foldout(position, property.isExpanded, label); if (property.isExpanded) { EditorGUI.indentLevel++; position.y += 16f; position.height -= 16f; for (int i = 0; i < property.ChildCount; i++) { SerializedPropertyX child = property.GetChildAt(i); // PropertyField(position, child); float propHeight = EditorGUIUtilityX.GetHeight(child, child.label, child.isExpanded); position.y += propHeight; position.height -= propHeight; } EditorGUI.indentLevel--; } } }
public override void Render() { if (rootProperty == null) { return; } SerializedPropertyX contextTypeProp = rootProperty["contextType"]; Type currentType = contextTypeProp.GetValue <Type>(); if (currentType == null) { currentType = typeof(Context); } int idx = 0; for (int i = 1; i < contextTypes.Length; i++) { if (currentType == contextTypes[i]) { idx = i; break; } } int newIdx = EditorGUILayout.Popup("Context Type", idx, contextTypeNames, GUILayout.Width(EditorGUIUtility.labelWidth + 300)); if (idx != newIdx || currentType == null) { Type newType = contextTypes[newIdx]; SerializedPropertyX considerationsProp = rootProperty["considerations"]; SerializedPropertyX requirementsProp = rootProperty["requirements"]; List <SerializedPropertyX> nukeList = new List <SerializedPropertyX>(); for (int i = 0; i < considerationsProp.ChildCount; i++) { Consideration consideration = considerationsProp.GetChildAt(i).Value as Consideration; if (!newType.IsAssignableFrom(consideration.GetContextType())) { nukeList.Add(considerationsProp.GetChildAt(i)); } } for (int i = 0; i < requirementsProp.ChildCount; i++) { Requirement requirement = requirementsProp.GetChildAt(i).Value as Requirement; if (!newType.IsAssignableFrom(requirement.GetContextType())) { nukeList.Add(requirementsProp.GetChildAt(i)); } } if (nukeList.Count > 0) { if (ShouldNuke(nukeList, newType)) { for (int i = 0; i < nukeList.Count; i++) { SerializedPropertyX toNuke = nukeList[i]; int reqChildIndex = requirementsProp.GetChildIndex(toNuke); int conChildIndex = considerationsProp.GetChildIndex(toNuke); requirementsProp.DeleteArrayElementAt(reqChildIndex); considerationsProp.DeleteArrayElementAt(conChildIndex); } contextTypeProp.Value = newType; } } else { contextTypeProp.Value = newType; } } }
private static void PropertyFieldExtendedValue(Rect position, SerializedPropertyX property, GUIContent label = null, GUIStyle style = null) { Type type = property.type; if (type.IsSubclassOf(typeof(UnityEngine.Object))) { property.Value = EditorGUI.ObjectField(position, label, (UnityEngine.Object)property.Value, type, true); } else if (type.IsArray) { if (property.Value == null) { property.Value = Array.CreateInstance(type.GetElementType(), 1); } //int ctrlId = GUIUtility.GetControlID(FocusType.Keyboard); property.isExpanded = EditorGUI.Foldout(position, property.isExpanded, label); if (property.isExpanded) { position.y += 16f; position.height -= 16f; EditorGUI.indentLevel++; Array array = (Array)property.Value; int length = array.Length; int newLength = 0; z = EditorGUI.IntField(position, new GUIContent("Size"), z); if (newLength < 0) newLength = 0; if (length != newLength) { var newArray = Array.CreateInstance(type.GetElementType(), newLength); for (int i = 0; i < newLength; i++) { if (i == array.Length) break; newArray.SetValue(array.GetValue(i), i); } array.CopyTo(newArray, 0); array = newArray; } position.y += 16f; position.height -= 16f; Type elementType = array.GetType().GetElementType(); for (int i = 0; i < array.Length; i++) { if (array.GetValue(i) == null) { array.SetValue(CreateInstance(elementType), i); } //array.SetValue(PropertyFieldExtendedValue(position, elementType, array.GetValue(i), new GUIContent("Element " + i), null), i); //position.y += 48f; //needs to be += getheight } EditorGUI.indentLevel--; } } else if (type.IsEnum) { if (style == null) style = EditorStyles.popup; //todo unity default is popup field property.Value = EditorGUI.EnumMaskField(position, label, (Enum)property.Value, style); } else if (type == typeof(Color)) { property.Value = EditorGUI.ColorField(position, label, (Color)property.Value); } else if (type == typeof(Bounds)) { Bounds b = (Bounds)property.Value; position = EditorGUI.PrefixLabel(position, label); position.x -= 48f; EditorGUI.LabelField(position, new GUIContent("Center:")); position.x += 53f; position.width -= 5f; b.center = EditorGUI.Vector3Field(position, GUIContent.none, b.center); position.y += 16f; position.x -= 53f; EditorGUI.LabelField(position, new GUIContent("Extents:")); position.x += 53f; b.extents = EditorGUI.Vector3Field(position, GUIContent.none, b.extents); property.Value = b; } else if (type == typeof(AnimationCurve)) { if (property.Value == null) property.Value = new AnimationCurve(); position.width = 200f; property.Value = EditorGUI.CurveField(position, label, (AnimationCurve)property.Value); } else if (type == typeof(double)) { if (style == null) style = EditorStyles.numberField; property.Value = EditorGUI.DoubleField(position, label, (double)property.Value, style); } else if (type == typeof(float)) { if (style == null) style = EditorStyles.numberField; property.Value = EditorGUI.FloatField(position, label, (float)property.Value, style); } else if (type == typeof(int)) { if (style == null) style = EditorStyles.numberField; property.Value = EditorGUI.IntField(position, label, (int)property.Value, style); } else if (type == typeof(long)) { if (style == null) style = EditorStyles.numberField; property.Value = EditorGUI.LongField(position, label, (long)property.Value, style); } else if (type == typeof(Rect)) { property.Value = EditorGUI.RectField(position, label, (Rect)property.Value); } else if (type == typeof(bool)) { if (style == null) style = EditorStyles.toggle; property.Value = EditorGUI.Toggle(position, label, (bool)property.Value, style); } else if (type == typeof(Vector2)) { property.Value = EditorGUI.Vector2Field(position, label, (Vector2)property.Value); } else if (type == typeof(Vector3)) { property.Value = EditorGUI.Vector3Field(position, label, (Vector3)property.Value); } else if (type == typeof(Vector4)) { property.Value = EditorGUI.Vector4Field(position, label.text, (Vector4)property.Value); } else if (type == typeof(string)) { if (style == null) style = EditorStyles.textField; property.Value = EditorGUI.TextField(position, label, (string)property.Value, style); } else { property.isExpanded = EditorGUI.Foldout(position, property.isExpanded, label); if (property.isExpanded) { EditorGUI.indentLevel++; position.y += 16f; position.height -= 16f; for (int i = 0; i < property.ChildCount; i++) { SerializedPropertyX child = property.GetChildAt(i); PropertyField(position, child); float propHeight = EditorGUIUtilityX.GetHeight(child, child.label, child.isExpanded); position.y += propHeight; position.height -= propHeight; } EditorGUI.indentLevel--; } } }