Exemplo n.º 1
0
        /**
         * Called every frame.
         */
        private static void Update()
        {
            // Reinitialize modified fsms and repaint all if some fsms were modified.
            foreach (PlayMakerFSM playMakerFSM in m_dirtyPlayMakerFSMs)
            {
                playMakerFSM.Fsm.Reinitialize();
            }
            m_dirtyPlayMakerFSMs.Clear();
            if (m_fsmEditorDirty)
            {
                m_fsmEditorDirty = false;
                EditorCommands.UpdateGraphView();
                FsmEditor.SetFsmDirty();
                FsmEditor.RepaintAll();
            }

            // Lock all fsms that were temporarily unlocked before saving the scene.
            if (m_unlockedPlayMakerFSMs.Count > 0)
            {
                LockAllFsms();
            }

            // Lock all fsms that are on a locked game object.
            foreach (PlayMakerFSM playMakerFSM in m_playMakerFSMsToBeLocked)
            {
                LockFsm(playMakerFSM);
            }
            m_playMakerFSMsToBeLocked.Clear();
        }
Exemplo n.º 2
0
        protected void DoTopicGUI(GuidedTour.Topic topic)
        {
            if (!guidedTour.IsVisible(topic))
            {
                return;
            }

            var isRepaint = Event.current.type == EventType.Repaint;

            // setup selected styles
            var isSelected = guidedTour.IsHighlighted(topic);
            var rowStyle   = isSelected ? FsmEditorStyles.ActionItemSelected : FsmEditorStyles.ActionItem;
            var labelStyle = isSelected ? FsmEditorStyles.ActionLabelSelected : FsmEditorStyles.ActionLabel;

            GUILayout.BeginHorizontal(rowStyle);

            GUILayout.Space(topic.Indent * 10f);

            if (!string.IsNullOrEmpty(topic.HelpUrl))
            {
                if (FsmEditorGUILayout.HelpButton())
                {
                    Application.OpenURL(topic.HelpUrl);
                }
            }
            else
            {
                GUILayout.Space(18f);
            }

            if (GUILayout.Button(topic.Label, labelStyle))
            {
                autoScroll = true;
                guidedTour.HighlightTopic(topic);
                FsmEditor.RepaintAll();
                GUIUtility.ExitGUI();
            }

            GUILayout.Space(20); // reserve space for scrollbar
            GUILayout.EndHorizontal();

            // Store selectedRect for auto scroll

            if (isRepaint)
            {
                if (isSelected)
                {
                    selectedRect         = GUILayoutUtility.GetLastRect();
                    selectedRect.y      -= scrollPosition.y + 20;
                    selectedRect.height += 20; // pad to scroll a little further
                }

                if (topic.IsNew(NewVersion))
                {
                    var rect = GUILayoutUtility.GetLastRect();
                    GUI.Label(rect, NewTag, FsmEditorStyles.NewTag);
                }
            }
        }
        public override void Initialize()
        {
            // First time?

            if (position.height < 300)
            {
                position = new Rect(position.x, position.y, position.width, 600);
            }

            minSize = new Vector2(200, 300);

            // Refresh highlights created in repaint
            FsmEditor.RepaintAll();

            wantsMouseMove = true;

            guidedTour.OnSelectionChanged = RepaintAll;
        }
Exemplo n.º 4
0
    public override void OnInspectorGUI()
    {
        if (fsmComponent == null)
        {
            return;                       // shouldn't happen
        }
        FsmEditorStyles.Init();

        var fsm = fsmComponent.Fsm;  // grab Fsm for convenience

        if (fsm.States.Length > 100) // a little arbitrary, but better than nothing!
        {
            EditorGUILayout.HelpBox("NOTE: Collapse this inspector for better editor performance with large FSMs.", MessageType.None);
        }

        // Edit FSM name

        EditorGUILayout.BeginHorizontal();

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

        if (GUILayout.Button(new GUIContent(Strings.Label_Edit, Strings.Tooltip_Edit_in_the_PlayMaker_Editor), GUILayout.MaxWidth(45)))
        {
            OpenInEditor(fsmComponent);
            GUIUtility.ExitGUI();
        }

        EditorGUILayout.EndHorizontal();

        // Edit FSM Template

        EditorGUILayout.BeginHorizontal();

        var template = (FsmTemplate)
                       EditorGUILayout.ObjectField(new GUIContent(Strings.Label_Use_Template, Strings.Tooltip_Use_Template),
                                                   fsmComponent.FsmTemplate, typeof(FsmTemplate), false);

        if (template != fsmComponent.FsmTemplate)
        {
            SelectTemplate(template);
        }

        if (GUILayout.Button(new GUIContent(Strings.Label_Browse, Strings.Tooltip_Browse_Templates), GUILayout.MaxWidth(45)))
        {
            DoSelectTemplateMenu();
        }

        EditorGUILayout.EndHorizontal();

        // Disable GUI that can't be edited if referencing a template

        if (!Application.isPlaying && fsmComponent.FsmTemplate != null)
        {
            template = fsmComponent.FsmTemplate;
            fsm      = template.fsm;

            GUI.enabled = false;
        }

        // Edit Description

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

        // Edit Help Url (lets the user link to documentation for the FSM)

        EditorGUILayout.BeginHorizontal();

        fsm.DocUrl = FsmEditorGUILayout.TextFieldWithHint(fsm.DocUrl, Strings.Tooltip_Documentation_Url);

        var guiEnabled = GUI.enabled;

        GUI.enabled = !string.IsNullOrEmpty(fsm.DocUrl);

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

        EditorGUILayout.EndHorizontal();

        GUI.enabled = guiEnabled;

        // Edit FSM Settings

        fsm.RestartOnEnable = GUILayout.Toggle(fsm.RestartOnEnable, new GUIContent(Strings.Label_Reset_On_Disable, Strings.Tooltip_Reset_On_Disable));
        fsm.ShowStateLabel  = GUILayout.Toggle(fsm.ShowStateLabel, new GUIContent(Strings.Label_Show_State_Label, Strings.Tooltip_Show_State_Label));
        fsm.EnableDebugFlow = GUILayout.Toggle(fsm.EnableDebugFlow, new GUIContent(Strings.FsmEditorSettings_Enable_DebugFlow, Strings.FsmEditorSettings_Enable_DebugFlow_Tooltip));

        // The rest of the GUI is readonly so we can check for changes here

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

        // Controls Section

        GUI.enabled = true;

        // Show FSM variables with Inspector option checked

        FsmEditorGUILayout.LightDivider();
        showControls = EditorGUILayout.Foldout(showControls, new GUIContent(Strings.Label_Controls, Strings.Tooltip_Controls), FsmEditorStyles.CategoryFoldout);

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

            BuildFsmVariableList();

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

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

        // Show events with Inspector option checked
        // These become buttons that the user can press to send the events

        if (showControls)
        {
            foreach (var fsmEvent in fsm.ExposedEvents)
            {
                GUILayout.BeginHorizontal();
                EditorGUILayout.PrefixLabel(fsmEvent.Name);
                if (GUILayout.Button(fsmEvent.Name))
                {
                    fsm.Event(fsmEvent);
                    FsmEditor.RepaintAll();
                }
                GUILayout.EndHorizontal();
            }
        }

        // Show general info about the FSM

        EditorGUI.indentLevel = 0;

        FsmEditorGUILayout.LightDivider();
        showInfo = EditorGUILayout.Foldout(showInfo, Strings.Label_Info, FsmEditorStyles.CategoryFoldout);

        if (showInfo)
        {
            EditorGUI.indentLevel = 1;

            showStates = EditorGUILayout.Foldout(showStates, string.Format(Strings.Label_States_Count, fsm.States.Length));
            if (showStates)
            {
                string states = "";

                if (fsm.States.Length > 0)
                {
                    foreach (var state in fsm.States)
                    {
                        states += FsmEditorStyles.tab2 + state.Name + FsmEditorStyles.newline;
                    }
                    states = states.Substring(0, states.Length - 1);
                }
                else
                {
                    states = FsmEditorStyles.tab2 + Strings.Label_None_In_Table;
                }

                GUILayout.Label(states);
            }

            showEvents = EditorGUILayout.Foldout(showEvents, string.Format(Strings.Label_Events_Count, fsm.Events.Length));
            if (showEvents)
            {
                var events = "";

                if (fsm.Events.Length > 0)
                {
                    foreach (var fsmEvent in fsm.Events)
                    {
                        events += FsmEditorStyles.tab2 + fsmEvent.Name + FsmEditorStyles.newline;
                    }
                    events = events.Substring(0, events.Length - 1);
                }
                else
                {
                    events = FsmEditorStyles.tab2 + Strings.Label_None_In_Table;
                }

                GUILayout.Label(events);
            }

            showVariables = EditorGUILayout.Foldout(showVariables, string.Format(Strings.Label_Variables_Count, fsmVariables.Count));
            if (showVariables)
            {
                var variables = "";

                if (fsmVariables.Count > 0)
                {
                    foreach (var fsmVar in fsmVariables)
                    {
                        variables += FsmEditorStyles.tab2 + fsmVar.Name + FsmEditorStyles.newline;
                    }
                    variables = variables.Substring(0, variables.Length - 1);
                }
                else
                {
                    variables = FsmEditorStyles.tab2 + Strings.Label_None_In_Table;
                }

                GUILayout.Label(variables);
            }
        }

        // Manual refresh if template has been edited

        if (fsmTemplate != null)
        {
            if (GUILayout.Button(new GUIContent("Refresh Template", "Use this if you've updated the template but don't see the changes here.")))
            {
                RefreshTemplate();
            }
        }
    }
 public void OnFocus()
 {
     // Repaint all to make sure highlight ids are refreshed
     FsmEditor.RepaintAll();
     Repaint();
 }
Exemplo n.º 6
0
    public override void OnInspectorGUI()
    {
        if (textAreaStyle == null)
        {
            textAreaStyle          = new GUIStyle(EditorStyles.textField);
            textAreaStyle.wordWrap = true;
        }

        EditorGUILayout.BeginHorizontal();

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

        if (GUILayout.Button(new GUIContent("Edit", "Edit in the PlayMaker FSM Editor"), GUILayout.MaxWidth(50)))
        {
            FsmEditorWindow.OpenWindow();
            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);

        //if (GUILayout.Button("Update Control Panel"))
        //	BuildFsmVariableList();

        // VARIABLES

        BuildFsmVariableList();

        //GUILayout.Label("Variables");

        foreach (var fsmVar in fsmVariables)
        {
            if (fsmVar.ShowInInspector)
            {
                fsmVar.DoValueGUI(new GUIContent(fsmVar.Name, fsmVar.Tooltip));
            }
        }

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

        //INFO

        if (showInfo)
        {
            //GUILayout.Label("Description");
            //fsmComponent.FsmDescription = EditorGUILayout.TextArea(fsmComponent.FsmDescription);

            GUILayout.Label("Summary");

            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);
            }
        }
    }
Exemplo n.º 7
0
    public override void OnInspectorGUI()
    {
        if (fsmComponent == null)
        {
            return;                       // shouldn't happen
        }
        if (!initialized)
        {
            Initialize();
        }

        if (!fsmComponent.Fsm.Initialized)
        {
            // Note: cannot do this in OnEnable since is breaks FSMs in editor
            // Safe to do now since FSM would already have initialized itself
            fsmComponent.Fsm.Init(fsmComponent);
        }

        FsmEditorStyles.Init();

        var fsm = fsmComponent.Fsm; // grab Fsm for convenience

        if (fsm.States.Length > 50) // a little arbitrary, but better than nothing!
        {
            EditorGUILayout.HelpBox("NOTE: Collapse this inspector for better editor performance with large FSMs.", MessageType.None);
        }

        // Edit FSM name

        EditorGUILayout.BeginHorizontal();
        var foldoutRect = GUILayoutUtility.GetRect(GUIContent.none, EditorStyles.foldout, GUILayout.Width(0));

        fsm.NameIsExpanded = EditorGUI.Foldout(foldoutRect, fsm.NameIsExpanded, GUIContent.none);

        EditorGUI.BeginChangeCheck();
        fsm.Name = EditorGUILayout.TextField(fsm.Name);
        if (EditorGUI.EndChangeCheck())
        {
            Labels.Update(fsm);
        }

        // Edit FSM Button
        if (GUILayout.Button(FsmEditorContent.EditFsmButton, GUILayout.MaxWidth(45)))
        {
            OpenInEditor(fsmComponent);
            GUIUtility.ExitGUI();
        }
        EditorGUILayout.EndHorizontal();

        if (fsm.NameIsExpanded)
        {
            // Edit FSM Template

            EditorGUILayout.BeginHorizontal();
            var template = (FsmTemplate)EditorGUILayout.ObjectField(FsmEditorContent.UseTemplateLabel, fsmComponent.FsmTemplate, typeof(FsmTemplate), false);
            if (template != fsmComponent.FsmTemplate)
            {
                SelectTemplate(template);
            }
            if (GUILayout.Button(FsmEditorContent.BrowseTemplateButton, GUILayout.MaxWidth(45)))
            {
                DoSelectTemplateMenu();
            }
            EditorGUILayout.EndHorizontal();

            // Disable GUI that can't be edited if referencing a template

            EditorGUI.BeginDisabledGroup(!Application.isPlaying && fsmComponent.FsmTemplate != null);

            if (fsmComponent.FsmTemplate != null)
            {
                // next few fields should show template values
                template = fsmComponent.FsmTemplate;
                fsm      = template.fsm;
            }

            // Edit Description

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

            // Edit Help Url (lets the user link to documentation for the FSM)

            EditorGUILayout.BeginHorizontal();
            fsm.DocUrl = FsmEditorGUILayout.TextFieldWithHint(fsm.DocUrl, Strings.Tooltip_Documentation_Url);
            EditorGUI.BeginDisabledGroup(!string.IsNullOrEmpty(fsm.DocUrl));
            if (FsmEditorGUILayout.HelpButton())
            {
                Application.OpenURL(fsm.DocUrl);
            }
            EditorGUI.EndDisabledGroup();
            EditorGUILayout.EndHorizontal();

            // Settings

            EditorGUI.BeginDisabledGroup(!Application.isPlaying && FsmEditor.SelectedFsmUsesTemplate);

            fsm.MaxLoopCountOverride = EditorGUILayout.IntField(FsmEditorContent.MaxLoopOverrideLabel, fsm.MaxLoopCountOverride);
            fsm.RestartOnEnable      = GUILayout.Toggle(fsm.RestartOnEnable, FsmEditorContent.ResetOnDisableLabel);

            EditorGUI.EndDisabledGroup(); // Settings
            EditorGUI.EndDisabledGroup(); // Uses template

            // stop showing template values
            fsm = fsmComponent.Fsm;
        }

        // Controls Section

        // Show FSM variables with Inspector option checked

        FsmEditorGUILayout.LightDivider();
        fsm.ControlsIsExpanded = EditorGUILayout.Foldout(fsm.ControlsIsExpanded, FsmEditorContent.FsmControlsLabel, FsmEditorStyles.CategoryFoldout);
        if (fsm.ControlsIsExpanded)
        {
            BuildFsmVariableList();

            var currentCategory = 0;
            for (var index = 0; index < fsmVariables.Count; index++)
            {
                var fsmVariable = fsmVariables[index];
                if (fsmVariable.ShowInInspector)
                {
                    var categoryID = fsmVariable.CategoryID;
                    if (categoryID > 0 && categoryID != currentCategory)
                    {
                        currentCategory = categoryID;
                        GUILayout.Label(fsmComponent.Fsm.Variables.Categories[categoryID], EditorStyles.boldLabel);
                        FsmEditorGUILayout.LightDivider();
                    }
                    fsmVariable.DoInspectorGUI(FsmEditorContent.TempContent(fsmVariable.Name, fsmVariable.Name + (!string.IsNullOrEmpty(fsmVariable.Tooltip) ? ":\n" + fsmVariable.Tooltip : "")));
                }
            }
        }

        // Show events with Inspector option checked
        // These become buttons that the user can press to send the events

        if (fsm.ControlsIsExpanded)
        {
            foreach (var fsmEvent in fsm.ExposedEvents)
            {
                //GUILayout.BeginHorizontal();
                //EditorGUILayout.PrefixLabel(fsmEvent.Name);
                if (GUILayout.Button(fsmEvent.Name))
                {
                    fsm.Event(fsmEvent);
                    FsmEditor.RepaintAll();
                }
                //GUILayout.EndHorizontal();
            }
        }

        // DEBUG

        FsmEditorGUILayout.LightDivider();
        fsm.DebugIsExpanded = EditorGUILayout.Foldout(fsm.DebugIsExpanded, "Debug", FsmEditorStyles.CategoryFoldout);
        if (fsm.DebugIsExpanded)
        {
            fsm.ShowStateLabel = GUILayout.Toggle(fsm.ShowStateLabel, FsmEditorContent.ShowStateLabelsLabel);
        }

        // Experimental
        // Hide for now

        /*
         * FsmEditorGUILayout.LightDivider();
         * fsm.ExperimentalIsExpanded = EditorGUILayout.Foldout(fsm.ExperimentalIsExpanded, "Experimental", FsmEditorStyles.CategoryFoldout);
         * if (fsm.ExperimentalIsExpanded)
         * {
         *  fsm.KillDelayedEventsOnStateExit = GUILayout.Toggle(fsm.KillDelayedEventsOnStateExit, FsmEditorContent.KillDelayedEvents);
         * }*/

        #region INFO
        // Show general info about the FSM

        /* Is this useful...?
         * EditorGUI.indentLevel = 0;
         * FsmEditorGUILayout.LightDivider();
         * showInfo = EditorGUILayout.Foldout(showInfo, Strings.Label_Info, FsmEditorStyles.CategoryFoldout);
         * if (showInfo)
         * {
         *  EditorGUI.indentLevel = 1;
         *
         *  showStates = EditorGUILayout.Foldout(showStates, string.Format(Strings.Label_States_Count, fsm.States.Length));
         *  if (showStates)
         *  {
         *      string states = "";
         *
         *      if (fsm.States.Length > 0)
         *      {
         *          foreach (var state in fsm.States)
         *          {
         *              states += FsmEditorStyles.tab2 + state.Name + FsmEditorStyles.newline;
         *          }
         *          states = states.Substring(0, states.Length - 1);
         *      }
         *      else
         *      {
         *          states = FsmEditorStyles.tab2 + Strings.Label_None_In_Table;
         *      }
         *      GUILayout.Label(states);
         *  }
         *
         *  showEvents = EditorGUILayout.Foldout(showEvents, string.Format(Strings.Label_Events_Count, fsm.Events.Length));
         *  if (showEvents)
         *  {
         *      var events = "";
         *
         *      if (fsm.Events.Length > 0)
         *      {
         *          foreach (var fsmEvent in fsm.Events)
         *          {
         *              events += FsmEditorStyles.tab2 + fsmEvent.Name + FsmEditorStyles.newline;
         *          }
         *          events = events.Substring(0, events.Length - 1);
         *      }
         *      else
         *      {
         *          events = FsmEditorStyles.tab2 + Strings.Label_None_In_Table;
         *      }
         *      GUILayout.Label(events);
         *  }
         *
         *  showVariables = EditorGUILayout.Foldout(showVariables, string.Format(Strings.Label_Variables_Count, fsmVariables.Count));
         *  if (showVariables)
         *  {
         *      var variables = "";
         *
         *      if (fsmVariables.Count > 0)
         *      {
         *          foreach (var fsmVar in fsmVariables)
         *          {
         *              variables += FsmEditorStyles.tab2 + fsmVar.Name + FsmEditorStyles.newline;
         *          }
         *          variables = variables.Substring(0, variables.Length - 1);
         *      }
         *      else
         *      {
         *          variables = FsmEditorStyles.tab2 + Strings.Label_None_In_Table;
         *      }
         *      GUILayout.Label(variables);
         *  }
         * }*/
        #endregion


        // Manual refresh if template has been edited

        if (fsmTemplate != null)
        {
            if (GUILayout.Button(FsmEditorContent.RefreshTemplateLabel))
            {
                RefreshTemplate();
            }
        }

        if (GUI.changed)
        {
            EditorUtility.SetDirty(fsmComponent);
            FsmEditor.RepaintAll();
        }
    }
Exemplo n.º 8
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);
            }
        }
    }
    public override void OnInspectorGUI()
    {
        // can happen when playmaker is updated...?

        if (fsmComponent == null)
        {
            return;
        }

        // Make sure common PlayMaker styles are initialized

        FsmEditorStyles.Init();

        // Begin GUI

        var fsm = fsmComponent.Fsm;

        fsm.Owner = fsmComponent; // since Owner is no longer serialized

        if (fsm.States.Length > 100)
        {
            EditorGUILayout.HelpBox("NOTE: Collapse this inspector for better editor performance with large FSMs.", MessageType.None);
        }

        // FSM Name

        EditorGUILayout.BeginHorizontal();

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

        if (GUILayout.Button(new GUIContent(Strings.Label_Edit, Strings.Tooltip_Edit_in_the_PlayMaker_Editor), GUILayout.MaxWidth(45)))
        {
            OpenInEditor(fsmComponent);
            GUIUtility.ExitGUI();
        }

        EditorGUILayout.EndHorizontal();

        // FSM Template

        EditorGUILayout.BeginHorizontal();

        var template = (FsmTemplate)
                       EditorGUILayout.ObjectField(new GUIContent(Strings.Label_Use_Template, Strings.Tooltip_Use_Template),
                                                   fsmComponent.FsmTemplate, typeof(FsmTemplate), false);

        if (template != fsmComponent.FsmTemplate)
        {
            fsmComponent.SetFsmTemplate(template);
        }

        if (GUILayout.Button(new GUIContent(Strings.Label_Browse, Strings.Tooltip_Browse_Templates), GUILayout.MaxWidth(45)))
        {
            DoSelectTemplateMenu();
        }

        EditorGUILayout.EndHorizontal();

        if (!Application.isPlaying && fsmComponent.FsmTemplate != null)
        {
            template = fsmComponent.FsmTemplate;
            fsm      = template.fsm;

            GUI.enabled = false;
        }

        // Description

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

        // Help Url

        EditorGUILayout.BeginHorizontal();

        fsm.DocUrl = FsmEditorGUILayout.TextFieldWithHint(fsm.DocUrl, Strings.Tooltip_Documentation_Url);

        var guiEnabled = GUI.enabled;

        GUI.enabled = !string.IsNullOrEmpty(fsm.DocUrl);

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

        EditorGUILayout.EndHorizontal();

        GUI.enabled = guiEnabled;

        // Basic Settings

        fsm.RestartOnEnable = GUILayout.Toggle(fsm.RestartOnEnable, new GUIContent(Strings.Label_Reset_On_Disable, Strings.Tooltip_Reset_On_Disable));
        fsm.ShowStateLabel  = GUILayout.Toggle(fsm.ShowStateLabel, new GUIContent(Strings.Label_Show_State_Label, Strings.Tooltip_Show_State_Label));
        fsm.EnableDebugFlow = GUILayout.Toggle(fsm.EnableDebugFlow, new GUIContent(Strings.FsmEditorSettings_Enable_DebugFlow, Strings.FsmEditorSettings_Enable_DebugFlow_Tooltip));

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

        GUI.enabled = true;

        // VARIABLES

        FsmEditorGUILayout.LightDivider();
        showControls = EditorGUILayout.Foldout(showControls, new GUIContent(Strings.Label_Controls, Strings.Tooltip_Controls), FsmEditorStyles.CategoryFoldout);

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

            BuildFsmVariableList();

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

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

        // EVENTS

        if (showControls)
        {
            foreach (var fsmEvent in fsm.ExposedEvents)
            {
                GUILayout.BeginHorizontal();
                EditorGUILayout.PrefixLabel(fsmEvent.Name);
                if (GUILayout.Button(fsmEvent.Name))
                {
                    fsm.Event(fsmEvent);
                    FsmEditor.RepaintAll();
                }
                GUILayout.EndHorizontal();
            }
        }

        //INFO

        EditorGUI.indentLevel = 0;

        FsmEditorGUILayout.LightDivider();
        showInfo = EditorGUILayout.Foldout(showInfo, Strings.Label_Info, FsmEditorStyles.CategoryFoldout);

        if (showInfo)
        {
            EditorGUI.indentLevel = 1;

            showStates = EditorGUILayout.Foldout(showStates, string.Format(Strings.Label_States_Count, fsm.States.Length));
            if (showStates)
            {
                string states = "";

                if (fsm.States.Length > 0)
                {
                    foreach (var state in fsm.States)
                    {
                        states += FsmEditorStyles.tab2 + state.Name + FsmEditorStyles.newline;
                    }
                    states = states.Substring(0, states.Length - 1);
                }
                else
                {
                    states = FsmEditorStyles.tab2 + Strings.Label_None_In_Table;
                }

                GUILayout.Label(states);
            }

            showEvents = EditorGUILayout.Foldout(showEvents, string.Format(Strings.Label_Events_Count, fsm.Events.Length));
            if (showEvents)
            {
                var events = "";

                if (fsm.Events.Length > 0)
                {
                    foreach (var fsmEvent in fsm.Events)
                    {
                        events += FsmEditorStyles.tab2 + fsmEvent.Name + FsmEditorStyles.newline;
                    }
                    events = events.Substring(0, events.Length - 1);
                }
                else
                {
                    events = FsmEditorStyles.tab2 + Strings.Label_None_In_Table;
                }

                GUILayout.Label(events);
            }

            showVariables = EditorGUILayout.Foldout(showVariables, string.Format(Strings.Label_Variables_Count, fsmVariables.Count));
            if (showVariables)
            {
                var variables = "";

                if (fsmVariables.Count > 0)
                {
                    foreach (var fsmVar in fsmVariables)
                    {
                        variables += FsmEditorStyles.tab2 + fsmVar.Name + FsmEditorStyles.newline;
                    }
                    variables = variables.Substring(0, variables.Length - 1);
                }
                else
                {
                    variables = FsmEditorStyles.tab2 + Strings.Label_None_In_Table;
                }

                GUILayout.Label(variables);
            }
        }
    }
 private void RepaintAll()
 {
     Repaint();
     FsmEditor.RepaintAll();
 }
Exemplo n.º 11
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);
            }
        }
    }