コード例 #1
0
 private void ExecuteAutomations()
 {
     executionRoutine = EditorCoroutine.Start(ExecuteAutomationsAsync());
 }
コード例 #2
0
        protected override void OnGUI()
        {
            EditorGUILayout.BeginHorizontal(EditorStyles.toolbar);
            EditorGUI.BeginDisabledGroup(Globals.IsExecuting);
            if (GUILayout.Button("File", EditorStyles.toolbarDropDown))
            {
                var gm = GenericMenuBuilder.CreateMenu();
                gm.AddItem("New Automatron", false, () => {
                    AddWindow(new AutomatronMenu(1));
                    Remove();
                });
                gm.AddItem("Open Automatron", false, () => {
                    AddWindow(new AutomatronMenu());
                    Remove();
                });
                gm.AddSeparator();
                gm.AddItem("Save Automatron", false, () => {
                    AutomatronSerializer.Save(this);
                    ShowNotification("Automatron saved");
                });
                gm.AddItem("Save Automatron As...", false, () => {
                    ShowPopup(new InputBox(
                                  "Save Automatron As...",
                                  "Please insert a new name for the Automatron",
                                  (EDialogResult result, string input) => {
                        if (result == EDialogResult.OK && !string.IsNullOrEmpty(input))
                        {
                            Name = input;
                            Save();
                            ShowNotification(string.Format("Automatron saved as '{0}'", input));
                        }
                    }));
                });
                gm.AddSeparator();
                gm.AddItem("Create.../Automation", false, () => {
                    ShowPopup(new InputBox(
                                  "Create Automation",
                                  "Please insert the name for your Automation",
                                  (EDialogResult result, string input) => {
                        if (result == EDialogResult.OK && !string.IsNullOrEmpty(input))
                        {
                            templator.CreateAutomation(input);
                        }
                    }));
                });
                gm.AddItem("Create.../Conditional Automation", false, () => {
                    ShowPopup(new InputBox(
                                  "Create Conditional Automation",
                                  "Please insert the name for your Automation",
                                  (EDialogResult result, string input) => {
                        if (result == EDialogResult.OK && !string.IsNullOrEmpty(input))
                        {
                            templator.CreateConditionalAutomation(input);
                        }
                    }));
                });
                gm.AddItem("Create.../Loopable Automation", false, () => {
                    ShowPopup(new InputBox(
                                  "Create Loopable Automation",
                                  "Please insert the name for your Automation",
                                  (EDialogResult result, string input) => {
                        if (result == EDialogResult.OK && !string.IsNullOrEmpty(input))
                        {
                            templator.CreateLoopableAutomation(input);
                        }
                    }));
                });
                gm.AddSeparator("Create.../");
                gm.AddItem("Create.../Generator", false, () => {
                    Generation.Generator.CreateMe();
                });
                gm.AddSeparator();
                gm.AddItem("Exit", false, () => {
                    Editor.Close();
                });
                gm.ShowAsContext();
            }

            if (GUILayout.Button("Automations", EditorStyles.toolbarDropDown))
            {
                ShowAutomationPopup();
            }
            EditorGUI.EndDisabledGroup();

            // Spacer
            GUILayout.Button("", EditorStyles.toolbarButton);

            if (Globals.IsExecuting)
            {
                if (GUILayout.Button(stopContent, EditorStyles.toolbarButton))
                {
                    executionRoutine.Stop();
                    executionRoutine    = null;
                    Globals.IsExecuting = false;
                }
            }
            else
            {
                if (GUILayout.Button(executeContent, EditorStyles.toolbarButton))
                {
                    ExecuteAutomations();
                }
            }

            EditorGUI.BeginDisabledGroup(Globals.IsExecuting);
            if (GUILayout.Button(resetContent, EditorStyles.toolbarButton))
            {
                var list = GetControls <Automation>();
                foreach (var item in list)
                {
                    item.Reset();
                    item.ResetFields();
                }
            }

            if (GUILayout.Button(trashContent, EditorStyles.toolbarButton))
            {
                ShowPopup(new MessageBox("Caution!", "You're about to empty this Automatron...\nAre you sure you want to do this?", EMessageBoxButtons.YesNo, ( EDialogResult result ) => {
                    if (result == EDialogResult.Yes)
                    {
                        var controls = GetControls <ExtendedControl>();
                        for (int i = controls.Count - 1; i >= 0; i--)
                        {
                            var item = controls[i];
                            if (item != entryPoint)
                            {
                                item.Remove();
                            }
                        }
                        entryPoint.Reset();
                        Globals.Camera      = new Vector2();
                        entryPoint.Position = WindowRect.center;
                    }
                }));
            }
            EditorGUI.EndDisabledGroup();

            GUILayout.FlexibleSpace();

            if (GUILayout.Button("Help", EditorStyles.toolbarButton))
            {
                Application.OpenURL("http://tnrd.net/automatron");
            }

            EditorGUILayout.EndHorizontal();

            if (Input.KeyReleased(KeyCode.F1))
            {
                Application.OpenURL("http://tnrd.net/automatron");
            }

            if (Event.current.keyCode == KeyCode.Space)
            {
                if (Event.current.type == EventType.KeyDown)
                {
                    spacePan = true;
                    Event.current.Use();
                }
                else if (Event.current.type == EventType.KeyUp)
                {
                    spacePan = false;
                    Event.current.Use();
                }
            }

            if (Input.ButtonPressed(EMouseButton.Middle))
            {
                mousePan = true;
            }
            else if (Input.ButtonDown(EMouseButton.Middle))
            {
                Globals.Camera += Input.DragDelta;
            }
            else if (Input.ButtonReleased(EMouseButton.Middle) || Input.ButtonUp(EMouseButton.Middle))
            {
                mousePan = false;
            }

            if (spacePan || mousePan)
            {
                EditorGUIUtility.AddCursorRect(new Rect(0, 0, Size.x, Size.y), MouseCursor.Pan);

                if (!mousePan && (Input.ButtonDown(EMouseButton.Left) || Input.ButtonDown(EMouseButton.Right)))
                {
                    Globals.Camera += Input.DragDelta;
                }
            }
            else if (Input.ButtonReleased(EMouseButton.Right))
            {
                ShowAutomationPopup();
                Input.Use();
            }

            if (AutomatronSettings.AutoSave)
            {
                if (Input.ButtonReleased(EMouseButton.Left))
                {
                    Save();
                    Input.Use();
                }
            }

            Repaint();
        }