public void CopySelectedNodes() { Debug.Log("copy"); //copy data VisualEditor.BackEnd.Node[] buffer = new VisualEditor.BackEnd.Node[selectedNodes.Count]; BinaryFormatter bf = new BinaryFormatter(); MemoryStream ms = new MemoryStream(); clipboardPos = new Vector2[buffer.Length]; for (int i = 0; i < buffer.Length; i++) { buffer[i] = selectedNodes[i].GetComponent <NodeVisual>().node; clipboardPos[i] = selectedNodes[i].position; } //duplicate nodes bf.Serialize(ms, buffer); ms.Position = 0; buffer = (VisualEditor.BackEnd.Node[])bf.Deserialize(ms); //disconnect inputs and outputs that are not linked to a node inside the selection for (int i = 0; i < buffer.Length; i++) { for (int k = 0; k < buffer[i].inputs.Count; k++) { if (buffer[i].inputs[k].outputConnectedTo != null && !buffer.Contains(buffer[i].inputs[k].outputConnectedTo.host)) { buffer[i].inputs[k].SetIncommingDataType(null); buffer[i].inputs[k].outputConnectedTo = null; buffer[i].inputs[k].host.PartialSetup(); } } for (int k = 0; k < buffer[i].outputs.Count; k++) { VisualEditor.BackEnd.Input[] copy = buffer[i].outputs[k].destinations.ToArray(); for (int z = 0; z < copy.Length; z++) { if (!buffer.Contains(copy[z].host)) { buffer[i].outputs[k].DisconnectFrom(copy[z]); } } } } clipboard = buffer; }
public void CopySelectedNodesForGrouping(out VisualEditor.BackEnd.Input[] cutIns, out VisualEditor.BackEnd.Output[] cutOuts, out Type[] insType, out Vector2[] inPoss, out Vector2[] outPoss) { Debug.Log("copy for grouping"); //copy data VisualEditor.BackEnd.Node[] buffer = new VisualEditor.BackEnd.Node[selectedNodes.Count]; BinaryFormatter bf = new BinaryFormatter(); MemoryStream ms = new MemoryStream(); clipboardPos = new Vector2[buffer.Length]; List <VisualEditor.BackEnd.Input> insR = new List <VisualEditor.BackEnd.Input>(); List <VisualEditor.BackEnd.Output> outsR = new List <VisualEditor.BackEnd.Output>(); List <Type> inTypes = new List <Type>(); List <Vector2> inPos = new List <Vector2>(); List <Vector2> outPos = new List <Vector2>(); for (int i = 0; i < buffer.Length; i++) { buffer[i] = selectedNodes[i].GetComponent <NodeVisual>().node; clipboardPos[i] = selectedNodes[i].position; } //duplicate nodes bf.Serialize(ms, buffer); ms.Position = 0; buffer = (VisualEditor.BackEnd.Node[])bf.Deserialize(ms); //disconnect inputs and outputs that are not linked to a node inside the selection for (int i = 0; i < buffer.Length; i++) { for (int k = 0; k < buffer[i].inputs.Count; k++) { if (buffer[i].inputs[k].outputConnectedTo != null && !buffer.Contains(buffer[i].inputs[k].outputConnectedTo.host)) { insR.Add(buffer[i].inputs[k]); inTypes.Add(buffer[i].inputs[k].GetDataType()); inPos.Add(selectedNodes[i].GetComponent <NodeVisual>().transform.position); buffer[i].inputs[k].SetIncommingDataType(null); buffer[i].inputs[k].outputConnectedTo = null; buffer[i].inputs[k].host.PartialSetup(); } } for (int k = 0; k < buffer[i].outputs.Count; k++) { VisualEditor.BackEnd.Input[] copy = buffer[i].outputs[k].destinations.ToArray(); for (int z = 0; z < copy.Length; z++) { if (!buffer.Contains(copy[z].host)) { outPos.Add(selectedNodes[i].GetComponent <NodeVisual>().transform.position); buffer[i].outputs[k].DisconnectFrom(copy[z]); outsR.Add(buffer[i].outputs[k]); } } } } cutIns = insR.ToArray(); cutOuts = outsR.ToArray(); insType = inTypes.ToArray(); inPoss = inPos.ToArray(); outPoss = outPos.ToArray(); clipboard = buffer; }