protected void Paste() { Block block = target as Block; Flowchart flowchart = block.GetFlowchart(); if (flowchart == null || flowchart.selectedBlock == null) { return; } CommandCopyBuffer commandCopyBuffer = CommandCopyBuffer.GetInstance(); // Find where to paste commands in block (either at end or after last selected command) int pasteIndex = flowchart.selectedBlock.commandList.Count; if (flowchart.selectedCommands.Count > 0) { for (int i = 0; i < flowchart.selectedBlock.commandList.Count; ++i) { Command command = flowchart.selectedBlock.commandList[i]; foreach (Command selectedCommand in flowchart.selectedCommands) { if (command == selectedCommand) { pasteIndex = i + 1; } } } } foreach (Command command in commandCopyBuffer.GetCommands()) { // Using the Editor copy / paste functionality instead instead of reflection // because this does a deep copy of the command properties. if (ComponentUtility.CopyComponent(command)) { if (ComponentUtility.PasteComponentAsNew(flowchart.gameObject)) { Command[] commands = flowchart.GetComponents <Command>(); Command pastedCommand = commands.Last <Command>(); if (pastedCommand != null) { pastedCommand.itemId = flowchart.NextItemId(); flowchart.selectedBlock.commandList.Insert(pasteIndex++, pastedCommand); } } // This stops the user pasting the command manually into another game object. ComponentUtility.CopyComponent(flowchart.transform); } } // Because this is an async call, we need to force prefab instances to record changes PrefabUtility.RecordPrefabInstancePropertyModifications(block); Repaint(); }
protected void Paste() { Sequence sequence = target as Sequence; FungusScript fungusScript = sequence.GetFungusScript(); if (fungusScript == null || fungusScript.selectedSequence == null) { return; } CommandCopyBuffer commandCopyBuffer = CommandCopyBuffer.GetInstance(); // Find where to paste commands in sequence (either at end or after last selected command) int pasteIndex = fungusScript.selectedSequence.commandList.Count; if (fungusScript.selectedCommands.Count > 0) { for (int i = 0; i < fungusScript.selectedSequence.commandList.Count; ++i) { Command command = fungusScript.selectedSequence.commandList[i]; foreach (Command selectedCommand in fungusScript.selectedCommands) { if (command == selectedCommand) { pasteIndex = i + 1; } } } } foreach (Command command in commandCopyBuffer.GetCommands()) { // Using the Editor copy / paste functionality instead instead of reflection // because this does a deep copy of the command properties. if (ComponentUtility.CopyComponent(command)) { if (ComponentUtility.PasteComponentAsNew(fungusScript.gameObject)) { Command[] commands = fungusScript.GetComponents <Command>(); Command pastedCommand = commands.Last <Command>(); if (pastedCommand != null) { fungusScript.selectedSequence.commandList.Insert(pasteIndex++, pastedCommand); } } // This stops the user pasting the command manually into another game object. ComponentUtility.CopyComponent(fungusScript.transform); } } Repaint(); }