コード例 #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
        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;
            }
        }