feat: rewrite 3D step undo using an exact ActionHistory stack
This commit is contained in:
@@ -208,111 +208,9 @@ public class StepManager : MonoBehaviour
|
||||
|
||||
private bool TryUndoActiveHandler()
|
||||
{
|
||||
if (_pingStepIndex > 0 && _pingStepIndex <= _pingMaxStep)
|
||||
{
|
||||
if (_pingObjects == null) InitPingSteps();
|
||||
PingStepPrevious();
|
||||
return true;
|
||||
}
|
||||
if (_womanStepIndex > 0 && _womanStepIndex <= _womanMaxStep && _pingStepIndex == 0)
|
||||
{
|
||||
WomanStepPrevious();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return ActionHistory.TryUndoLast();
|
||||
}
|
||||
|
||||
private void PingStepPrevious()
|
||||
{
|
||||
if (_pingStepIndex <= 0) return;
|
||||
int idx = (_pingStepIndex - 1) / 2; // ping index (0-3, mapping to 004-001)
|
||||
bool wasSecond = (_pingStepIndex - 1) % 2 == 1; // true if was second click
|
||||
|
||||
if (wasSecond)
|
||||
{
|
||||
// Undo second click: hide chanrao, restore ping to first-click state
|
||||
if (_chanraoObjects != null && idx < _chanraoObjects.Length && _chanraoObjects[idx] != null)
|
||||
_chanraoObjects[idx].SetActive(false);
|
||||
if (_pingObjects != null && idx < _pingObjects.Length && _pingObjects[idx] != null)
|
||||
{
|
||||
var h = _pingObjects[idx].GetComponent<PingClickHandler>();
|
||||
if (h != null) h.UndoSecondClick();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Undo first click: reset current ping to blink state, and hide the next ping it spawned
|
||||
if (_pingObjects != null && idx < _pingObjects.Length && _pingObjects[idx] != null)
|
||||
{
|
||||
var h = _pingObjects[idx].GetComponent<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.gameObject != h.gameObject)
|
||||
{
|
||||
p.gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
// 重置自己到初始状态
|
||||
h.ResetState();
|
||||
}
|
||||
}
|
||||
}
|
||||
_pingStepIndex--;
|
||||
Debug.Log($"StepManager: Ping撤销 -> {_pingStepIndex}");
|
||||
OnStepChanged?.Invoke(_pingStepIndex);
|
||||
}
|
||||
|
||||
private void PingStepNext()
|
||||
{
|
||||
if (_pingStepIndex >= _pingMaxStep) return;
|
||||
int idx = _pingStepIndex / 2;
|
||||
bool isSecond = _pingStepIndex % 2 == 1;
|
||||
|
||||
if (!isSecond)
|
||||
{
|
||||
// Advance to first click: ensure ping is visible and in first-click state
|
||||
if (_pingObjects != null && idx < _pingObjects.Length && _pingObjects[idx] != null)
|
||||
{
|
||||
var ping = _pingObjects[idx];
|
||||
ping.SetActive(true);
|
||||
var h = ping.GetComponent<PingClickHandler>();
|
||||
if (h != null)
|
||||
{
|
||||
h.UndoSecondClick(); // Reset to first-click state
|
||||
// Trigger first click via reflection/method
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Advance to second click: show chanrao
|
||||
if (_chanraoObjects != null && idx < _chanraoObjects.Length && _chanraoObjects[idx] != null)
|
||||
_chanraoObjects[idx].SetActive(true);
|
||||
if (_pingObjects != null && idx < _pingObjects.Length && _pingObjects[idx] != null)
|
||||
{
|
||||
var h = _pingObjects[idx].GetComponent<PingClickHandler>();
|
||||
if (h != null) h.UndoShow();
|
||||
}
|
||||
// Show next ping for first click
|
||||
if (idx + 1 < 4 && _pingObjects != null && _pingObjects[idx+1] != null)
|
||||
_pingObjects[idx+1].SetActive(true);
|
||||
}
|
||||
_pingStepIndex++;
|
||||
Debug.Log($"StepManager: Ping前进 -> {_pingStepIndex}");
|
||||
OnStepChanged?.Invoke(_pingStepIndex);
|
||||
}
|
||||
|
||||
public void RecordPingStep(int pingIndex, bool secondClick)
|
||||
{
|
||||
@@ -321,6 +219,20 @@ public class StepManager : MonoBehaviour
|
||||
OnStepChanged?.Invoke(_pingStepIndex);
|
||||
}
|
||||
|
||||
public void DecrementPingStep()
|
||||
{
|
||||
_pingStepIndex--;
|
||||
Debug.Log($"StepManager: Ping撤销 -> {_pingStepIndex}");
|
||||
OnStepChanged?.Invoke(_pingStepIndex);
|
||||
}
|
||||
|
||||
public void DecrementWomanStep()
|
||||
{
|
||||
if (_womanStepIndex > 0) _womanStepIndex--;
|
||||
Debug.Log($"StepManager: Woman撤销 -> {_womanStepIndex}");
|
||||
OnStepChanged?.Invoke(_womanStepIndex);
|
||||
}
|
||||
|
||||
public void PreviousStep()
|
||||
{
|
||||
Debug.LogError("====== StepManager: 接收到 PreviousStep 指令! ======");
|
||||
@@ -429,25 +341,6 @@ public class StepManager : MonoBehaviour
|
||||
|
||||
public void RecordWomanStep(int newStepIndex) { _womanStepIndex = Mathf.Clamp(newStepIndex, 0, _womanMaxStep); Debug.Log($"StepManager: Woman步进 -> {_womanStepIndex}"); OnStepChanged?.Invoke(_womanStepIndex); }
|
||||
|
||||
private void WomanStepPrevious()
|
||||
{
|
||||
if (_womanStepIndex <= 0) return;
|
||||
_womanStepIndex--;
|
||||
MoveWomanToStep(_womanStepIndex);
|
||||
UpdateTouchVisibility(_womanStepIndex);
|
||||
Debug.Log($"StepManager: Woman撤销 -> {_womanStepIndex}");
|
||||
OnStepChanged?.Invoke(_womanStepIndex);
|
||||
}
|
||||
|
||||
private void WomanStepNext()
|
||||
{
|
||||
if (_womanStepIndex >= _womanMaxStep) return;
|
||||
_womanStepIndex++;
|
||||
MoveWomanToStep(_womanStepIndex);
|
||||
UpdateTouchVisibility(_womanStepIndex);
|
||||
Debug.Log($"StepManager: Woman前进 -> {_womanStepIndex}");
|
||||
OnStepChanged?.Invoke(_womanStepIndex);
|
||||
}
|
||||
|
||||
private void MoveWomanToStep(int step)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user