RemoveUnused() public method

public RemoveUnused ( ) : void
return void
Example #1
0
    public override void OnInspectorGUI()
    {
        EditorGUIUtility.LookLikeInspector();

        SteeringBehaviorAsset sab = (SteeringBehaviorAsset)target;

        EditorGUILayout.BeginVertical();

        showProperties = EditorGUILayout.Foldout(showProperties,
                                                 "Properties");
        if (showProperties)
        {
            EditorGUI.indentLevel++;
            int idx = 0;
            foreach (SteeringBehaviorAsset.SteeringProperty prop
                     in sab.properties)
            {
                EditorGUILayout.BeginVertical("Box");
                string newName = EditorGUILayout.TextField("Name", prop.name);
                if (!newName.Equals(prop.name))
                {
                    sab.RenameProperty(prop.name,
                                       GetUniqueLinkedPropName(sab, newName));
                }
                EditorGUILayout.BeginHorizontal();
                GUILayout.FlexibleSpace();
                int count = sab.CountUsed(prop.name);
                GUILayout.Label(count + " Link" + (count == 1 ? "" : "s"),
                                EditorStyles.miniLabel);
                EditorGUILayout.Space();
                if (GUILayout.Button("Delete", EditorStyles.miniButton))
                {
                    sab.RemoveProperty(idx);
                }
                EditorGUILayout.EndHorizontal();

                idx++;
                EditorGUILayout.EndVertical();
                EditorGUILayout.Separator();
            }
            EditorGUI.indentLevel--;
        }
        showBehaviors = EditorGUILayout.Foldout(showBehaviors,
                                                "Behavior Definitions");
        if (showBehaviors)
        {
            EditorGUI.indentLevel++;
            int idx = 0;
            foreach (SteeringBehaviorAsset.BehaviorDef def in sab.behaviors)
            {
                EditorGUILayout.BeginVertical("Box");
                EditorGUILayout.LabelField("Type", def.name);
                def.weight  = EditorGUILayout.FloatField("Weight", def.weight);
                def.enabled = EditorGUILayout.Toggle("Enabled", def.enabled);
                EditorGUI.indentLevel++;
                foreach (SteeringBehaviorAsset.LinkedProperty prop in
                         def.properties)
                {
                    EditorGUILayout.BeginVertical("Box");
                    EditorGUI.indentLevel++;
                    EditorGUILayout.LabelField("Built-in Property Name",
                                               prop.name);
                    EditorGUILayout.LabelField("Type", prop.type.ToString());
                    prop.defaultValue = DefaultField(
                        prop.defaultValue, prop.type);
                    List <string> existingProps = new List <string>();
                    existingProps.Add("(None)");
                    foreach (SteeringBehaviorAsset.SteeringProperty p2
                             in sab.properties)
                    {
                        if (p2.type == prop.type)
                        {
                            existingProps.Add(p2.name);
                        }
                    }
                    existingProps.Add("-- Add New --");
                    string[] linkNames = existingProps.ToArray();
                    int      link      = existingProps.IndexOf(prop.link);
                    if (link < 0)
                    {
                        link = 0;
                    }
                    link = EditorGUILayout.Popup("Linked To", link, linkNames);
                    if (link >= 1 && link < linkNames.Length - 1)
                    {
                        prop.link = linkNames[link];
                    }
                    else if (link == linkNames.Length - 1)
                    {
                        prop.link = NewLinkProperty(sab, prop);
                    }
                    else
                    {
                        prop.link = "";
                    }
                    EditorGUILayout.EndVertical();
                    EditorGUILayout.Separator();
                    EditorGUI.indentLevel--;
                }
                EditorGUILayout.BeginHorizontal();
                GUILayout.FlexibleSpace();
                if (GUILayout.Button("Delete", EditorStyles.miniButton))
                {
                    sab.RemoveBehavior(idx);
                    sab.RemoveUnused();
                }
                EditorGUILayout.EndHorizontal();
                EditorGUILayout.EndVertical();

                EditorGUILayout.Separator();

                EditorGUI.indentLevel--;
                idx++;
            }
            EditorGUI.indentLevel--;
        }
        if (GUILayout.Button("Add Behavior"))
        {
            NewSteeringBehavior win = (NewSteeringBehavior)
                                      EditorWindow.GetWindow(typeof(NewSteeringBehavior));
            win.asset = sab;
        }
        EditorGUILayout.EndVertical();

        if (GUI.changed)
        {
            sab.RemoveUnused();
            EditorUtility.SetDirty(target);
        }
    }