feat: group all ping steps into a single undo action per user request

This commit is contained in:
yangbear
2026-07-09 16:51:57 +08:00
parent ea913c85d0
commit c0edd71a56
2 changed files with 41 additions and 26 deletions
+7
View File
@@ -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--;
+34 -26
View File
@@ -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<PingClickHandler>(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<StepManager>();
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<StepManager>();
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<PingClickHandler>();
foreach (var p in allPings) { if (p != h) p.UndoShow(); }
}
h.ResetState();
}
var sm = Object.FindObjectOfType<StepManager>();
if (sm != null) sm.DecrementPingStep();
}
else if (item.Type == ActionType.Woman)
{
var sm = Object.FindObjectOfType<StepManager>();