129 lines
4.1 KiB
C#
129 lines
4.1 KiB
C#
using UnityEngine;
|
|
using System.Collections.Generic;
|
|
|
|
public static class ActionHistory
|
|
{
|
|
public enum ActionType
|
|
{
|
|
Point2,
|
|
Shose,
|
|
ChanraoTuibu,
|
|
PingFirst,
|
|
PingSecond,
|
|
Woman,
|
|
SplintPlank
|
|
}
|
|
|
|
public class HistoryItem
|
|
{
|
|
public ActionType Type;
|
|
public MonoBehaviour Handler;
|
|
public int ExtraInt;
|
|
}
|
|
|
|
public static Stack<HistoryItem> History = new Stack<HistoryItem>();
|
|
|
|
public static void Clear()
|
|
{
|
|
History.Clear();
|
|
Debug.Log("[ActionHistory] 已清空历史记录");
|
|
}
|
|
|
|
public static void Push(ActionType type, MonoBehaviour handler, int extra = 0)
|
|
{
|
|
History.Push(new HistoryItem { Type = type, Handler = handler, ExtraInt = extra });
|
|
}
|
|
|
|
public static bool TryUndoLast()
|
|
{
|
|
if (History.Count == 0) return false;
|
|
var item = History.Pop();
|
|
Debug.Log($"[ActionHistory] Undo {item.Type} handler={(item.Handler != null ? item.Handler.name : "null")}, remaining={History.Count}");
|
|
|
|
if (item.Type == ActionType.PingFirst || item.Type == ActionType.PingSecond)
|
|
{
|
|
var splintFlow = Object.FindObjectOfType<SplintPracticeFlowManager>();
|
|
if (splintFlow != null && splintFlow.IsActive)
|
|
{
|
|
splintFlow.ResetToFirstPingStage();
|
|
var splintStepManager = Object.FindObjectOfType<StepManager>();
|
|
if (splintStepManager != null) splintStepManager.SetPingStepIndex(0);
|
|
return true;
|
|
}
|
|
|
|
// 如果遇到任何 Ping 的动作,就代表用户想重置整个包扎步骤
|
|
while (History.Count > 0 && (History.Peek().Type == ActionType.PingFirst || History.Peek().Type == ActionType.PingSecond))
|
|
{
|
|
History.Pop();
|
|
}
|
|
|
|
var allPings = Object.FindObjectsOfType<PingClickHandler>(true);
|
|
foreach (var p in allPings)
|
|
{
|
|
if (p.chanraoObject != null) p.chanraoObject.SetActive(false);
|
|
|
|
if (p.pingIndex == 0)
|
|
{
|
|
p.gameObject.SetActive(true);
|
|
p.ResetState();
|
|
}
|
|
else
|
|
{
|
|
p.UndoShow();
|
|
}
|
|
}
|
|
|
|
var sm = Object.FindObjectOfType<StepManager>();
|
|
if (sm != null) sm.SetPingStepIndex(0);
|
|
|
|
var chanraotuibu = GameObject.Find("chanraotuibu");
|
|
if (chanraotuibu == null)
|
|
{
|
|
var mi = GameObject.Find("manInjury");
|
|
if (mi != null)
|
|
{
|
|
var t = mi.transform.Find("chanraotuibu");
|
|
if (t != null) chanraotuibu = t.gameObject;
|
|
}
|
|
}
|
|
if (chanraotuibu != null) chanraotuibu.SetActive(false);
|
|
|
|
return true;
|
|
}
|
|
|
|
if (item.Type == ActionType.Point2)
|
|
{
|
|
var h = item.Handler as Point2ClickHandler;
|
|
if (h != null) h.ResetState();
|
|
}
|
|
else if (item.Type == ActionType.Shose)
|
|
{
|
|
var h = item.Handler as ShoseClickHandler;
|
|
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;
|
|
}
|
|
}
|
|
else if (item.Type == ActionType.SplintPlank)
|
|
{
|
|
var h = item.Handler as SplintObjectClickHandler;
|
|
var flow = Object.FindObjectOfType<SplintPracticeFlowManager>();
|
|
if (flow != null && h != null) flow.UndoPlank(h);
|
|
else if (h != null) h.ResetState(true);
|
|
}
|
|
|
|
return true;
|
|
}
|
|
}
|