コード例 #1
0
        private void ListGUI()
        {
            var area = new Rect(50 + (Size.x * anim), 125, Size.x - 100, Size.y - 200);

            GUILayout.BeginArea(area);

            GUILayout.BeginArea(new Rect(area.width - 125, 35, 125, 16));
            ExtendedGUI.HorizontalLine();
            GUILayout.EndArea();

            var cbr     = new Rect(area.width - 115, 7.5f, 50, 20);
            var isHover = cbr.Contains(Input.MousePosition);

            if (Event.current.type == EventType.Repaint)
            {
                buttonStyle.Draw(cbr, "Create", isHover, isHover, false, false);
            }
            if (isHover)
            {
                EditorGUIUtility.AddCursorRect(new Rect(0, 0, Size.x, Size.y), MouseCursor.Link);
                if (Input.ButtonReleased(EMouseButton.Left))
                {
                    target = 1;
                }
            }

            var obr = new Rect(area.width - 60, 7.5f, 50, 20);

            isHover = obr.Contains(Input.MousePosition);
            if (Event.current.type == EventType.Repaint)
            {
                buttonStyle.Draw(obr, "Open", isHover, isHover, false, false);
            }
            if (isHover)
            {
                EditorGUIUtility.AddCursorRect(new Rect(0, 0, Size.x, Size.y), MouseCursor.Link);
                if (Input.ButtonReleased(EMouseButton.Left))
                {
                    var p = EditorUtility.OpenFilePanel("Select Automation", "", "acfg");
                    if (!string.IsNullOrEmpty(p))
                    {
                        var a = AutomatronSerializer.Load(p);
                        if (a != null)
                        {
                            loadAutomatron = true;
                            automatron     = p;
                        }
                    }
                }
            }

            GUILayout.Space(50);

            if (configs.Count == 0)
            {
                EditorGUILayout.LabelField("It seems pretty empty over here", noneStyle, GUILayout.ExpandHeight(true));
            }
            else
            {
                scroll = EditorGUILayout.BeginScrollView(scroll);

                for (int i = 0; i < configs.Count; i++)
                {
                    var p = configs[i];
                    var l = Path.GetFileNameWithoutExtension(p);
                    var s = p.Replace("\\", "/");

                    GUILayout.Space(5);
                    var r = EditorGUILayout.GetControlRect(false, 48);
                    isHover = r.Contains(Input.MousePosition);
                    if (Event.current.type == EventType.Repaint)
                    {
                        labelStyle.Draw(r, l, isHover, isHover, false, false);
                    }
                    EditorGUI.LabelField(new Rect(r.x + 12, r.y + 24, r.width, 20), s, subLabelStyle);

                    if (isHover)
                    {
                        EditorGUIUtility.AddCursorRect(new Rect(0, 0, Size.x, Size.y), MouseCursor.Link);
                        if (Input.ButtonReleased(EMouseButton.Left))
                        {
                            automatron = p;

                            if (File.Exists(p))
                            {
                                loadAutomatron = true;
                            }
                            else
                            {
                                if (EditorUtility.DisplayDialog("Automatron", string.Format("\"{0}\" could not be opened. Do you want to remove the reference from the list?", l), "Yes", "No"))
                                {
                                    deleteAutomatron = true;
                                }
                            }
                        }
                    }
                }

                EditorGUILayout.EndScrollView();
            }

            GUILayout.EndArea();
        }
コード例 #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();
        }
コード例 #3
0
 public void Save()
 {
     AutomatronSerializer.Save(this);
 }
コード例 #4
0
        public void LoadAutomatron(string path)
        {
            var a = AutomatronSerializer.Load(path);

            if (a == null)
            {
                return;
            }

            Globals.Camera = a.Camera;
            Name           = a.Name;
            Path           = a.Path;

            foreach (var item in a.Automations)
            {
                var type = Globals.Types.Where(t => t.FullName == item.Type).FirstOrDefault();
                if (type == null)
                {
                    type = Type.GetType(item.Type);
                }
                if (type == null)
                {
                    continue;
                }

                var pos = item.Position;

                var instance = (Automation)Activator.CreateInstance(type);
                instance.Position = pos;

                AddControl(instance);
                instance.ID = item.ID;
                instance.LoadFields();

                foreach (var f in item.Fields)
                {
                    var fid = instance.GetField(f.ID);
                    if (fid != null)
                    {
                        fid.SetValue(f.Value);
                    }
                }

                if (item.ID == a.EntryID)
                {
                    entryPoint = (InternalQueueStart)instance;
                    EntryId    = entryPoint.ID;
                }
            }

            var automations = GetControls <Automation>();

            foreach (var item in a.Lines)
            {
                if (item.LineType == ELineType.FieldLine)
                {
                    var left  = automations.Where(auto => auto.HasField(item.IdLeft)).FirstOrDefault();
                    var right = automations.Where(auto => auto.HasField(item.IdRight)).FirstOrDefault();

                    if (left == null || right == null)
                    {
                        continue;
                    }

                    var line = new FieldLine(left.GetField(item.IdLeft), right.GetField(item.IdRight));
                    AddControl(line);
                }
                else
                {
                    var left  = automations.Where(auto => auto.ID == item.IdLeft).FirstOrDefault();
                    var right = automations.Where(auto => auto.ID == item.IdRight).FirstOrDefault();

                    if (left == null || right == null)
                    {
                        continue;
                    }

                    BezierLine line = null;

                    switch (item.LineType)
                    {
                    case ELineType.AutomationLine:
                        line = new AutomationLine(left, right);
                        break;

                    case ELineType.ConditionalLine:
                        line = new ConditionalLine((ConditionalAutomation)left, right);
                        break;

                    case ELineType.LoopableLine:
                        line = new LoopableLine((LoopableAutomation)left, right);
                        break;
                    }

                    if (line != null)
                    {
                        AddControl(line);
                        line.ID = item.ID;
                    }
                }
            }

            var id = GetControlID();

            if (id < a.ControlID)
            {
                var amount = a.ControlID - id;
                for (int i = 0; i < amount; i++)
                {
                    GetControlID();
                }
            }

            if (entryPoint == null)
            {
                entryPoint = new InternalQueueStart()
                {
                    Position = WindowRect.center
                };
                AddControl(entryPoint);

                EntryId = entryPoint.ID;
            }
        }