2026-07-09 03:16:00 +08:00
|
|
|
using UnityEngine;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
|
|
|
|
public static class ActionHistory
|
|
|
|
|
{
|
|
|
|
|
public enum ActionType
|
|
|
|
|
{
|
2026-07-11 04:50:21 +08:00
|
|
|
Point2,
|
2026-07-09 03:16:00 +08:00
|
|
|
Shose,
|
|
|
|
|
ChanraoTuibu,
|
|
|
|
|
PingFirst,
|
|
|
|
|
PingSecond,
|
|
|
|
|
Woman
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class HistoryItem
|
|
|
|
|
{
|
|
|
|
|
public ActionType Type;
|
|
|
|
|
public MonoBehaviour Handler;
|
|
|
|
|
public int ExtraInt;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static Stack<HistoryItem> History = new Stack<HistoryItem>();
|
|
|
|
|
|
2026-07-09 03:23:41 +08:00
|
|
|
public static void Push(ActionType type, MonoBehaviour handler, int extra = 0)
|
|
|
|
|
{
|
|
|
|
|
History.Push(new HistoryItem { Type = type, Handler = handler, ExtraInt = extra });
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-09 03:16:00 +08:00
|
|
|
public static bool TryUndoLast()
|
|
|
|
|
{
|
|
|
|
|
if (History.Count == 0) return false;
|
|
|
|
|
var item = History.Pop();
|
2026-07-09 06:14:48 +08:00
|
|
|
Debug.Log($"[ActionHistory] Undo {item.Type} handler={(item.Handler != null ? item.Handler.name : "null")}, remaining={History.Count}");
|
2026-07-09 03:16:00 +08:00
|
|
|
|
2026-07-10 01:17:51 +08:00
|
|
|
if (item.Type == ActionType.PingFirst || item.Type == ActionType.PingSecond)
|
2026-07-09 16:51:57 +08:00
|
|
|
{
|
2026-07-10 01:17:51 +08:00
|
|
|
// 如果遇到任何 Ping 的动作,就代表用户想重置整个包扎步骤
|
|
|
|
|
while (History.Count > 0 && (History.Peek().Type == ActionType.PingFirst || History.Peek().Type == ActionType.PingSecond))
|
2026-07-09 18:28:08 +08:00
|
|
|
{
|
|
|
|
|
History.Pop();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var allPings = Object.FindObjectsOfType<PingClickHandler>(true);
|
|
|
|
|
foreach (var p in allPings)
|
|
|
|
|
{
|
|
|
|
|
if (p.chanraoObject != null) p.chanraoObject.SetActive(false);
|
2026-07-10 01:17:51 +08:00
|
|
|
|
|
|
|
|
if (p.pingIndex == 0)
|
|
|
|
|
{
|
|
|
|
|
p.gameObject.SetActive(true);
|
|
|
|
|
p.ResetState();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
p.UndoShow();
|
|
|
|
|
}
|
2026-07-09 18:28:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var sm = Object.FindObjectOfType<StepManager>();
|
2026-07-10 01:17:51 +08:00
|
|
|
if (sm != null) sm.SetPingStepIndex(0);
|
2026-07-09 18:28:08 +08:00
|
|
|
|
2026-07-09 16:51:57 +08:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-11 04:50:21 +08:00
|
|
|
if (item.Type == ActionType.Point2)
|
|
|
|
|
{
|
|
|
|
|
var h = item.Handler as Point2ClickHandler;
|
|
|
|
|
if (h != null) h.ResetState();
|
|
|
|
|
}
|
|
|
|
|
else if (item.Type == ActionType.Shose)
|
2026-07-09 03:16:00 +08:00
|
|
|
{
|
|
|
|
|
var h = item.Handler as ShoseClickHandler;
|
|
|
|
|
if (h != null) h.ResetState();
|
|
|
|
|
}
|
|
|
|
|
else if (item.Type == ActionType.ChanraoTuibu)
|
|
|
|
|
{
|
|
|
|
|
var h = item.Handler as ChanraoTuibuHandler;
|
|
|
|
|
if (h != null) h.ResetState();
|
|
|
|
|
}
|
|
|
|
|
else if (item.Type == ActionType.Woman)
|
|
|
|
|
{
|
|
|
|
|
var sm = Object.FindObjectOfType<StepManager>();
|
|
|
|
|
if (sm != null) sm.DecrementWomanStep();
|
|
|
|
|
|
|
|
|
|
// 隐藏下一个小球并恢复当前小球
|
|
|
|
|
var h = item.Handler as TouchPositionHandler;
|
|
|
|
|
if (h != null)
|
|
|
|
|
{
|
|
|
|
|
if (h.nextTouchObject != null) h.nextTouchObject.SetActive(false);
|
|
|
|
|
h.gameObject.SetActive(true);
|
|
|
|
|
var mr = h.GetComponent<MeshRenderer>();
|
|
|
|
|
if (mr != null) mr.enabled = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|