115 lines
3.6 KiB
C#
115 lines
3.6 KiB
C#
using UnityEngine;
|
|
using System.Collections.Generic;
|
|
|
|
public static class ActionHistory
|
|
{
|
|
public enum ActionType
|
|
{
|
|
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>();
|
|
|
|
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.PingSecond)
|
|
{
|
|
// 如果在包扎(第二阶段),则重置所有的包扎纱布,退回到所有骨折点发光的状态
|
|
while (History.Count > 0 && 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);
|
|
p.gameObject.SetActive(true);
|
|
p.ReEnableBorder();
|
|
}
|
|
|
|
var sm = Object.FindObjectOfType<StepManager>();
|
|
if (sm != null) sm.SetPingStepIndex(8); // 退回到 4 个底模已确认的状态 (Ping 阶段的第一半结束)
|
|
|
|
return true;
|
|
}
|
|
else if (item.Type == ActionType.PingFirst)
|
|
{
|
|
// 如果在定位(第一阶段),则重置所有的定位,退回到只有第一个点发光的状态
|
|
while (History.Count > 0 && History.Peek().Type == ActionType.PingFirst)
|
|
{
|
|
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);
|
|
|
|
return true;
|
|
}
|
|
|
|
if (item.Type == ActionType.Shose)
|
|
{
|
|
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;
|
|
}
|
|
}
|