Ejemplo n.º 1
0
        public AutomationField(Automation parent, FieldInfo info, string id)
        {
            this.parent = parent;
            this.info   = info;
            this.ID     = id;

            var fieldType  = info.FieldType;
            var drawerType = AutomatronEditor.GetDrawerType(fieldType);

            if (drawerType == typeof(HelpDrawer))
            {
                if (fieldType.IsEnum)
                {
                    drawerType = typeof(EnumDrawer);
                }
                else if (fieldType.IsArray)
                {
                    drawerType = typeof(ArrayDrawer);
                }
                else if (fieldType.GetInterfaces().Contains(typeof(IList)))
                {
                    drawerType = typeof(ListDrawer);
                }
                else
                {
                    var t = typeof(UnityEngine.Object);
                    if (fieldType == t || fieldType.IsSubclassOf(t))
                    {
                        drawerType = typeof(ObjectDrawer);
                    }
                }
            }

            drawer = (AutomationDrawer)Activator.CreateInstance(drawerType);
            drawer.CustomAttributes     = info.GetCustomAttributes(false).ToList();
            drawer.HasReadOnlyAttribute = info.GetCustomAttributes(typeof(ReadOnlyAttribute), false).FirstOrDefault() != null;
            drawer.Parent = this;
            drawer.Type   = fieldType;
            drawer.Initialize();

            Name = ObjectNames.NicifyVariableName(info.Name);

            Rectangle = new Rect(parent.Position.x, parent.Position.y, parent.Size.x, drawer.GetFieldHeight());
        }
Ejemplo n.º 2
0
 public AutomationTemplator(AutomatronEditor editor)
 {
     this.editor = editor;
 }
Ejemplo n.º 3
0
        protected override void OnGUI()
        {
            EditorGUI.LabelField(new Rect(0, 10, Size.x, Size.y), "AUTOMATRON", headerStyle);

            GUILayout.BeginArea(new Rect(50, 125, Size.x - 100, 16));
            ExtendedGUI.HorizontalLine();
            GUILayout.EndArea();

            ListGUI();
            if (anim > 0)
            {
                CreateGUI();
            }

            if (Event.current.type == EventType.Repaint && AutomatronSettings.FirstRun)
            {
                AutomatronSettings.FirstRun.Value = false;
                if (configs.Count == 0)
                {
                    var v = EditorUtility.DisplayDialog("", "It seems that this is your first time you here.\nDo you want to add some example projects?", "Yes", "No");
                    if (v)
                    {
                        if (!Directory.Exists(AutomatronSettings.ConfigFolder))
                        {
                            Directory.CreateDirectory(AutomatronSettings.ConfigFolder);
                        }

                        AddExample("ForEach Example");
                        AddExample("For Example");
                        AddExample("Conditional Example");
                        AddExample("Advanced Example");
                        AddExample("Simple Example");

                        SaveRecents();
                    }
                }
            }

            switch (Event.current.type)
            {
            case EventType.DragUpdated:
            case EventType.DragPerform: {
                var paths = DragAndDrop.paths.Where(p => p.EndsWith(".acfg")).ToList();

                if (paths.Count > 0)
                {
                    DragAndDrop.visualMode = DragAndDropVisualMode.Link;
                }

                if (Event.current.type == EventType.DragPerform)
                {
                    DragAndDrop.AcceptDrag();

                    if (paths.Count == 1)
                    {
                        loadAutomatron = true;
                        automatron     = paths[0];
                    }
                    else
                    {
                        addAutomatrons = true;
                        automatrons    = paths;
                    }
                }
            }
            break;
            }

            if (Event.current.type == EventType.Repaint)
            {
                if (createAutomatron)
                {
                    createAutomatron = false;
                    try {
                        var p = Path.Combine(automatronPath, automatronName).Replace("\\", "/") + ".acfg";

                        var i = -1;
                        while ((i = configs.IndexOf(p)) != -1)
                        {
                            configs.RemoveAt(i);
                        }

                        configs.Insert(0, p);
                        SaveRecents();
                    } catch (System.Exception) {
                        EditorUtility.DisplayDialog("Oops", "Something went wrong trying to make this Automatron!", "OK");
                        return;
                    }

                    Remove();
                    var wnd = new AutomatronEditor();
                    AddWindow(wnd);
                    wnd.NewAutomatron(automatronPath, automatronName);

                    return;
                }
                else if (loadAutomatron)
                {
                    loadAutomatron = false;

                    var i = configs.IndexOf(automatron);
                    if (i != -1)
                    {
                        configs.RemoveAt(i);
                    }

                    configs.Insert(0, automatron);
                    SaveRecents();

                    Remove();
                    var wnd = new AutomatronEditor();
                    AddWindow(wnd);
                    wnd.LoadAutomatron(automatron);

                    return;
                }
                else if (deleteAutomatron)
                {
                    deleteAutomatron = false;

                    var i = configs.IndexOf(automatron);
                    if (i != -1)
                    {
                        configs.RemoveAt(i);
                        SaveRecents();
                    }

                    return;
                }
                else if (addAutomatrons)
                {
                    addAutomatrons = false;

                    foreach (var item in automatrons)
                    {
                        if (configs.Contains(item))
                        {
                            continue;
                        }
                        configs.Insert(0, item);
                    }

                    SaveRecents();
                }
            }

            Repaint();
        }
        public static void Save(AutomatronEditor editor)
        {
            var automatron = new SerializableAutomatron();

            automatron.EntryID   = editor.EntryId;
            automatron.Name      = editor.Name;
            automatron.Path      = editor.Path;
            automatron.Camera    = Globals.Camera;
            automatron.ControlID = editor.GetControlID();

            var automations = editor.GetControls <Automation>();

            foreach (var item in automations)
            {
                var automation = new SerializableAutomation();
                automation.ID       = item.ID;
                automation.Type     = item.GetType().FullName;
                automation.Position = item.Position;

                var fields = item.GetFields();
                foreach (var f in fields)
                {
                    var field = new SerializableField();
                    field.ID = f.ID;
                    var v = f.GetValue();
                    if (v is GameObject)
                    {
                        continue;
                    }
                    if (v is ScriptableObject)
                    {
                        continue;
                    }
                    field.Value = v;
                    automation.Fields.Add(field);
                }

                automatron.Automations.Add(automation);
            }

            var lines = editor.GetControls <BezierLine>();

            foreach (var item in lines)
            {
                var line = new SerializableLine();
                line.ID = item.ID;

                if (item is ConditionalLine)
                {
                    var l = (ConditionalLine)item;
                    line.LineType = ELineType.ConditionalLine;
                    line.IdLeft   = l.Left.ID;
                    line.IdRight  = l.Right.ID;
                }
                else if (item is FieldLine)
                {
                    var l = (FieldLine)item;
                    line.LineType = ELineType.FieldLine;
                    line.IdLeft   = l.Left.ID;
                    line.IdRight  = l.Right.ID;
                }
                else if (item is LoopableLine)
                {
                    var l = (LoopableLine)item;
                    line.LineType = ELineType.LoopableLine;
                    line.IdLeft   = l.Left.ID;
                    line.IdRight  = l.Right.ID;
                }
                else if (item is AutomationLine)
                {
                    var l = (AutomationLine)item;
                    line.LineType = ELineType.AutomationLine;
                    line.IdLeft   = l.Left.ID;
                    line.IdRight  = l.Right.ID;
                }

                automatron.Lines.Add(line);
            }

            var buffer = Serializer.SerializeToBytes(automatron);

            var path = editor.Path;

            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }

            var fpath = Path.Combine(path, automatron.Name + ".acfg");

            File.WriteAllBytes(fpath, buffer);
        }