Beispiel #1
0
    static void CreateAsset()
    {
        AreaFlagDef item = EditorUtil.CreateAsset <AreaFlagDef>(NMBEditorUtil.AssetLabel);

        EditorUtility.FocusProjectWindow();
        Selection.activeObject = item;
    }
Beispiel #2
0
    /// <summary>
    /// Controls behavior of the inspector.
    /// </summary>
    public override void OnInspectorGUI()
    {
        AreaFlagDef targ = (AreaFlagDef)target;

        // Has someone done something naughty?

        if (targ.areas == null || targ.areas == null || targ.areas.Count != targ.flags.Count)
        {
            Debug.LogError("Data null reference or size mismatch. Resetting component.", targ);
            targ.areas = new List <byte>();
            targ.flags = new List <int>();
        }

        List <byte> areas = targ.areas;
        List <int>  flags = targ.flags;

        EditorGUILayout.Separator();

        targ.SetPriority(EditorGUILayout.IntField("Priority", targ.Priority));

        EditorGUILayout.Separator();

        GUILayout.Label("Area / Flags");

        EditorGUILayout.Separator();

        if (areas.Count > 0)
        {
            EditorGUILayout.BeginVertical();

            int delChoice = -1;

            for (int i = 0; i < areas.Count; i++)
            {
                EditorGUILayout.BeginHorizontal();

                // Note: Duplicates are a waste, but technically ok.

                areas[i] = mAreaControl.OnGUI(areas[i]);
                flags[i] = EditorGUILayout.MaskField(flags[i], mFlagNames);

                if (GUILayout.Button("X", GUILayout.Width(30)))
                {
                    delChoice = i;
                }

                EditorGUILayout.EndHorizontal();
            }

            if (delChoice >= 0)
            {
                flags.RemoveAt(delChoice);
                areas.RemoveAt(delChoice);
            }

            EditorGUILayout.EndVertical();
        }

        EditorGUILayout.BeginVertical();
        EditorGUILayout.Separator();

        EditorGUILayout.BeginHorizontal();

        mAddSelection = mAreaControl.OnGUI(mAddSelection);

        if (GUILayout.Button("Add"))
        {
            areas.Add(mAddSelection);
            flags.Add(org.critterai.nmbuild.NMBuild.DefaultFlag);
            GUI.changed = true;
        }

        EditorGUILayout.EndHorizontal();

        EditorGUILayout.EndVertical();

        EditorGUILayout.Separator();

        GUILayout.Box("Input Build Processor\n\nAdds an NMGen processor that adds flags to"
                      + " polygons based on area assignment. E.g. Add the 'swim' flag to all 'water'"
                      + " polygons."
                      , EditorUtil.HelpStyle
                      , GUILayout.ExpandWidth(true));

        EditorGUILayout.Separator();

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