From ea913c85d0e630761bc66a51612bc4c833c24908 Mon Sep 17 00:00:00 2001 From: yangbear Date: Thu, 9 Jul 2026 06:14:48 +0800 Subject: [PATCH] fix: stabilize ping undo state and prevent negative ping steps --- Assets/Scripts/Core/StepManager.cs | 2 +- Assets/Scripts/Core/UndoManager.cs | 1 + .../Scripts/Interaction/PingClickHandler.cs | 22 ++++++++++--------- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/Assets/Scripts/Core/StepManager.cs b/Assets/Scripts/Core/StepManager.cs index 06d7165..ad99986 100644 --- a/Assets/Scripts/Core/StepManager.cs +++ b/Assets/Scripts/Core/StepManager.cs @@ -221,7 +221,7 @@ public class StepManager : MonoBehaviour public void DecrementPingStep() { - _pingStepIndex--; + _pingStepIndex = Mathf.Max(0, _pingStepIndex - 1); Debug.Log($"StepManager: Ping撤销 -> {_pingStepIndex}"); OnStepChanged?.Invoke(_pingStepIndex); } diff --git a/Assets/Scripts/Core/UndoManager.cs b/Assets/Scripts/Core/UndoManager.cs index d05cffc..b9eea2a 100644 --- a/Assets/Scripts/Core/UndoManager.cs +++ b/Assets/Scripts/Core/UndoManager.cs @@ -30,6 +30,7 @@ public static class ActionHistory { 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.Shose) { diff --git a/Assets/Scripts/Interaction/PingClickHandler.cs b/Assets/Scripts/Interaction/PingClickHandler.cs index 5814bc9..e966e1e 100644 --- a/Assets/Scripts/Interaction/PingClickHandler.cs +++ b/Assets/Scripts/Interaction/PingClickHandler.cs @@ -6,10 +6,9 @@ public class PingClickHandler : MonoBehaviour public int pingIndex; private MeshRenderer _modelRenderer, _outlineMesh; private bool _modelShown; - private float _lastClickTime; - private bool _isFinished; + private bool _isBlinking; - public bool CanBeClicked() { return !_isFinished; } + public bool CanBeClicked() { return _isBlinking; } void OnEnable() { @@ -19,7 +18,7 @@ public class PingClickHandler : MonoBehaviour if (GetComponent() == null) gameObject.AddComponent().radius = 0.5f; CreateOutlineMesh(); _modelShown = false; - _isFinished = false; + _isBlinking = true; StopAllCoroutines(); StartCoroutine(BlinkOutline()); } @@ -59,9 +58,7 @@ public class PingClickHandler : MonoBehaviour public void PerformClick() { - if (Time.time - _lastClickTime < 0.3f) return; // 防连击 - _lastClickTime = Time.time; - if (_isFinished) return; + if (!_isBlinking) return; // 防止重复点击 foreach (var c in Object.FindObjectsOfType()) { @@ -73,6 +70,7 @@ public class PingClickHandler : MonoBehaviour if (!_modelShown) { _modelShown = true; + _isBlinking = false; ActionHistory.Push(ActionHistory.ActionType.PingFirst, this); StopAllCoroutines(); if (_modelRenderer != null) _modelRenderer.enabled = true; @@ -127,12 +125,16 @@ public class PingClickHandler : MonoBehaviour } public void ReEnableBorder() { _isBlinking = true; if (_outlineMesh != null) { _outlineMesh.enabled = true; StopAllCoroutines(); StartCoroutine(BlinkOutline()); } } + public void UndoSecondClick() { if (chanraoObject != null) chanraoObject.SetActive(false); ShowSelf(); _modelShown = true; - _isFinished = false; + _isBlinking = true; + if (_outlineMesh != null) _outlineMesh.enabled = true; + StopAllCoroutines(); + StartCoroutine(BlinkOutline()); } public void UndoShow() { HideSelf(); } @@ -140,7 +142,7 @@ public class PingClickHandler : MonoBehaviour { foreach (var r in GetComponentsInChildren(true)) r.enabled = false; var col = GetComponent(); if (col != null) col.enabled = false; - _isFinished = true; + _isBlinking = false; StopAllCoroutines(); } @@ -154,7 +156,7 @@ public class PingClickHandler : MonoBehaviour public void ResetState() { _modelShown = false; - _isFinished = false; + _isBlinking = true; if (_modelRenderer != null) _modelRenderer.enabled = false; // 隐藏自身模型 foreach (var r in GetComponentsInChildren(true)) { if (_outlineMesh != null && r == _outlineMesh) continue; r.enabled = false; }