From a06b7b47c67bba1be1880b9659e73fbe384cc88b Mon Sep 17 00:00:00 2001 From: geondo55 <102933884+geondo55@users.noreply.github.com> Date: Wed, 25 Jun 2025 14:12:36 +0900 Subject: [PATCH] =?UTF-8?q?Redo=20=EB=8F=99=EC=9E=91=20=EC=95=88=ED=95=98?= =?UTF-8?q?=EB=8A=94=20=EC=98=A4=EB=A5=98=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../UndoRedo/RTUndoRedo.cs | 44 +++++++++---------- Assets/Scripts/Studio/Core/CommandInvoker.cs | 17 +++++-- 2 files changed, 36 insertions(+), 25 deletions(-) diff --git a/Assets/Scripts/ExternalAssets/Runtime Transform Gizmos/Runtime Package Common/UndoRedo/RTUndoRedo.cs b/Assets/Scripts/ExternalAssets/Runtime Transform Gizmos/Runtime Package Common/UndoRedo/RTUndoRedo.cs index aba44626..aa7d26a5 100644 --- a/Assets/Scripts/ExternalAssets/Runtime Transform Gizmos/Runtime Package Common/UndoRedo/RTUndoRedo.cs +++ b/Assets/Scripts/ExternalAssets/Runtime Transform Gizmos/Runtime Package Common/UndoRedo/RTUndoRedo.cs @@ -99,28 +99,28 @@ namespace RTG if (!_isEnabled) return; - if (!Application.isEditor) - { - if (RTInput.GetKeyDown(KeyCode.Z) && RTInput.GetKey(KeyCode.LeftControl)) - { - Undo(); - } - else if (RTInput.GetKeyDown(KeyCode.Y) && RTInput.GetKey(KeyCode.LeftControl)) - { - Redo(); - } - return; - } - // Note: When running inside the editor, it seems that we need to add the LSHIFT key into - // the mix. Otherwise, Undo/Redo does not work. - if (GetEditorUndoHotkey()) - { - Undo(); - } - else if (GetEditorRedoHotkey()) - { - Redo(); - } + //if (!Application.isEditor) + //{ + // if (RTInput.GetKeyDown(KeyCode.Z) && RTInput.GetKey(KeyCode.LeftControl)) + // { + // Undo(); + // } + // else if (RTInput.GetKeyDown(KeyCode.Y) && RTInput.GetKey(KeyCode.LeftControl)) + // { + // Redo(); + // } + // return; + //} + //// Note: When running inside the editor, it seems that we need to add the LSHIFT key into + //// the mix. Otherwise, Undo/Redo does not work. + //if (GetEditorUndoHotkey()) + //{ + // Undo(); + //} + //else if (GetEditorRedoHotkey()) + //{ + // Redo(); + //} } bool GetEditorUndoHotkey() diff --git a/Assets/Scripts/Studio/Core/CommandInvoker.cs b/Assets/Scripts/Studio/Core/CommandInvoker.cs index f379bda1..f011aad4 100644 --- a/Assets/Scripts/Studio/Core/CommandInvoker.cs +++ b/Assets/Scripts/Studio/Core/CommandInvoker.cs @@ -7,12 +7,13 @@ using Studio.Manage; namespace Studio.Command { - public class CommandInvoker: IInputHandler + public class CommandInvoker : IInputHandler { public static CommandInvoker instance => SystemMain.instance.commandInvoker; Stack commandStack = new(); - Stack undoableStack = new (); + Stack undoableStack = new(); + Stack redoableStack = new(); public void Invoke(ICommand command) { switch (command) @@ -33,9 +34,10 @@ namespace Studio.Command command.Execute(); commandStack.Push(command); undoableStack.Push(command); + redoableStack.Clear(); } - public void Invoke(IIrreversibleCommand command) + public void Invoke(IIrreversibleCommand command) { Debug.Log($"Invoke Irreversible Command={command}"); command.Execute(); @@ -50,12 +52,21 @@ namespace Studio.Command } var command = undoableStack.Pop(); command.Undo(); + redoableStack.Push(command); } public void Redo() { + if (redoableStack.Count == 0) + { + return; + } + var command = redoableStack.Pop(); + command.Execute(); + undoableStack.Push(command); } + public InputHandler GetInputHandler() { var shortcutTable = new Dictionary>(); -- 2.48.1.windows.1