/// <summary> /// Duplicates selected objects. /// </summary> public void Duplicate() { // Peek things that can be copied (copy all actors) var objects = Selection.Where(x => x.CanCopyPaste && x != Graph.Main).ToList().BuildAllNodes().Where(x => x.CanCopyPaste && x is ActorNode).ToList(); if (objects.Count == 0) { return; } // Serialize actors var actors = objects.ConvertAll(x => ((ActorNode)x).Actor); var data = Actor.ToBytes(actors.ToArray()); if (data == null) { Editor.LogError("Failed to copy actors data."); return; } // Create paste action (with selecting spawned objects) var pasteAction = CustomPasteActorsAction.CustomDuplicate(this, data, Guid.Empty); if (pasteAction != null) { OnPasteAcction(pasteAction); } }
/// <summary> /// Pastes the copied objects. Supports undo/redo. /// </summary> /// <param name="pasteTargetActor">The target actor to paste copied data.</param> public void Paste(Actor pasteTargetActor) { // Get clipboard data var data = Application.ClipboardRawData; // Set paste target if only one actor is selected and no target provided if (pasteTargetActor == null && Selection.Count == 1 && Selection[0] is ActorNode actorNode) { pasteTargetActor = actorNode.Actor; } // Create paste action var pasteAction = CustomPasteActorsAction.CustomPaste(this, data, pasteTargetActor?.ID ?? Guid.Empty); if (pasteAction != null) { OnPasteAcction(pasteAction); } }