Esempio n. 1
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();
            }
        }