public static Graph FlattenedCopy(Graph source) { Dictionary <Node, Node> dictionary = new Dictionary <Node, Node>(); Graph graph = (Graph)Activator.CreateInstance(source.GetType()); foreach (Node current in source.nodes) { Node node = (Node)Activator.CreateInstance(current.GetType()); EditorUtility.CopySerialized(current, node); dictionary.Add(current, node); graph.AddNode(node); } graph.OnEnable(); foreach (Edge current2 in source.edges) { Node node2 = current2.fromSlot.node; Node node3 = current2.toSlot.node; node2 = dictionary[node2]; node3 = dictionary[node3]; Slot fromSlot = node2[current2.fromSlot.name]; Slot toSlot = node3[current2.toSlot.name]; graph.Connect(fromSlot, toSlot); } return(graph); }
protected Graph CopyNodesPasteboardData(out int[] ids) { Graph graph = ScriptableObject.CreateInstance(this.m_Graph.GetType()) as Graph; graph.nodes.AddRange(this.selection.ToArray()); foreach (Edge current in this.m_Graph.edges) { if (this.selection.Contains(current.fromSlot.node) && this.selection.Contains(current.toSlot.node)) { graph.Connect(current.fromSlot, current.toSlot); } } List <int> list = new List <int>(); list.Add(graph.GetInstanceID()); list.AddRange(Graph.GetNodeIdsForSerialization(graph)); ids = list.ToArray(); return(graph); }