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 override void OnGUI(SerializedPropertyX property, GUIContent label) { shown = EditorGUILayout.Foldout(shown, label); if (!shown) { return; } EditorGUI.indentLevel++; EditorGUILayoutX.PropertyField(property["abilityCreator"]); if (property["abilityCreator"].Changed) { //todo assert type matches } if (property["abilityCreator"].Value == null) { property["contextCreator"].Value = null; return; } Type type; PlayerContextCreator current = property["contextCreator"].GetValue <PlayerContextCreator>(); Type currentType = null; if (current != null) { currentType = current.GetType(); } SerializedPropertyX creatorProperty = property["contextCreator"]; if (popup.DrawPopup("Context Constructor", currentType, out type)) { if (type != null) { creatorProperty.Value = Activator.CreateInstance(type); } else { creatorProperty.Value = null; } } if (creatorProperty.Value != null) { EditorGUI.indentLevel++; EditorGUILayoutX.DrawProperties(creatorProperty); EditorGUI.indentLevel--; } EditorGUI.indentLevel--; }