From c0edd71a568cc80a6d1d731322f5ea05751ed122 Mon Sep 17 00:00:00 2001 From: yangbear Date: Thu, 9 Jul 2026 16:51:57 +0800 Subject: [PATCH] feat: group all ping steps into a single undo action per user request --- Assets/Scripts/Core/StepManager.cs | 7 ++++ Assets/Scripts/Core/UndoManager.cs | 60 +++++++++++++++++------------- 2 files changed, 41 insertions(+), 26 deletions(-) diff --git a/Assets/Scripts/Core/StepManager.cs b/Assets/Scripts/Core/StepManager.cs index ad99986..d2838d1 100644 --- a/Assets/Scripts/Core/StepManager.cs +++ b/Assets/Scripts/Core/StepManager.cs @@ -226,6 +226,13 @@ public class StepManager : MonoBehaviour OnStepChanged?.Invoke(_pingStepIndex); } + public void ResetPingStep() + { + _pingStepIndex = 0; + Debug.Log($"StepManager: Ping彻底重置 -> {_pingStepIndex}"); + OnStepChanged?.Invoke(_pingStepIndex); + } + public void DecrementWomanStep() { if (_womanStepIndex > 0) _womanStepIndex--; diff --git a/Assets/Scripts/Core/UndoManager.cs b/Assets/Scripts/Core/UndoManager.cs index b9eea2a..3e65b7e 100644 --- a/Assets/Scripts/Core/UndoManager.cs +++ b/Assets/Scripts/Core/UndoManager.cs @@ -32,6 +32,40 @@ public static class ActionHistory var item = History.Pop(); Debug.Log($"[ActionHistory] Undo {item.Type} handler={(item.Handler != null ? item.Handler.name : "null")}, remaining={History.Count}"); + // 如果遇到任何 Ping 的动作,就代表用户想重置整个包扎步骤 + if (item.Type == ActionType.PingFirst || item.Type == ActionType.PingSecond) + { + // 1. 持续弹栈,直到把所有 Ping 相关的记录都清理掉 + while (History.Count > 0 && (History.Peek().Type == ActionType.PingFirst || History.Peek().Type == ActionType.PingSecond)) + { + History.Pop(); + } + + // 2. 将场景里的所有 Ping 彻底重置 + var allPings = Object.FindObjectsOfType(true); + foreach (var p in allPings) + { + if (p.chanraoObject != null) p.chanraoObject.SetActive(false); + + // pingIndex 为 0 的通常是第一个出现的物体 (ping.004) + if (p.pingIndex == 0) + { + p.gameObject.SetActive(true); + p.ResetState(); + } + else + { + p.UndoShow(); // 其他的全部隐藏 + } + } + + // 3. 将 UI 的 Ping 进度清零 + var sm = Object.FindObjectOfType(); + if (sm != null) sm.ResetPingStep(); + + return true; + } + if (item.Type == ActionType.Shose) { var h = item.Handler as ShoseClickHandler; @@ -42,32 +76,6 @@ public static class ActionHistory var h = item.Handler as ChanraoTuibuHandler; if (h != null) h.ResetState(); } - else if (item.Type == ActionType.PingSecond) - { - var h = item.Handler as PingClickHandler; - if (h != null) h.UndoSecondClick(); - - // 撤销对 UI 步骤的影响 - var sm = Object.FindObjectOfType(); - if (sm != null) sm.DecrementPingStep(); - } - else if (item.Type == ActionType.PingFirst) - { - var h = item.Handler as PingClickHandler; - if (h != null) - { - if (h.nextPing != null) h.nextPing.SetActive(false); - else - { - var allPings = Object.FindObjectsOfType(); - foreach (var p in allPings) { if (p != h) p.UndoShow(); } - } - h.ResetState(); - } - - var sm = Object.FindObjectOfType(); - if (sm != null) sm.DecrementPingStep(); - } else if (item.Type == ActionType.Woman) { var sm = Object.FindObjectOfType();