示例#1
0
        public virtual void UpdateGUI(BaseNode _node, NodeEditorWindow _curWindow)
        {
            if (GUI.Button(m_IORect, new GUIContent("")))
            {
                NodeGraph graph = _curWindow.GetCurrentGraph();
                Event     e     = Event.current;
                if (e.button == 1)
                {
                    graph.SetIsMakingConnection(false);
                    graph.m_connectionFrom = null;
                    ProcessContextMenu(e, graph);
                    return;
                }

                if (graph.GetIsMakingConnection() && graph.GetConnectionType() != m_type)
                {
                    if (m_connectedTo != null)
                    {
                        m_connectedTo.m_isOccupied  = false;
                        m_connectedTo.m_connectedTo = null;
                    }

                    Debug.Log("Connection made");
                    m_isOccupied  = true;
                    m_connectedTo = graph.m_connectionFrom;
                    m_connectedTo.m_isOccupied = true;

                    m_connectedTo.m_isOccupied  = true;
                    m_connectedTo.m_connectedTo = this;

                    graph.SetIsMakingConnection(false);
                    graph.m_connectionFrom = null;
                }
                else if (!_curWindow.GetCurrentGraph().GetIsMakingConnection())
                {
                    _curWindow.GetCurrentGraph().SetIsMakingConnection(true);
                    _curWindow.GetCurrentGraph().SetConnectionType(m_type);
                    _curWindow.GetCurrentGraph().SetConnectionStart(m_IORect.center);
                    _curWindow.GetCurrentGraph().m_connectionFrom = this;
                }

                AssetDatabase.AddObjectToAsset(this, m_holderNode);
                AssetDatabase.SaveAssets();
                AssetDatabase.Refresh();
            }
        }
示例#2
0
        private void ProcessContextMenu(Event _e)
        {
            if (_e.type == EventType.MouseDrag)
            {
                if (_e.button == 0)
                {
                    m_parentGraph.SetSelectedNode(this);
                    BaseNode        selectedNode = m_parentGraph.GetSelectedNode();
                    List <BaseNode> nodes        = new List <BaseNode>();
                    nodes.Add(selectedNode);
                    if (selectedNode.m_outputs.Count > 0)
                    {
                        foreach (NodeOutput output in m_outputs)
                        {
                            if (output == null)
                            {
                                continue;
                            }

                            if (output.m_isOccupied)
                            {
                                BaseNode node = output.m_connectedTo.m_holderNode;

                                if (node != null && node.m_outputs.Count > 0 && node.m_outputs[0] != null)
                                {
                                    foreach (NodeOutput childOutput in node.m_outputs)
                                    {
                                        if (output == null)
                                        {
                                            continue;
                                        }

                                        nodes.Add(childOutput.m_connectedTo.m_holderNode);
                                    }
                                }
                                nodes.Add(output.m_connectedTo.m_holderNode);
                            }
                        }
                    }

                    Vector2 delta = _e.delta;

                    foreach (BaseNode node in nodes)
                    {
                        Rect temp = node.GetNodeRect();
                        temp.x += delta.x;
                        temp.y += delta.y;
                        node.SetNodeRect(temp);
                    }

                    m_parentGraph.isDragging = true;
                }
            }

            if (_e.type == EventType.Layout && _e.button == 1)
            {
                NodeGraph graph = (EditorWindow.GetWindow <NodeEditorWindow>() as NodeEditorWindow).GetCurrentGraph();

                if (graph != null)
                {
                    graph.SetIsMakingConnection(false);
                }

                GenericMenu menu = new GenericMenu();

                menu.AddItem(new GUIContent("Delete Node"), false, CallbackOnContextMenu, "0");
                menu.AddItem(new GUIContent("Mark this as Root Node"), false, CallbackOnContextMenu, "1");

                menu.AddSeparator("");
                menu.AddItem(new GUIContent("Add Output"), false, CallbackOnContextMenu, "2");

                menu.ShowAsContext();
            }
        }
示例#3
0
        public override void ProcessEvents(Event _e)
        {
            base.ProcessEvents(_e);

            if (GetViewRect().Contains(_e.mousePosition))
            {
                if (_e.button == 0)
                {
                    if (_e.type == EventType.MouseUp)
                    {
                    }

                    if (_e.type == EventType.MouseDown)
                    {
                        NodeGraph graph = (EditorWindow.GetWindow <NodeEditorWindow>() as NodeEditorWindow).GetCurrentGraph();
                        if (graph != null)
                        {
                            graph.SetIsMakingConnection(false);
                        }
                    }

                    if (_e.type == EventType.MouseDrag)
                    {
                    }
                }

                if (_e.button == 1)
                {
                    if (_e.type == EventType.MouseDown)
                    {
                        NodeGraph graph = (EditorWindow.GetWindow <NodeEditorWindow>() as NodeEditorWindow).GetCurrentGraph();
                        if (graph != null)
                        {
                            graph.SetIsMakingConnection(false);
                        }

                        m_mousePosition = _e.mousePosition;
                        ProcessContextMenu(_e);
                    }
                }

                if (_e.type == EventType.MouseDrag &&
                    (_e.button == 0 && _e.modifiers == EventModifiers.Alt) ||
                    _e.button == 2)
                {
                    NodeGraph graph = (EditorWindow.GetWindow <NodeEditorWindow>() as NodeEditorWindow).GetCurrentGraph();
                    if (graph != null)
                    {
                        graph.SetIsMakingConnection(false);
                    }

                    Vector2 delta = _e.delta;

                    foreach (BaseNode node in m_currGraph.m_nodes)
                    {
                        Rect temp = node.GetNodeRect();
                        temp.x += delta.x;
                        temp.y += delta.y;
                        node.SetNodeRect(temp);
                    }
                }

                if (_e.type == EventType.ScrollWheel)
                {
                    NodeGraph graph = (EditorWindow.GetWindow <NodeEditorWindow>() as NodeEditorWindow).GetCurrentGraph();
                    if (graph != null)
                    {
                        graph.SetIsMakingConnection(false);
                    }

                    zoomScale -= _e.delta.x * 0.01f;
                    zoomScale -= _e.delta.y * 0.01f;
                }
            }
        }