fix: stabilize ping undo state and prevent negative ping steps

This commit is contained in:
yangbear
2026-07-09 06:14:48 +08:00
parent a9d97d4b17
commit ea913c85d0
3 changed files with 14 additions and 11 deletions
+12 -10
View File
@@ -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; }