public void DeleteArrayElementAt(int index) { if (isCircular) { circularRef.DeleteArrayElementAt(index); return; } if (!IsArrayLike || index < 0 || index >= children.Count) { return; } int start = index; IList list = value as IList; children[index].parent = null; if (list != null) { for (int i = start + 1; i < list.Count; i++) { list[i - 1] = list[i]; children[i - 1] = children[i]; } } if (type.IsArray) { ResizeArray(list.Count - 1); } else { ResizeList(list.Count - 1); } changed = true; }
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 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(); }
public override void Render() { if (targetItem == null) { return; } SerializedPropertyX contextTypeProp = rootProperty["contextType"]; Type selectedType; if (typePopUp.DrawPopup("Context Type", contextTypeProp.GetValue <Type>(), out selectedType)) { SerializedPropertyX componentsProp = rootProperty["components"]; SerializedPropertyX requirementsProp = rootProperty["requirements"]; List <SerializedPropertyX> nukeList = new List <SerializedPropertyX>(); for (int i = 0; i < componentsProp.ChildCount; i++) { AbilityComponent component = componentsProp.GetChildAt(i).Value as AbilityComponent; if (!selectedType.IsAssignableFrom(component.GetContextType())) { nukeList.Add(componentsProp.GetChildAt(i)); } } for (int i = 0; i < requirementsProp.ChildCount; i++) { Requirement requirement = requirementsProp.GetChildAt(i).Value as Requirement; if (!selectedType.IsAssignableFrom(requirement.GetContextType())) { nukeList.Add(requirementsProp.GetChildAt(i)); } } if (nukeList.Count > 0) { if (ShouldNuke(nukeList, selectedType)) { for (int i = 0; i < nukeList.Count; i++) { SerializedPropertyX toNuke = nukeList[i]; int reqChildIndex = requirementsProp.GetChildIndex(toNuke); int comChildIndex = componentsProp.GetChildIndex(toNuke); requirementsProp.DeleteArrayElementAt(reqChildIndex); componentsProp.DeleteArrayElementAt(comChildIndex); } contextTypeProp.Value = selectedType; } } else { contextTypeProp.Value = selectedType; } } }
public void CanDeleteArrayElement() { SerializedPropertyX property = new SerializedPropertyX("name", typeof(string[])); property.Value = new string[] { "hello", "there" }; var child1 = property.GetChildAt(1); property.DeleteArrayElementAt(0); string[] value = property.Value as string[]; Assert.AreEqual(value[0], "there"); Assert.AreEqual(child1, property.GetChildAt(0)); Assert.AreEqual(property.ChildCount, 1); }
private HashSet <ItemType> _itemTypesCheck = new HashSet <ItemType>(); // workaround for the fact that we cannot make serializable hashsets public override void Render() { if (rootProperty == null) { return; } SerializedPropertyX isSoulbound = rootProperty.FindProperty("isSoulbound"); SerializedPropertyX isUnique = rootProperty.FindProperty("isUnique"); SerializedPropertyX isStackable = rootProperty.FindProperty("isStackable"); SerializedPropertyX isUsable = rootProperty.FindProperty("isUsable"); SerializedPropertyX isDestructable = rootProperty.FindProperty("isDestructable"); SerializedPropertyX isTypes = rootProperty.FindProperty("isType"); GUILayout.BeginVertical(); isSoulbound.Value = EditorGUILayout.Toggle(new GUIContent("Soulbound"), (bool)isSoulbound.Value); isUnique.Value = EditorGUILayout.Toggle(new GUIContent("Unique"), (bool)isUnique.Value); isUsable.Value = EditorGUILayout.Toggle(new GUIContent("Usable"), (bool)isUsable.Value); isDestructable.Value = EditorGUILayout.Toggle(new GUIContent("Destructable"), (bool)isDestructable.Value); isStackable.Value = EditorGUILayout.Toggle(new GUIContent("Stackable"), (bool)isStackable.Value); EditorGUILayout.LabelField("Attributes (" + isTypes.ArraySize + ")"); if (GUILayout.Button("+", GUILayout.Width(20f), GUILayout.Height(15f))) { // part of the workaround if (isTypes.ArraySize > 0) { if (!_itemTypesCheck.Add((ItemType)isTypes.GetChildAt(isTypes.ArraySize - 1).Value)) { return; } } isTypes.ArraySize++; } EditorGUI.indentLevel++; for (int i = 0; i < isTypes.ArraySize; i++) { GUILayout.BeginHorizontal(); if (GUILayout.Button("-", GUILayout.Width(20f), GUILayout.Height(15f))) { _itemTypesCheck.Remove((ItemType)isTypes.GetChildAt(i).Value); // also part of the workaround isTypes.DeleteArrayElementAt(i); } EditorGUILayoutX.PropertyField(isTypes.GetChildAt(i)); GUILayout.EndHorizontal(); } EditorGUI.indentLevel--; GUILayout.EndVertical(); }
protected virtual void RenderHeader(SerializedPropertyX property, RenderData data, int index) { EditorGUILayout.BeginHorizontal(); GUIStyle style; style = new GUIStyle(EditorStyles.foldout); style.normal.textColor = Color.white; style.active.textColor = Color.white; style.focused.textColor = Color.white; style.onActive.textColor = Color.white; style.onFocused.textColor = Color.white; style.onNormal.textColor = Color.white; style.onHover.textColor = Color.white; data.isDisplayed = EditorGUILayout.Foldout(data.isDisplayed, GetItemFoldoutLabel(property, data), style); GUILayout.FlexibleSpace(); GUIStyle miniLeft = GUI.skin.GetStyle("minibuttonleft"); GUIStyle miniMid = GUI.skin.GetStyle("minibuttonmid"); GUIStyle miniRight = GUI.skin.GetStyle("minibuttonright"); if (GUILayout.Button("Delete", miniLeft)) { listRoot.DeleteArrayElementAt(index); renderData.RemoveAt(index); return; } GUI.enabled = index != 0; if (GUILayout.Button("Up", miniMid)) { Swap(index, -1); } GUI.enabled = index != listRoot.ChildCount - 1; if (GUILayout.Button("Down", miniRight)) { Swap(index, 1); } GUI.enabled = true; EditorGUILayout.EndHorizontal(); }
public void ChangedFlagIsFlippedWhenManipulatingArray() { List <string> list = new List <string>(); list.Add("Hello"); list.Add("There"); list.Add("Unity"); SerializedPropertyX property = new SerializedPropertyX("name", typeof(List <string>)); property.ArraySize++; Assert.IsTrue(property.Changed); property = new SerializedPropertyX("name", typeof(List <string>), list); property.ArraySize--; Assert.IsTrue(property.Changed); property = new SerializedPropertyX("name", typeof(List <string>), list); property.SwapArrayElements(1, -1); Assert.IsTrue(property.Changed); property = new SerializedPropertyX("name", typeof(List <string>), list); property.DeleteArrayElementAt(1); Assert.IsTrue(property.Changed); }
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; } } }