Пример #1
0
    public override void OnInspectorGUI()
    {
        //EditorGUIUtility.LookLikeControls();

        // can happen when playmaker is updated...?

        if (fsmComponent == null)
        {
            return;
        }

        var fsm = fsmComponent.Fsm;

        // Make sure common PlayMaker styles are initialized
        // TODO: Remove this dependency so Inspector is lighter weight?

        if (!FsmEditorStyles.IsInitialized())
        {
            FsmEditorStyles.Init();
        }

        // Begin GUI

        EditorGUILayout.BeginHorizontal();

        // Edit FSM name

        fsm.Name = EditorGUILayout.TextField(fsm.Name);

        // Open PlayMaker editor button

        if (GUILayout.Button(new GUIContent("Edit", "Edit in the PlayMaker FSM Editor"), GUILayout.MaxWidth(45)))
        {
            OpenInEditor(fsmComponent);
            GUIUtility.ExitGUI();
        }

        EditorGUILayout.EndHorizontal();

        // Description

        fsm.Description = FsmEditorGUILayout.TextAreaWithHint(fsm.Description, "Description...", GUILayout.MinHeight(60));

        // Help Url

        EditorGUILayout.BeginHorizontal();

        fsm.DocUrl = FsmEditorGUILayout.TextFieldWithHint(fsm.DocUrl, "Documentation Url...");

        var guiEnabled = GUI.enabled;

        if (string.IsNullOrEmpty(fsm.DocUrl))
        {
            GUI.enabled = false;
        }

        if (FsmEditorGUILayout.HelpButton())
        {
            Application.OpenURL(fsm.DocUrl);
        }

        EditorGUILayout.EndHorizontal();

        GUI.enabled = guiEnabled;

        // Basic Settings

/*		if (GUILayout.Button(WatermarkLabel, EditorStyles.popup))
 *              {
 *                      GenerateWatermarkMenu().ShowAsContext();
 *              }
 */
        fsm.RestartOnEnable = GUILayout.Toggle(fsm.RestartOnEnable,
                                               new GUIContent("Reset On Disable",
                                                              "Should the FSM reset or keep its current state on Enable/Disable. Uncheck this if you want to pause an FSM by enabling/disabling the PlayMakerFSM component."));

        fsm.ShowStateLabel = GUILayout.Toggle(fsm.ShowStateLabel, new GUIContent("Show State Label", "Show active state label in game view.\nNOTE: Requires PlayMakerGUI in scene"));

        fsm.EnableDebugFlow = GUILayout.Toggle(fsm.EnableDebugFlow, new GUIContent("Enable Debug Flow", "Enable caching of variables and other state info while the game is running. NOTE: Disabling this can improve performance in the editor (it is always disabled in standalone builds)."));


        // VARIABLES

        FsmEditorGUILayout.LightDivider();
        showControls = EditorGUILayout.Foldout(showControls, new GUIContent("Controls", "FSM Variables and Events exposed in the Inspector."), FsmEditorStyles.CategoryFoldout);

        if (showControls)
        {
            //EditorGUIUtility.LookLikeInspector();

            BuildFsmVariableList();

            foreach (var fsmVar in fsmVariables)
            {
                if (fsmVar.ShowInInspector)
                {
                    fsmVar.DoValueGUI(new GUIContent(fsmVar.Name, fsmVar.Name + (!string.IsNullOrEmpty(fsmVar.Tooltip) ? ":\n" + fsmVar.Tooltip : "")));
                }
            }

            if (GUI.changed)
            {
                FsmEditor.RepaintAll();
            }
        }

        // EVENTS

        //FsmEditorGUILayout.LightDivider();
        //showExposedEvents = EditorGUILayout.Foldout(showExposedEvents, new GUIContent("Events", "To expose events here:\nIn PlayMaker Editor, Events tab, select an event and check Inspector."), FsmEditorStyles.CategoryFoldout);

        if (showControls)
        {
            EditorGUI.indentLevel = 1;

            //GUI.enabled = Application.isPlaying;

            foreach (var fsmEvent in fsm.ExposedEvents)
            {
                if (GUILayout.Button(fsmEvent.Name))
                {
                    fsm.Event(fsmEvent);
                }
            }

            if (GUI.changed)
            {
                FsmEditor.RepaintAll();
            }
        }

        //GUI.enabled = true;

        //INFO

        EditorGUI.indentLevel = 0;

        FsmEditorGUILayout.LightDivider();
        showInfo = EditorGUILayout.Foldout(showInfo, "Info", FsmEditorStyles.CategoryFoldout);

        if (showInfo)
        {
            EditorGUI.indentLevel = 1;

            //FsmEditorGUILayout.LightDivider();
            //GUILayout.Label("Summary", EditorStyles.boldLabel);

            showStates = EditorGUILayout.Foldout(showStates, "States [" + fsmComponent.FsmStates.Length + "]");
            if (showStates)
            {
                string states = "";

                if (fsmComponent.FsmStates.Length > 0)
                {
                    foreach (var state in fsmComponent.FsmStates)
                    {
                        states += "\t\t" + state.Name + "\n";
                    }
                    states = states.Substring(0, states.Length - 1);
                }
                else
                {
                    states = "\t\t[none]";
                }

                GUILayout.Label(states);
            }

            showEvents = EditorGUILayout.Foldout(showEvents, "Events [" + fsmComponent.FsmEvents.Length + "]");
            if (showEvents)
            {
                string events = "";

                if (fsmComponent.FsmEvents.Length > 0)
                {
                    foreach (var fsmEvent in fsmComponent.FsmEvents)
                    {
                        events += "\t\t" + fsmEvent.Name + "\n";
                    }
                    events = events.Substring(0, events.Length - 1);
                }
                else
                {
                    events = "\t\t[none]";
                }

                GUILayout.Label(events);
            }

            showVariables = EditorGUILayout.Foldout(showVariables, "Variables [" + fsmVariables.Count + "]");
            if (showVariables)
            {
                string variables = "";

                if (fsmVariables.Count > 0)
                {
                    foreach (var fsmVar in fsmVariables)
                    {
                        variables += "\t\t" + fsmVar.Name + "\n";
                    }
                    variables = variables.Substring(0, variables.Length - 1);
                }
                else
                {
                    variables = "\t\t[none]";
                }

                GUILayout.Label(variables);
            }
        }
    }
Пример #2
0
    public override void OnInspectorGUI()
    {
        //EditorGUIUtility.LookLikeControls();

        // can happen when playmaker is updated...?

        if (fsmComponent == null)
        {
            return;
        }

        if (!FsmEditorStyles.IsInitialized())
        {
            FsmEditorStyles.Init();
        }

        if (textAreaStyle == null)
        {
            textAreaStyle = new GUIStyle(EditorStyles.textField)
            {
                wordWrap = true
            };
        }

        EditorGUILayout.BeginHorizontal();

        fsmComponent.FsmName = EditorGUILayout.TextField(fsmComponent.FsmName);

        //fsmComponent.Fsm.ShowStateLabel = GUILayout.Toggle(fsmComponent.Fsm.ShowStateLabel, new GUIContent("i", "Show active state label in game view. NOTE: Requires PlayMakerGUI in scene"), "Button", GUILayout.MaxWidth(40));

        if (GUILayout.Button(new GUIContent("Edit", "Edit in the PlayMaker FSM Editor"), GUILayout.MaxWidth(45)))
        {
            FsmEditorWindow.OpenWindow(fsmComponent);
            GUIUtility.ExitGUI();
        }

        //showInfo = GUILayout.Toggle(showInfo, new GUIContent("Info","Show overview of States, Events and Variables"), "Button", GUILayout.MaxWidth(50));

        EditorGUILayout.EndHorizontal();

        fsmComponent.FsmDescription = EditorGUILayout.TextArea(fsmComponent.FsmDescription, textAreaStyle);

        fsmComponent.Fsm.ShowStateLabel = GUILayout.Toggle(fsmComponent.Fsm.ShowStateLabel, new GUIContent("Show State Label", "Show active state label in game view.\nNOTE: Requires PlayMakerGUI in scene"));

        // VARIABLES

        FsmEditorGUILayout.LightDivider();
        showControls = EditorGUILayout.Foldout(showControls, new GUIContent("Controls", "FSM Variables and Events exposed in the Inspector."), FsmEditorStyles.CategoryFoldout);

        if (showControls)
        {
            //EditorGUIUtility.LookLikeInspector();

            BuildFsmVariableList();

            foreach (var fsmVar in fsmVariables)
            {
                if (fsmVar.ShowInInspector)
                {
                    fsmVar.DoValueGUI(new GUIContent(fsmVar.Name, fsmVar.Name + (!string.IsNullOrEmpty(fsmVar.Tooltip) ? ":\n" + fsmVar.Tooltip : "")));
                }
            }

            if (GUI.changed)
            {
                FsmEditor.RepaintAll();
            }
        }

        // EVENTS

        //FsmEditorGUILayout.LightDivider();
        //showExposedEvents = EditorGUILayout.Foldout(showExposedEvents, new GUIContent("Events", "To expose events here:\nIn PlayMaker Editor, Events tab, select an event and check Inspector."), FsmEditorStyles.CategoryFoldout);

        if (showControls)
        {
            EditorGUI.indentLevel = 1;

            //GUI.enabled = Application.isPlaying;

            foreach (var fsmEvent in fsmComponent.Fsm.ExposedEvents)
            {
                if (GUILayout.Button(fsmEvent.Name))
                {
                    fsmComponent.Fsm.Event(fsmEvent);
                }
            }

            if (GUI.changed)
            {
                FsmEditor.RepaintAll();
            }
        }

        //GUI.enabled = true;

        //INFO

        EditorGUI.indentLevel = 0;

        FsmEditorGUILayout.LightDivider();
        showInfo = EditorGUILayout.Foldout(showInfo, "Info", FsmEditorStyles.CategoryFoldout);

        if (showInfo)
        {
            EditorGUI.indentLevel = 1;

            //FsmEditorGUILayout.LightDivider();
            //GUILayout.Label("Summary", EditorStyles.boldLabel);

            showStates = EditorGUILayout.Foldout(showStates, "States [" + fsmComponent.FsmStates.Length + "]");
            if (showStates)
            {
                string states = "";

                if (fsmComponent.FsmStates.Length > 0)
                {
                    foreach (var state in fsmComponent.FsmStates)
                    {
                        states += "\t\t" + state.Name + "\n";
                    }
                    states = states.Substring(0, states.Length - 1);
                }
                else
                {
                    states = "\t\t[none]";
                }

                GUILayout.Label(states);
            }

            showEvents = EditorGUILayout.Foldout(showEvents, "Events [" + fsmComponent.FsmEvents.Length + "]");
            if (showEvents)
            {
                string events = "";

                if (fsmComponent.FsmEvents.Length > 0)
                {
                    foreach (var fsmEvent in fsmComponent.FsmEvents)
                    {
                        events += "\t\t" + fsmEvent.Name + "\n";
                    }
                    events = events.Substring(0, events.Length - 1);
                }
                else
                {
                    events = "\t\t[none]";
                }

                GUILayout.Label(events);
            }

            showVariables = EditorGUILayout.Foldout(showVariables, "Variables [" + fsmVariables.Count + "]");
            if (showVariables)
            {
                string variables = "";

                if (fsmVariables.Count > 0)
                {
                    foreach (var fsmVar in fsmVariables)
                    {
                        variables += "\t\t" + fsmVar.Name + "\n";
                    }
                    variables = variables.Substring(0, variables.Length - 1);
                }
                else
                {
                    variables = "\t\t[none]";
                }

                GUILayout.Label(variables);
            }
        }
    }