Example #1
0
 public static void UnplugPort(Port port)
 {
     UndoManager.RecordObject(asset, string.Format("{0} > {1}: {2} Unplug", asset.name, port.node.name, port.name));
     if (port is IPlug)
     {
         ((IPlug)port).Unplug();
     }
     UndoManager.SetDirty(asset);
 }
Example #2
0
 public static void DeleteSelectedNodes()
 {
     UndoManager.RecordObject(asset, string.Format("{0} Destroy Nodes", asset.name));
     if (selection.Count > 0)
     {
         graph.RemoveNodes(selection);
         ClearSelection();
     }
     UndoManager.SetDirty(asset);
 }
Example #3
0
 public static void PlugPort(Port a, Port b)
 {
     if (a is IPlugIn && b is IPlugOut)
     {
         UndoManager.RecordObject(asset, string.Format("{0} > {1}: {2} Plug to {3}: {4}", asset.name, a.node.name, a.name, b.node.name, b.name));
         ((IPlugIn)a).PlugTo((IPlugOut)b);
         UndoManager.SetDirty(asset);
     }
     else if (a is IPlugOut && b is IPlugIn)
     {
         UndoManager.RecordObject(asset, string.Format("{0} > {1}: {3} Plug to {2}: {4}", asset.name, a.node.name, a.name, b.node.name, b.name));
         ((IPlugIn)b).PlugTo((IPlugOut)a);
         UndoManager.SetDirty(asset);
     }
 }
Example #4
0
 public static void DuplicateSelectedNodes()
 {
     UndoManager.RecordObject(asset, string.Format("{0} Duplicate Nodes", asset.name));
     if (selection.Count > 0)
     {
         List <Node> new_selection = new List <Node>();
         foreach (Node node in selection)
         {
             Node clone = node.GetClone();
             new_selection.Add(graph.AddNode(clone, node.position + new Vector2(20.0f, 20.0f)));
             clone.Validate();
         }
         ClearSelection();
         SelectNodes(new_selection);
     }
     UndoManager.SetDirty(asset);
 }
        public override void OnInspectorGUI()
        {
            ConstantTypes types = (ConstantTypes)target;

            if (GUILayout.Button("Reset to defaults"))
            {
                UndoManager.RecordObject(target, "Reset to defaults");
                types.current_types = ConstantTypes.default_types;
                CreateTypeList();
            }

            list.DoLayoutList();

            if (GUI.changed)
            {
                UndoManager.SetDirty(target);
                GUI.changed = true;
            }
        }
Example #6
0
        private static void HierarchyIndex(int instance_id, Rect index_rect)
        {
            Event current = Event.current;

            if (styles == null)
            {
                styles = new Styles();
            }

            target = EditorUtility.InstanceIDToObject(instance_id) as GameObject;
            if (index_rect.Contains(current.mousePosition))
            {
                InputGUI();
            }
            if (target)
            {
                if (target.GetComponent <GraphController>())
                {
                    int graph_count = target.GetComponents <GraphController>().Length;

                    Rect       rect    = new Rect(index_rect.width - 10.0f, index_rect.y - 2.0f, 20.0f, 20.0f);
                    GUIContent content = new GUIContent(graph_count > 1 ? graph_count.ToString() : string.Empty, string.Empty);

                    if (GUI.Button(rect, content, styles.icon))
                    {
                        Selection.activeObject = target;
                        GraphEditorWindow.OpenEditor(target.GetComponent <GraphController>().graph);
                    }
                }
                if (set_dirty)
                {
                    UndoManager.SetDirty(target);
                    set_dirty = false;
                }
            }
            target = null;
        }
Example #7
0
 public static void QuickPlugPort(Port port, Node node)
 {
     UndoManager.RecordObject(asset, string.Format("{0} > {1}: {2} Plug", asset.name, node.name, port.name));
     foreach (Port p in node.portValues)
     {
         if (p is IPlugOut && port is IPlugIn)
         {
             if (((IPlugIn)port).CanPlug((IPlugOut)p, false))
             {
                 ((IPlugIn)port).PlugTo((IPlugOut)p);
                 break;
             }
         }
         else if (p is IPlugIn && port is IPlugOut)
         {
             if (((IPlugIn)p).CanPlug((IPlugOut)port, false))
             {
                 ((IPlugIn)p).PlugTo((IPlugOut)port);
                 break;
             }
         }
     }
     UndoManager.SetDirty(asset);
 }
Example #8
0
        public override void OnInspectorGUI()
        {
            GraphController controller = (GraphController)target;
            GraphAsset      graph      = controller.graph;

            OnEnableAction  on_enable  = controller.on_enable;
            bool            once       = controller.once;
            float           seconds    = controller.seconds;
            OnDisableAction on_disable = controller.on_disable;

            controller.CopyParameters();

            graph = (GraphAsset)EditorGUILayout.ObjectField(new GUIContent("Graph"), controller.graph, typeof(GraphAsset), false);

            if (controller.graph != graph)
            {
                controller.OnGraphChange(controller.graph, graph);
            }

            if (controller.graph)
            {
                on_enable = (OnEnableAction)EditorGUILayout.EnumPopup(new GUIContent("OnEnable"), controller.on_enable);

                switch (on_enable)
                {
                case OnEnableAction.DoNothing:
                case OnEnableAction.PlayGraph:
                    if (height != 0.0f)
                    {
                        height = 0.0f;
                        EditorUtils.RepaintInspector();
                    }
                    seconds = 0.0f;
                    break;

                case OnEnableAction.WaitForSeconds:
                    GUILayout.BeginVertical("Box");
                    if (height != EditorGUIUtility.singleLineHeight)
                    {
                        height = Mathf.MoveTowards(height, EditorGUIUtility.singleLineHeight, 1.0f);
                        EditorUtils.RepaintInspector();
                    }
                    once    = EditorGUILayout.Toggle(new GUIContent("Only Once"), controller.once, GUILayout.Height(height));
                    seconds = EditorGUILayout.FloatField(new GUIContent("Seconds"), controller.seconds, GUILayout.Height(height));
                    GUILayout.EndVertical();
                    break;
                }
                on_disable = (OnDisableAction)EditorGUILayout.EnumPopup(new GUIContent("OnDisable"), controller.on_disable);

                GUILayout.BeginHorizontal();
                if (GUILayout.Button("Ping to Asset"))
                {
                    EditorGUIUtility.PingObject(controller.graph);
                }
                if (GUILayout.Button("Open in Editor"))
                {
                    GraphEditorWindow.OpenEditor(controller.graph);
                }
                GUILayout.EndHorizontal();
            }

            GUILayout.BeginHorizontal("RL Header");
            {
                GUILayout.Space(15.0f);
                GUILayout.BeginVertical();
                {
                    foldout = EditorGUILayout.Foldout(foldout, new GUIContent(string.Format("Variables [{0}]", controller.properties.Values.Where(p => p.is_public).Count())));
                }
                GUILayout.EndVertical();
                if (GUILayout.Toggle(debug, debug ? "Debug" : "Normal", (GUIStyle)"minibutton") != debug)
                {
                    debug = !debug;
                }
            }
            GUILayout.EndHorizontal();

            if (foldout)
            {
                GUILayout.BeginHorizontal("RL Background", GUILayout.MinHeight(10.0f));
                {
                    GUILayout.Space(10.0f);
                    GUILayout.BeginVertical();
                    {
                        foreach (VariableObject property in controller.properties.Values.ToList())
                        {
                            if (property.is_public || debug)
                            {
                                object last_value = property.GetValue();
                                object new_value  = GUIDraw.AnyField(last_value, property.valueType, debug ? property.name + string.Format(" (ID = {0}, Type = {1})", property.id, property.valueType.GetTypeName(true, true)) : property.name);
                                if (new_value != last_value)
                                {
                                    UndoManager.RecordObject(target, "Change Value");
                                    property.SetValue(new_value);
                                }
                            }
                        }
                    }
                    GUILayout.Space(5.0f);
                    GUILayout.EndVertical();
                }
                GUILayout.EndHorizontal();
            }

            if (GUI.changed)
            {
                UndoManager.RecordObject(target, "GraphController Inspector");
                controller.graph      = graph;
                controller.on_enable  = on_enable;
                controller.once       = once;
                controller.seconds    = seconds;
                controller.on_disable = on_disable;
                UndoManager.SetDirty(target);
            }
        }
Example #9
0
        public override void OnInspectorGUI()
        {
            bool restore_wide_mode = EditorGUIUtility.wideMode;

            EditorGUIUtility.wideMode   = true;
            EditorGUIUtility.labelWidth = 0.0f;
            EditorGUIUtility.fieldWidth = 0.0f;

            if (GUILayout.Button("Open in Editor"))
            {
                GraphEditorWindow.OpenEditor(asset);
            }
            try {
                DrawMenuMode();

                GUILayout.Space(5.0f);

                switch (currentMenu)
                {
                //Graph
                case 0:
                    string title = EditorGUILayout.TextField(asset.title);
                    GUIDraw.GhostLabel(title, "Title...", -2.0f, 5.0f);
                    if (title != asset.title)
                    {
                        UndoManager.RecordObject(target, "Title Change");
                        asset.title = title;
                        GraphEditor.current_validate = true;
                    }
                    GUILayout.Space(3.0f);
                    string subtitle = EditorGUILayout.TextArea(asset.subtitle, GUILayout.MinHeight(50.0f));
                    GUIDraw.GhostLabel(subtitle, "Subtitle...", -2.0f, 5.0f);
                    if (subtitle != asset.subtitle)
                    {
                        UndoManager.RecordObject(target, "Subtitle Change");
                        asset.subtitle = subtitle;
                        GraphEditor.current_validate = true;
                    }
                    GUILayout.Label(string.Format("Nodes: {0}", asset.graph.nodes.Count.ToString()));
                    break;

                //Parameters
                case 1:
                    input_list.DoLayoutList();
                    output_list.DoLayoutList();
                    break;

                //Variables
                case 2:
                    variable_list.DoLayoutList();
                    break;

                //Node Inspector
                case 3:
                    DrawNodeInspector();
                    break;
                }
            }
            catch {
                CreateReorderableLists();
                GraphEditor.current_validate = true;
            }

            if (GUI.changed)
            {
                UndoManager.SetDirty(target);
                GUI.changed = false;
            }

            EditorGUIUtility.wideMode = restore_wide_mode;
        }
Example #10
0
 public static void DeleteNode(Node node)
 {
     UndoManager.RecordObject(asset, string.Format("{0} > {1} Destroy Node", asset.name, node.name));
     graph.RemoveNode(node);
     UndoManager.SetDirty(asset);
 }
Example #11
0
        public void OnGUI()
        {
            bkp_zoom   = GraphEditor.zoom;
            bkp_scroll = GraphEditor.scroll;

            GraphEditor.window = position;
            Color gui_background_color = GUI.backgroundColor;

            if (EditorApplication.isCompiling)
            {
                DrawLogoAnim();
                ShowNotification(new GUIContent("Compiling, please wait..."));
                return;
            }
            if (internal_error)
            {
                DrawLogoAnim();
                ShowNotification(new GUIContent("INTERNAL ERROR!\nPlease contact the support."));
                GUILayout.BeginHorizontal();
                if (GUILayout.Button("Retry"))
                {
                    internal_error = false;
                }
                if (GUILayout.Button("Close Editor"))
                {
                    editor.Close();
                }
                GUILayout.EndHorizontal();
                return;
            }
            try {
                bool dragging = GraphEditor.is_drag && GraphEditor.hover_node;
                if (GraphEditor.asset && GraphEditor.graph)
                {
                    current = Event.current;
                    GraphEditor.mouse_position = current.mousePosition;

                    if (isDocked)
                    {
                        zoom_area = new Rect(0.0f, 19.0f, position.width, position.height);
                    }
                    else
                    {
                        zoom_area = new Rect(0.0f, 22.0f, position.width, position.height);
                    }

                    ClearHoverElements();

                    BeginZoomArea();

                    DrawScrollBackground();

                    if (GraphEditor.drag_port)
                    {
                        if (GraphEditor.drag_port is IInputPort)
                        {
                            Node.DrawConnection(GraphEditor.drag_port.rect.center, GraphEditor.mouse_position / GraphEditor.zoom, GraphEditor.drag_port.color, true);
                        }
                        else
                        {
                            Node.DrawConnection(GraphEditor.mouse_position / GraphEditor.zoom, GraphEditor.drag_port.rect.center, GraphEditor.drag_port.color, true);
                        }
                        if (GraphEditor.drag_port is ActionPort)
                        {
                            GUI.Label(new Rect((GraphEditor.mouse_position) / GraphEditor.zoom - Node.PORT_SIZE / 2.0f, Node.PORT_SIZE), GUIContent.none, Node.styles.on_input_action);
                        }
                        else
                        {
                            GUI.backgroundColor = GraphEditor.drag_port.color;
                            GUI.Label(new Rect((GraphEditor.mouse_position) / GraphEditor.zoom - Node.PORT_SIZE / 2.0f, Node.PORT_SIZE), GUIContent.none, Node.styles.on_input_port);
                            GUI.backgroundColor = gui_background_color;
                        }
                    }

                    DrawNodes();

                    InputGUI();

                    EndZoomArea();

                    DrawSelectBox();

                    DrawWindowBorder();

                    DrawWindowHeader();

                    DrawToolbar();

                    if (dragging != (GraphEditor.is_drag && GraphEditor.hover_node))
                    {
                        UndoManager.RecordObject(GraphEditor.asset, string.Format("{0} Move Nodes", GraphEditor.asset.name));
                        set_dirty = true;
                    }

                    if (set_dirty)
                    {
                        UndoManager.SetDirty(GraphEditor.asset);
                        set_dirty = false;
                    }
                }
                else
                {
                    DrawLogoAnim();
                }
                if (dragging || bkp_zoom != GraphEditor.zoom || bkp_scroll != GraphEditor.scroll)
                {
                    bkp_zoom   = GraphEditor.zoom;
                    bkp_scroll = GraphEditor.scroll;
                }
                Repaint();
            }
            catch (Exception except) {
                Debug.LogException(except);
                internal_error = true;
            }
        }