Files
VFSUnity/Assets/Scripts/Core/UndoManager.cs
T

84 lines
2.5 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 bool TryUndoLast()
{
if (History.Count == 0) return false;
var item = History.Pop();
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.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>();
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;
}
}