fix: stabilize ping undo state and prevent negative ping steps
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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<Collider>() == null) gameObject.AddComponent<SphereCollider>().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<Camera>())
|
||||
{
|
||||
@@ -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<Renderer>(true)) r.enabled = false;
|
||||
var col = GetComponent<Collider>(); 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<Renderer>(true)) { if (_outlineMesh != null && r == _outlineMesh) continue; r.enabled = false; }
|
||||
|
||||
Reference in New Issue
Block a user