internal void PasteGraph(CopyPasteGraph graphToPaste, List <INode> remappedNodes, List <IEdge> remappedEdges) { var nodeGuidMap = new Dictionary <Guid, Guid>(); foreach (var node in graphToPaste.GetNodes <INode>()) { var oldGuid = node.guid; var newGuid = node.RewriteGuid(); nodeGuidMap[oldGuid] = newGuid; var drawState = node.drawState; var position = drawState.position; position.x += 30; position.y += 30; drawState.position = position; node.drawState = drawState; remappedNodes.Add(node); AddNode(node); // add the node to the pasted node list m_PastedNodes.Add(node); } // only connect edges within pasted elements, discard // external edges. foreach (var edge in graphToPaste.edges) { var outputSlot = edge.outputSlot; var inputSlot = edge.inputSlot; Guid remappedOutputNodeGuid; Guid remappedInputNodeGuid; if (nodeGuidMap.TryGetValue(outputSlot.nodeGuid, out remappedOutputNodeGuid) && nodeGuidMap.TryGetValue(inputSlot.nodeGuid, out remappedInputNodeGuid)) { var outputSlotRef = new SlotReference(remappedOutputNodeGuid, outputSlot.slotId); var inputSlotRef = new SlotReference(remappedInputNodeGuid, inputSlot.slotId); remappedEdges.Add(Connect(outputSlotRef, inputSlotRef)); } } ValidateGraph(); }
internal void PasteGraph(CopyPasteGraph graphToPaste, List <AbstractMaterialNode> remappedNodes, List <IEdge> remappedEdges) { var groupGuidMap = new Dictionary <Guid, Guid>(); foreach (var group in graphToPaste.groups) { var position = group.position; position.x += 30; position.y += 30; GroupData newGroup = new GroupData(group.title, position); var oldGuid = group.guid; var newGuid = newGroup.guid; groupGuidMap[oldGuid] = newGuid; AddGroup(newGroup); m_PastedGroups.Add(newGroup); } var nodeGuidMap = new Dictionary <Guid, Guid>(); foreach (var node in graphToPaste.GetNodes <AbstractMaterialNode>()) { AbstractMaterialNode pastedNode = node; var oldGuid = node.guid; var newGuid = node.RewriteGuid(); nodeGuidMap[oldGuid] = newGuid; // Check if the property nodes need to be made into a concrete node. if (node is PropertyNode) { PropertyNode propertyNode = (PropertyNode)node; // If the property is not in the current graph, do check if the // property can be made into a concrete node. if (!m_Properties.Select(x => x.guid).Contains(propertyNode.propertyGuid)) { // If the property is in the serialized paste graph, make the property node into a property node. var pastedGraphMetaProperties = graphToPaste.metaProperties.Where(x => x.guid == propertyNode.propertyGuid); if (pastedGraphMetaProperties.Any()) { pastedNode = pastedGraphMetaProperties.FirstOrDefault().ToConcreteNode(); pastedNode.drawState = node.drawState; nodeGuidMap[oldGuid] = pastedNode.guid; } } } AbstractMaterialNode abstractMaterialNode = (AbstractMaterialNode)node; // Check if the node is inside a group if (groupGuidMap.ContainsKey(abstractMaterialNode.groupGuid)) { var absNode = pastedNode as AbstractMaterialNode; absNode.groupGuid = groupGuidMap[abstractMaterialNode.groupGuid]; pastedNode = absNode; } var drawState = node.drawState; var position = drawState.position; position.x += 30; position.y += 30; drawState.position = position; node.drawState = drawState; remappedNodes.Add(pastedNode); AddNode(pastedNode); // add the node to the pasted node list m_PastedNodes.Add(pastedNode); } // only connect edges within pasted elements, discard // external edges. foreach (var edge in graphToPaste.edges) { var outputSlot = edge.outputSlot; var inputSlot = edge.inputSlot; Guid remappedOutputNodeGuid; Guid remappedInputNodeGuid; if (nodeGuidMap.TryGetValue(outputSlot.nodeGuid, out remappedOutputNodeGuid) && nodeGuidMap.TryGetValue(inputSlot.nodeGuid, out remappedInputNodeGuid)) { var outputSlotRef = new SlotReference(remappedOutputNodeGuid, outputSlot.slotId); var inputSlotRef = new SlotReference(remappedInputNodeGuid, inputSlot.slotId); remappedEdges.Add(Connect(outputSlotRef, inputSlotRef)); } } ValidateGraph(); }