// ReSharper disable UnusedMember.Local

    /// <summary>
    /// Delay initialization until first OnGUI to avoid interfering with runtime system intialization.
    /// </summary>
    public override void Initialize()
    {
        instance = this;

        if (fsmEditor == null)
        {
            fsmEditor = new FsmEditor();
        }

        fsmEditor.InitWindow(this);
        fsmEditor.OnEnable();
    }
	// ReSharper disable UnusedMember.Local

	/// Called when the Fsm Editor window is created
	/// NOTE: happens on playmode change and recompile!
	private void OnEnable()
	{
		instance = this;

		if (fsmEditor == null)
		{
			fsmEditor = new FsmEditor();
		}
		
		fsmEditor.InitWindow(this);
		fsmEditor.OnEnable();
	}
 public static void OpenToolWindow()
 {
     FsmEditor.OpenToolWindow();
 }
Beispiel #4
0
 public static void OpenGlobalEventsWindow()
 {
     FsmEditor.OpenGlobalEventsWindow();
 }
Beispiel #5
0
 public static void OpenFsmSelectorWindow()
 {
     FsmEditor.OpenFsmSelectorWindow();
 }
Beispiel #6
0
 public static void OpenReportWindow()
 {
     FsmEditor.OpenReportWindow();
 }
Beispiel #7
0
    public override void OnSceneGUI()
    {
        // Live iTween path editing

        var iTween = target as iTweenMoveTo;

        if (iTween == null) // shouldn't happen!
        {
            return;
        }

        var fsm = target.Fsm;

        if (fsm == null) // shouldn't happen!
        {
            return;
        }

        if (iTween.transforms.Length >= 2)
        {
#if UNITY_4_6
            Undo.RecordObject(target.Owner, Strings.Command_Adjust_iTween_Path);
#else
            Undo.SetSnapshotTarget(target.Owner, Strings.Command_Adjust_iTween_Path);
#endif
            var tempVct3 = new Vector3[iTween.transforms.Length];
            for (var i = 0; i < iTween.transforms.Length; i++)
            {
                if (iTween.transforms[i].IsNone)
                {
                    tempVct3[i] = iTween.vectors[i].IsNone ? Vector3.zero : iTween.vectors[i].Value;
                }
                else
                {
                    if (iTween.transforms[i].Value == null)
                    {
                        tempVct3[i] = iTween.vectors[i].IsNone ? Vector3.zero : iTween.vectors[i].Value;
                    }
                    else
                    {
                        tempVct3[i] = iTween.transforms[i].Value.transform.position +
                                      (iTween.vectors[i].IsNone ? Vector3.zero : iTween.vectors[i].Value);
                    }
                }
                tempVct3[i] = Handles.PositionHandle(tempVct3[i], Quaternion.identity);
                if (iTween.transforms[i].IsNone)
                {
                    if (!iTween.vectors[i].IsNone)
                    {
                        iTween.vectors[i].Value = tempVct3[i];
                    }
                }
                else
                {
                    if (iTween.transforms[i].Value == null)
                    {
                        if (!iTween.vectors[i].IsNone)
                        {
                            iTween.vectors[i].Value = tempVct3[i];
                        }
                    }
                    else
                    {
                        if (!iTween.vectors[i].IsNone)
                        {
                            iTween.vectors[i] = tempVct3[i] - iTween.transforms[i].Value.transform.position;
                        }
                    }
                }
            }

            Handles.Label(tempVct3[0], string.Format(Strings.iTween_Path_Editing_Label_Begin, fsm.Name));
            Handles.Label(tempVct3[tempVct3.Length - 1], string.Format(Strings.iTween_Path_Editing_Label_End, fsm.Name));

            if (GUI.changed)
            {
                FsmEditor.EditingActions();
            }
        }
    }
 public void OnFocus()
 {
     // Repaint all to make sure highlight ids are refreshed
     FsmEditor.RepaintAll();
     Repaint();
 }
 public void OnSceneGUI()
 {
     if (fsmComponent.Fsm.EditState != null)
     {
         for (int k = 0; k < fsmComponent.Fsm.EditState.Actions.Length; k++)
         {
             if (fsmComponent.Fsm.EditState.Actions[k] is iTweenMoveTo)
             {
                 temp = (iTweenMoveTo)fsmComponent.Fsm.EditState.Actions[k];
                 if (temp.transforms.Length >= 2)
                 {
                     Undo.SetSnapshotTarget(fsmComponent.gameObject, "Adjust iTween Path");
                     tempVct3 = new Vector3[temp.transforms.Length];
                     for (int i = 0; i < temp.transforms.Length; i++)
                     {
                         if (temp.transforms[i].IsNone)
                         {
                             tempVct3[i] = temp.vectors[i].IsNone ? Vector3.zero : temp.vectors[i].Value;
                         }
                         else
                         {
                             if (temp.transforms[i].Value == null)
                             {
                                 tempVct3[i] = temp.vectors[i].IsNone ? Vector3.zero : temp.vectors[i].Value;
                             }
                             else
                             {
                                 tempVct3[i] = temp.transforms[i].Value.transform.position + (temp.vectors[i].IsNone ? Vector3.zero : temp.vectors[i].Value);
                             }
                         }
                         tempVct3[i] = Handles.PositionHandle(tempVct3[i], Quaternion.identity);
                         if (temp.transforms[i].IsNone)
                         {
                             if (!temp.vectors[i].IsNone)
                             {
                                 temp.vectors[i].Value = tempVct3[i];
                             }
                         }
                         else
                         {
                             if (temp.transforms[i].Value == null)
                             {
                                 if (!temp.vectors[i].IsNone)
                                 {
                                     temp.vectors[i].Value = tempVct3[i];
                                 }
                             }
                             else
                             {
                                 if (!temp.vectors[i].IsNone)
                                 {
                                     temp.vectors[i] = tempVct3[i] - temp.transforms[i].Value.transform.position;
                                 }
                             }
                         }
                     }
                     Handles.Label(tempVct3[0], "'" + fsmComponent.name + "' Begin");
                     Handles.Label(tempVct3[tempVct3.Length - 1], "'" + fsmComponent.name + "' End");
                     if (GUI.changed)
                     {
                         FsmEditor.EditingActions();
                     }
                 }
             }
         }
     }
 }
Beispiel #10
0
        /// <summary>
        /// Open the Fsm Editor and select an Fsm Component
        /// </summary>
        public static void OpenWindow(FsmTemplate fsmTemplate)
        {
            OpenWindow();

            FsmEditor.SelectFsm(fsmTemplate.fsm);
        }
Beispiel #11
0
        /// <summary>
        /// Open the Fsm Editor and select an Fsm Component
        /// </summary>
        public static void OpenWindow(PlayMakerFSM fsmComponent)
        {
            OpenWindow();

            FsmEditor.SelectFsm(fsmComponent.Fsm);
        }
        public override void DoGUI()
        {
            fsmEditor.OnGUI();

            switch (eventType)
            {
            case EventType.ValidateCommand:
                switch (Event.current.commandName)
                {
                case "Cut":
                case "Copy":
                case "Paste":
                case "SelectAll":
                    Event.current.Use();
                    break;
                }

                break;

            case EventType.ExecuteCommand:
                switch (Event.current.commandName)
                {
                // NOTE: OSX 2018.3 needs Event.current.Use();
                // otherwise e.g., it pastes twice #1814

                case "Cut":
                    FsmEditor.Cut();
                    Event.current.Use();
                    break;

                case "Copy":
                    FsmEditor.Copy();
                    Event.current.Use();
                    break;

                case "Paste":
                    FsmEditor.Paste();
                    Event.current.Use();
                    break;

                case "SelectAll":
                    FsmEditor.SelectAll();
                    Event.current.Use();
                    break;

                case "OpenWelcomeWindow":
                    OpenWindow <PlayMakerWelcomeWindow>();
                    break;

                case "OpenToolWindow":
                    OpenWindow <ContextToolWindow>();
                    break;

                case "OpenFsmSelectorWindow":
                    OpenWindow <FsmSelectorWindow>();
                    break;

                case "OpenFsmTemplateWindow":
                    OpenWindow <FsmTemplateWindow>();
                    break;

                case "OpenStateSelectorWindow":
                    OpenWindow <FsmStateWindow>();
                    break;

                case "OpenActionWindow":
                    OpenWindow <FsmActionWindow>();
                    break;

                case "OpenGlobalEventsWindow":
                    OpenWindow <FsmEventsWindow>();
                    break;

                case "OpenGlobalVariablesWindow":
                    OpenWindow <FsmGlobalsWindow>();
                    break;

                case "OpenErrorWindow":
                    OpenWindow <FsmErrorWindow>();
                    break;

                case "OpenTimelineWindow":
                    OpenWindow <FsmTimelineWindow>();
                    break;

                case "OpenFsmLogWindow":
                    OpenWindow <FsmLogWindow>();
                    break;

                case "OpenAboutWindow":
                    OpenWindow <AboutWindow>();
                    break;

                case "OpenReportWindow":
                    OpenWindow <ReportWindow>();
                    break;

                case "AddFsmComponent":
                    PlayMakerMainMenu.AddFsmToSelected();
                    Event.current.Use();
                    break;

                case "ChangeLanguage":
                    ResetWindowTitles();
                    Event.current.Use();
                    break;

                case "OpenFsmControlsWindow":
                    OpenWindow <FsmControlsWindow>();
                    break;
                }

                GUIUtility.ExitGUI();
                break;
            }
        }
    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);
            }
        }
    }
Beispiel #15
0
    public void OnGUI()
    {
        fsmEditor.OnGUI();

/*		BeginWindows();
 *
 *              fsmEditor.DoPopupWindows();
 *
 *              EndWindows();*/

        if (Event.current.type == EventType.ValidateCommand)
        {
            //Debug.Log(Event.current.commandName);

            switch (Event.current.commandName)
            {
            case "UndoRedoPerformed":
                FsmEditor.UndoRedoPerformed();
                break;

            case "Copy":
                EditorCommands.CopyStateSelection();
                break;

            case "Paste":
                EditorCommands.PasteStates();
                break;
            }
        }

        if (Event.current.type == EventType.ExecuteCommand)
        {
            //Debug.Log(Event.current.commandName);

            switch (Event.current.commandName)
            {
            case "OpenToolWindow":
                toolWindow = GetWindow <ContextToolWindow>();
                break;

            case "OpenFsmSelectorWindow":
                fsmSelectorWindow = GetWindow <FsmSelectorWindow>();
                fsmSelectorWindow.ShowUtility();
                break;

            case "OpenFsmTemplateWindow":
                fsmTemplateWindow = GetWindow <FsmTemplateWindow>();
                break;

            case "OpenStateSelectorWindow":
                stateSelectorWindow = GetWindow <FsmStateWindow>();
                break;

            case "OpenActionWindow":
                actionWindow = GetWindow <FsmActionWindow>();
                break;

            case "OpenErrorWindow":
                errorWindow = GetWindow <FsmErrorWindow>();
                break;

            case "OpenFsmLogWindow":
                logWindow = GetWindow <FsmLogWindow>();
                break;

            case "OpenAboutWindow":
                aboutWindow = GetWindow <AboutWindow>();
                break;

            case "AddFsmComponent":
                AddFsmToSelected();
                break;

            case "RepaintAll":
                RepaintAllWindows();
                break;
            }

            GUIUtility.ExitGUI();
        }
    }
Beispiel #16
0
    /// <summary>
    /// Do the GUI
    /// </summary>
    void OnGUI()
    {
        fsmEditor.OnGUI();

/*		BeginWindows();
 *
 *              fsmEditor.DoPopupWindows();
 *
 *              EndWindows();*/

        if (Event.current.type == EventType.ValidateCommand)
        {
            //Debug.Log(Event.current.commandName);

            switch (Event.current.commandName)
            {
            case "UndoRedoPerformed":
                Event.current.Use();
                break;

            case "Copy":
                Event.current.Use();
                break;

            case "Paste":
                Event.current.Use();
                break;

            case "SelectAll":
                Event.current.Use();
                break;
            }
        }

        if (Event.current.type == EventType.ExecuteCommand)
        {
            //Debug.Log(Event.current.commandName);

            switch (Event.current.commandName)
            {
            case "UndoRedoPerformed":
                FsmEditor.UndoRedoPerformed();
                break;

            case "Copy":
                FsmEditor.Copy();
                break;

            case "Paste":
                FsmEditor.Paste();
                break;

            case "SelectAll":
                FsmEditor.SelectAll();
                break;

            case "OpenWelcomeWindow":
                GetWindow <PlayMakerWelcomeWindow>();
                break;

            case "OpenToolWindow":
                toolWindow = GetWindow <ContextToolWindow>();
                break;

            case "OpenFsmSelectorWindow":
                fsmSelectorWindow = GetWindow <FsmSelectorWindow>();
                fsmSelectorWindow.ShowUtility();
                break;

            case "OpenFsmTemplateWindow":
                fsmTemplateWindow = GetWindow <FsmTemplateWindow>();
                break;

            case "OpenStateSelectorWindow":
                stateSelectorWindow = GetWindow <FsmStateWindow>();
                break;

            case "OpenActionWindow":
                actionWindow = GetWindow <FsmActionWindow>();
                break;

            case "OpenGlobalEventsWindow":
                globalEventsWindow = GetWindow <FsmEventsWindow>();
                break;

            case "OpenGlobalVariablesWindow":
                globalVariablesWindow = GetWindow <FsmGlobalsWindow>();
                break;

            case "OpenErrorWindow":
                errorWindow = GetWindow <FsmErrorWindow>();
                break;

            case "OpenFsmLogWindow":
                logWindow = GetWindow <FsmLogWindow>();
                break;

            case "OpenAboutWindow":
                aboutWindow = GetWindow <AboutWindow>();
                break;

            case "OpenReportWindow":
                reportWindow = GetWindow <ReportWindow>();
                break;

            case "AddFsmComponent":
                PlayMakerMainMenu.AddFsmToSelected();
                break;

            case "RepaintAll":
                RepaintAllWindows();
                break;
            }

            GUIUtility.ExitGUI();
        }
    }
Beispiel #17
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();
        }
    }
Beispiel #18
0
        public override void DoGUI()
        {
            fsmEditor.OnGUI();

            /* Debug Repaint events
             * if (Event.current.type == EventType.repaint)
             * {
             *  Debug.Log("Repaint");
             * }*/

            if (Event.current.type == EventType.ValidateCommand)
            {
                switch (Event.current.commandName)
                {
                case "UndoRedoPerformed":
                case "Cut":
                case "Copy":
                case "Paste":
                case "SelectAll":
                    Event.current.Use();
                    break;
                }
            }

            if (Event.current.type == EventType.ExecuteCommand)
            {
                switch (Event.current.commandName)
                {
                /* replaced with Undo.undoRedoPerformed callback added in Unity 4.3
                 * case "UndoRedoPerformed":
                 *  FsmEditor.UndoRedoPerformed();
                 *  break;
                 */

                case "Cut":
                    FsmEditor.Cut();
                    break;

                case "Copy":
                    FsmEditor.Copy();
                    break;

                case "Paste":
                    FsmEditor.Paste();
                    break;

                case "SelectAll":
                    FsmEditor.SelectAll();
                    break;

                case "OpenWelcomeWindow":
                    GetWindow <PlayMakerWelcomeWindow>();
                    break;

                case "OpenToolWindow":
                    GetWindow <ContextToolWindow>();
                    break;

                case "OpenFsmSelectorWindow":
                    GetWindow <FsmSelectorWindow>();
                    break;

                case "OpenFsmTemplateWindow":
                    GetWindow <FsmTemplateWindow>();
                    break;

                case "OpenStateSelectorWindow":
                    GetWindow <FsmStateWindow>();
                    break;

                case "OpenActionWindow":
                    GetWindow <FsmActionWindow>();
                    break;

                case "OpenGlobalEventsWindow":
                    GetWindow <FsmEventsWindow>();
                    break;

                case "OpenGlobalVariablesWindow":
                    GetWindow <FsmGlobalsWindow>();
                    break;

                case "OpenErrorWindow":
                    GetWindow <FsmErrorWindow>();
                    break;

                case "OpenTimelineWindow":
                    GetWindow <FsmTimelineWindow>();
                    break;

                case "OpenFsmLogWindow":
                    GetWindow <FsmLogWindow>();
                    break;

                case "OpenAboutWindow":
                    GetWindow <AboutWindow>();
                    break;

                case "OpenReportWindow":
                    GetWindow <ReportWindow>();
                    break;

                case "AddFsmComponent":
                    PlayMakerMainMenu.AddFsmToSelected();
                    break;

                case "RepaintAll":
                    RepaintAllWindows();
                    break;

                case "ChangeLanguage":
                    ResetWindowTitles();
                    break;
                }

                GUIUtility.ExitGUI();
            }
        }
    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);
            }
        }
    }
        public override void OnSceneGUI()
        {
            var lookAtAction = (HutongGames.PlayMaker.Actions.LookAt)target;

            if (lookAtAction.UpdateLookAtPosition())
            {
                var go          = target.Fsm.GetOwnerDefaultTarget(lookAtAction.gameObject);
                var goTransform = go.transform;
                var goPosition  = goTransform.position;

                var lookAtPosition = lookAtAction.GetLookAtPosition();
                var lookAtVector   = lookAtPosition - goPosition;
                var lookAtRotation = Quaternion.LookRotation(lookAtVector);
                var lookAtAngle    = Vector3.Angle(goTransform.forward, lookAtVector);
                var lookAtNormal   = Vector3.Cross(goTransform.forward, lookAtVector);

                var handleSize = HandleUtility.GetHandleSize(goPosition);
                var arrowSize  = handleSize * 0.2f;
                var distance   = (lookAtPosition - goPosition).magnitude;

                var goTarget = lookAtAction.targetObject.Value;

                // Position handles

                if (!lookAtAction.targetPosition.IsNone)
                {
                    if (goTarget != null)
                    {
                        // Edit local offset from target object

                        var goTargetTransform = goTarget.transform;
                        var worldTargetPos    = goTargetTransform.TransformPoint(lookAtAction.targetPosition.Value);

                        lookAtAction.targetPosition.Value = goTargetTransform.InverseTransformPoint(Handles.PositionHandle(worldTargetPos, goTarget.transform.rotation));
                        Handles.color = new Color(1, 1, 1, 0.2f);
                        Handles.DrawLine(goTargetTransform.position, lookAtAction.GetLookAtPositionWithVertical());
                    }
                    else
                    {
                        // Edit world position

                        lookAtAction.targetPosition.Value = Handles.PositionHandle(lookAtAction.targetPosition.Value, Quaternion.identity);
                    }
                }

                // Forward vector

                Handles.color = Color.blue;
                Handles.DrawLine(goPosition, goPosition + goTransform.forward * handleSize);

                // Lookat vector

                Handles.DrawLine(goPosition, lookAtPosition);
#if UNITY_5_5_OR_NEWER
                Handles.ConeHandleCap(0, goPosition + lookAtVector.normalized * (distance - arrowSize * 0.7f), lookAtRotation, arrowSize, EventType.Repaint); // fudge factor to position cap correctly
#else
                Handles.ConeCap(0, goPosition + lookAtVector.normalized * (distance - arrowSize * 0.7f), lookAtRotation, arrowSize);                          // fudge factor to position cap correctly
#endif
                // Arc between vectors

                Handles.color = new Color(1, 1, 1, 0.2f);
                Handles.DrawSolidArc(goPosition, lookAtNormal, goTransform.forward, lookAtAngle, handleSize);

                // Show vertical offset

                if (lookAtAction.keepVertical.Value)
                {
                    Handles.DrawLine(lookAtPosition, lookAtAction.GetLookAtPositionWithVertical());
                }

                if (GUI.changed)
                {
                    FsmEditor.EditingActions();
                    FsmEditor.Repaint(true);
                }
            }
        }
Beispiel #21
0
        public override void OnSceneGUI()
        {
            var action = (HutongGames.PlayMaker.Actions.SetVelocity2d)target;
            var go     = action.Fsm.GetOwnerDefaultTarget(action.gameObject);

            if (go == null)
            {
                return;
            }

            var transform = go.transform;
            var space     = action.space;

            var velocity = action.vector.IsNone ? Vector2.zero : action.vector.Value;

            if (!action.x.IsNone)
            {
                velocity.x = action.x.Value;
            }
            if (!action.y.IsNone)
            {
                velocity.y = action.y.Value;
            }

            if (space == Space.Self)
            {
                velocity = transform.TransformDirection(velocity);
            }

            var constrainX = action.vector.IsNone && action.x.IsNone;
            var constrainY = action.vector.IsNone && action.y.IsNone;

            var origin = transform.position;

            toPos.x = origin.x + velocity.x;
            toPos.y = origin.y + velocity.y;
            toPos.z = origin.z;

            ActionHelpers.DrawArrow(origin, toPos, PlayMakerPrefs.ArrowColor);

            //if (EditorApplication.isPlayingOrWillChangePlaymode) return;

            // editor

            var newPosition = Handles.DoPositionHandle(toPos, space == Space.Self ? go.transform.rotation : Quaternion.identity);

            newPosition.z = origin.z;
            newPosition  -= origin;

            if (space == Space.Self)
            {
                newPosition = go.transform.InverseTransformDirection(newPosition);
            }

            if (constrainX)
            {
                newPosition.x = origin.x;
            }
            if (constrainY)
            {
                newPosition.y = origin.y;
            }

            if (Math.Abs(newPosition.x) < 0.0001f)
            {
                newPosition.x = 0;
            }
            if (Math.Abs(newPosition.y) < 0.0001f)
            {
                newPosition.y = 0;
            }

            action.vector.Value = new Vector2(newPosition.x, newPosition.y);
            action.x.Value      = newPosition.x;
            action.y.Value      = newPosition.y;

            //ActionHelpers.DrawTexture(newPosition, FsmEditorStyles.RightArrow, 45, Vector2.zero);

            if (GUI.changed)
            {
                FsmEditor.EditingActions();
                //Debug.Log("Save Actions");
                //FsmEditor.SaveActions();
            }
        }
    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;
        }

        // Resave warning

        /*
         * if (fsm.needsResave)
         * {
         *  EditorGUI.BeginDisabledGroup(false);
         *  EditorGUILayout.HelpBox("NOTE: Action data has changed since FSM was saved. Please resave FSM to update actions.", MessageType.Warning);
         *  EditorGUI.EndDisabledGroup();
         * }*/

        // 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, restartOnEnableLabel);
        fsm.ShowStateLabel  = GUILayout.Toggle(fsm.ShowStateLabel, showStateLabelLabel);
        fsm.EnableDebugFlow = GUILayout.Toggle(fsm.EnableDebugFlow, enableDebugFlowLabel);
        //fsm.QuickLoad = GUILayout.Toggle(fsm.QuickLoad, quickLoadLabel);

        // 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();
            }
        }
    }
Beispiel #23
0
 public static void OpenFsmLogWindow()
 {
     FsmEditor.OpenFsmLogWindow();
 }
    public static UnityEngine.Object[] GetSceneCustomActionDependencies()
    {
        UnityEngine.Object[] list = new UnityEngine.Object[0];

        FsmEditor.RebuildFsmList();

        List <PlayMakerFSM> fsms = FsmEditor.FsmComponentList;

//		List<System.Type> PlayMakerActions = FsmEditorUtility.Actionslist;

        foreach (PlayMakerFSM fsm in fsms)
        {
            //Debug.Log(FsmEditorUtility.GetFullFsmLabel(fsm));

            //if (fsm.FsmStates != null) fsm.FsmStates.Initialize();

            for (int s = 0; s < fsm.FsmStates.Length; ++s)
            {
                fsm.FsmStates[s].LoadActions();

                Debug.Log(fsm.FsmStates[s].Name + " is loaded:" + fsm.FsmStates[s].ActionsLoaded);

                // Show SendEvent and SendMessage as we find them
                foreach (FsmStateAction action in fsm.FsmStates[s].Actions)
                {
                                                #if PLAYMAKER_1_8_OR_NEWER
                    UnityEngine.Object _asset = ActionScripts.GetAsset(action);
                                                #else
                    UnityEngine.Object _asset = FsmEditorUtility.GetActionScriptAsset(action);
                                                #endif

                    string _name = action.Name;
                    if (String.IsNullOrEmpty(_name))
                    {
                        if (_asset != null)
                        {
                            _name = _asset.name;
                        }
                        else
                        {
                                                                #if PLAYMAKER_1_8_OR_NEWER
                            _name = Labels.GetActionLabel(action) + "[WARNING: FILE NOT FOUND]";
                                                                #else
                            _name = FsmEditorUtility.GetActionLabel(action) + "[WARNING: FILE NOT FOUND]";
                                                                #endif
                        }
                    }

                    if (Enum.IsDefined(typeof(WikiPages), _name))
                    {
                        //	Debug.Log(_name+" : official action");
                    }
                    else
                    {
                        //	Debug.Log(_name+" : custom action");

                        if (_asset != null)
                        {
                            ArrayUtility.Add <UnityEngine.Object>(ref list, _asset);
                        }
                    }
                }
            }
        }

        return(list);
    }    // GetSceneCustomActionDependencies
Beispiel #25
0
 public static void OpenActionWindow()
 {
     FsmEditor.OpenActionWindow();
 }
Beispiel #26
0
 public static void ToggleFsmEditorLock()
 {
     FsmEditor.ToggleLockSelection();
 }
Beispiel #27
0
 public static void OpenFsmTemplateWindow()
 {
     FsmEditor.OpenFsmTemplateWindow();
 }
Beispiel #28
0
        public override void OnSceneGUI()
        {
            var moveTowardsAction = (MoveTowardsAdvanced)target;

            if (moveTowardsAction.UpdateTargetPos())
            {
                var go          = target.Fsm.GetOwnerDefaultTarget(moveTowardsAction.gameObject);
                var goTransform = go.transform;
                var goPosition  = goTransform.position;

                var lookAtPosition = moveTowardsAction.GetTargetPos();
                var lookAtVector   = lookAtPosition - goPosition;
                if (lookAtVector == Vector3.zero)
                {
                    return;
                }
                var lookAtRotation = Quaternion.LookRotation(lookAtVector);

                var handleSize = HandleUtility.GetHandleSize(goPosition);
                var arrowSize  = handleSize * 0.2f;
                var distance   = (lookAtPosition - goPosition).magnitude;

                var goTarget = moveTowardsAction.targetObject.Value;

                // Position handles

                if (!moveTowardsAction.targetPosition.IsNone)
                {
                    if (goTarget != null)
                    {
                        // Edit local offset from target object

                        var goTargetTransform = goTarget.transform;
                        var worldTargetPos    = goTargetTransform.TransformPoint(moveTowardsAction.targetPosition.Value);

                        moveTowardsAction.targetPosition.Value = goTargetTransform.InverseTransformPoint(Handles.PositionHandle(worldTargetPos, goTarget.transform.rotation));
                        Handles.color = new Color(1, 1, 1, 0.2f);
                        Handles.DrawLine(goTargetTransform.position, moveTowardsAction.GetTargetPosWithVertical());
                    }
                    else
                    {
                        // Edit world position

                        moveTowardsAction.targetPosition.Value = Handles.PositionHandle(moveTowardsAction.targetPosition.Value, Quaternion.identity);
                    }
                }

                // Target vector

                Handles.DrawLine(goPosition, lookAtPosition);

#if UNITY_2019_1_OR_NEWER
                Handles.ArrowHandleCap(0,
                                       goPosition + lookAtVector.normalized * (distance - arrowSize * 0.7f),
                                       lookAtRotation,
                                       arrowSize, EventType.Repaint);
#else
                Handles.ConeCap(0, goPosition + lookAtVector.normalized * (distance - arrowSize * 0.7f), lookAtRotation, arrowSize);                 // fudge factor to position cap correctly
#endif

                // Show vertical offset

                if (moveTowardsAction.ignoreVertical.Value)
                {
                    Handles.DrawLine(lookAtPosition, moveTowardsAction.GetTargetPosWithVertical());
                }

                if (GUI.changed)
                {
                    FsmEditor.EditingActions();
                    FsmEditor.Repaint(true);
                }
            }
        }
Beispiel #29
0
 public static void OpenGlobalVariablesWindow()
 {
     FsmEditor.OpenGlobalVariablesWindow();
 }
Beispiel #30
0
 /// <summary>
 /// Actions can use OnSceneGUI to display interactive gizmos
 /// </summary>
 public void OnSceneGUI()
 {
     FsmEditor.OnSceneGUI();
 }
 public static void OpenTimelineWindow()
 {
     FsmEditor.OpenTimelineWindow();
 }
Beispiel #32
0
        public override bool OnGUI()
        {
            EditorGUI.BeginChangeCheck();

            EditField("gameObject");

            EditorGUI.BeginChangeCheck();
            EditField("fromOptions");
            if (EditorGUI.EndChangeCheck())
            {
                tweenAction.fromTarget = null;
                ResetSharedParameter(ref tweenAction.fromScale);
                FsmEditor.SaveActions();
            }

            switch (tweenAction.fromOptions)
            {
            case ScaleOptions.CurrentScale:
                break;

            case ScaleOptions.LocalScale:
                EditField("fromScale", "Local Scale");
                break;

            case ScaleOptions.MultiplyScale:
                EditField("fromScale", "Multiply Scale");
                break;

            case ScaleOptions.AddToScale:
                EditField("fromScale", "Add To Scale");
                break;

            case ScaleOptions.MatchGameObject:
                EditField("fromTarget", "GameObject");
                EditField("fromScale", "Multiplier");
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            EditorGUI.BeginChangeCheck();
            EditField("toOptions");
            if (EditorGUI.EndChangeCheck())
            {
                tweenAction.toTarget = null;
                ResetSharedParameter(ref tweenAction.toScale);
                FsmEditor.SaveActions();
            }

            switch (tweenAction.toOptions)
            {
            case ScaleOptions.CurrentScale:
                break;

            case ScaleOptions.LocalScale:
                EditField("toScale", "Local Scale");
                break;

            case ScaleOptions.MultiplyScale:
                EditField("toScale", "Multiply Scale");
                break;

            case ScaleOptions.AddToScale:
                EditField("toScale", "Add To Scale");
                break;

            case ScaleOptions.MatchGameObject:
                EditField("toTarget", "GameObject");
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            DoEasingUI();

            return(EditorGUI.EndChangeCheck());
        }