public int GetChildIndex(SerializedPropertyX child)
 {
     if (isCircular)
     {
         return(circularRef.GetChildIndex(child));
     }
     return(children.IndexOf(child));
 }
    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 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;
            }
        }
    }