Exemplo n.º 1
0
        public static GroupNode FromNodes(string name, List <Node> nodes, System.Type graphType)
        {
            if (nodes.Count == 0)
            {
                throw new ArgumentException("No nodes to group");
            }
            Graph parentGraph = nodes[0].graph;

            if (parentGraph == null)
            {
                throw new ArgumentException("Nodes needs to be attached to a graph");
            }
            GroupNode node = new GroupNode(name, parentGraph, graphType);

            parentGraph.AddNode(node);
            node.m_ProxyInNode = ProxyNode.Instance(true);
            node.subGraph.AddNode(node.m_ProxyInNode);
            node.m_ProxyOutNode = ProxyNode.Instance(false);
            node.subGraph.AddNode(node.m_ProxyOutNode);
            List <UnityEditor.Graphs.Edge> list = new List <UnityEditor.Graphs.Edge>();

            foreach (Node node2 in nodes)
            {
                list.AddRange(node2.outputEdges);
                list.AddRange(node2.inputEdges);
                node.AddChildNode(node2);
                parentGraph.nodes.Remove(node2);
            }
            foreach (UnityEditor.Graphs.Edge edge in list)
            {
                if ((edge.fromSlot.node.graph == node.subGraph) && (edge.toSlot.node.graph == node.subGraph))
                {
                    if (!node.subGraph.Connected(edge.fromSlot, edge.toSlot))
                    {
                        node.subGraph.Connect(edge.fromSlot, edge.toSlot);
                    }
                }
                else if ((edge.fromSlot.node.graph == node.subGraph) && (edge.toSlot.node.graph != node.subGraph))
                {
                    string str = edge.fromSlot.name;
                    int    num = 0;
                    while (node.m_ProxyInNode[str] != null)
                    {
                        str = edge.fromSlot.name + "_" + num++;
                    }
                    Slot s = new Slot(SlotType.InputSlot, str);
                    node.m_ProxyInNode.AddSlot(s);
                    node.subGraph.Connect(edge.fromSlot, s);
                    Slot slot2 = new Slot(SlotType.OutputSlot, str);
                    node.AddSlot(slot2);
                    node.graph.Connect(slot2, edge.toSlot);
                }
                else if ((edge.fromSlot.node.graph != node.subGraph) && (edge.toSlot.node.graph == node.subGraph))
                {
                    string str2 = edge.toSlot.name;
                    int    num2 = 0;
                    while (node.m_ProxyOutNode[str2] != null)
                    {
                        str2 = edge.toSlot.name + "_" + num2++;
                    }
                    Slot slot3 = new Slot(SlotType.OutputSlot, str2);
                    node.m_ProxyOutNode.AddSlot(slot3);
                    node.subGraph.Connect(slot3, edge.toSlot);
                    Slot slot4 = new Slot(SlotType.InputSlot, str2);
                    node.AddSlot(slot4);
                    node.graph.Connect(edge.fromSlot, slot4);
                }
                node.graph.RemoveEdge(edge);
            }
            return(node);
        }
Exemplo n.º 2
0
 private GroupNode(string name, Graph parentGraph, System.Type graphType)
 {
     this.m_SubGraph      = (Graph)Activator.CreateInstance(graphType);
     base.name            = name;
     this.m_SubGraph.name = "SubGraph";
 }