Fix ping click handler resetting logic properly dividing phase 1 and phase 2

This commit is contained in:
yangbear
2026-07-09 18:28:08 +08:00
parent c0edd71a56
commit 243b0f2c29
4 changed files with 63 additions and 13 deletions
+6
View File
@@ -218,6 +218,12 @@ public class StepManager : MonoBehaviour
Debug.Log($"StepManager: Ping步进 -> {_pingStepIndex} (ping{pingIndex} second={secondClick})");
OnStepChanged?.Invoke(_pingStepIndex);
}
public void SetPingStepIndex(int index)
{
_pingStepIndex = index;
Debug.Log($"StepManager: Ping彻底重置 -> {index}");
}
public void DecrementPingStep()
{
+26 -9
View File
@@ -32,22 +32,40 @@ public static class ActionHistory
var item = History.Pop();
Debug.Log($"[ActionHistory] Undo {item.Type} handler={(item.Handler != null ? item.Handler.name : "null")}, remaining={History.Count}");
// 如果遇到任何 Ping 的动作,就代表用户想重置整个包扎步骤
if (item.Type == ActionType.PingFirst || item.Type == ActionType.PingSecond)
if (item.Type == ActionType.PingSecond)
{
// 1. 持续弹栈,直到把所有 Ping 相关的记录都清理掉
while (History.Count > 0 && (History.Peek().Type == ActionType.PingFirst || History.Peek().Type == ActionType.PingSecond))
// 如果在包扎(第二阶段),则重置所有的包扎纱布,退回到所有骨折点发光的状态
while (History.Count > 0 && History.Peek().Type == ActionType.PingSecond)
{
History.Pop();
}
var allPings = Object.FindObjectsOfType<PingClickHandler>(true);
foreach (var p in allPings)
{
if (p.chanraoObject != null) p.chanraoObject.SetActive(false);
p.gameObject.SetActive(true);
p.ReEnableBorder();
}
var sm = Object.FindObjectOfType<StepManager>();
if (sm != null) sm.SetPingStepIndex(8); // 退回到 4 个底模已确认的状态 (Ping 阶段的第一半结束)
return true;
}
else if (item.Type == ActionType.PingFirst)
{
// 如果在定位(第一阶段),则重置所有的定位,退回到只有第一个点发光的状态
while (History.Count > 0 && History.Peek().Type == ActionType.PingFirst)
{
History.Pop();
}
// 2. 将场景里的所有 Ping 彻底重置
var allPings = Object.FindObjectsOfType<PingClickHandler>(true);
foreach (var p in allPings)
{
if (p.chanraoObject != null) p.chanraoObject.SetActive(false);
// pingIndex 为 0 的通常是第一个出现的物体 (ping.004)
if (p.pingIndex == 0)
{
p.gameObject.SetActive(true);
@@ -55,13 +73,12 @@ public static class ActionHistory
}
else
{
p.UndoShow(); // 其他的全部隐藏
p.UndoShow();
}
}
// 3. 将 UI 的 Ping 进度清零
var sm = Object.FindObjectOfType<StepManager>();
if (sm != null) sm.ResetPingStep();
if (sm != null) sm.SetPingStepIndex(0);
return true;
}
@@ -99,7 +99,7 @@ public class ChanraoTuibuHandler : MonoBehaviour
var smr = GetComponent<SkinnedMeshRenderer>(); if (smr != null) smr.enabled = false;
foreach (var r in GetComponentsInChildren<Renderer>(true)) { if (_outlineMesh != null && r == _outlineMesh) continue; r.enabled = false; }
if (_outlineMesh != null) _outlineMesh.enabled = true;
if (nextObject != null) nextObject.SetActive(false);
if (nextObject != null) { nextObject.SetActive(false); var p = nextObject.GetComponent<PingClickHandler>(); if (p != null) p.UndoShow(); }
StopAllCoroutines();
StartCoroutine(BlinkOutline());
}
+30 -3
View File
@@ -84,11 +84,18 @@ public class PingClickHandler : MonoBehaviour
var allPings = Object.FindObjectsOfType<PingClickHandler>();
foreach (var p in allPings)
{
p.ReEnableBorder();
// 只有未被包扎过的 ping 才能重新亮起边框
if (p._modelShown)
{
p.ReEnableBorder();
}
}
Debug.Log($"[PingClick] {name} 是最后一个 ping,所有边框已重新激活!");
}
Debug.Log($"[PingClick] {name} 模型显示, 激活 {nextPing?.name}");
if (nextPing != null) Debug.Log($"[PingClick] {name} 模型显示, 激活 {nextPing.name}");
else Debug.Log($"[PingClick] {name} 模型显示, 激活下一个");
var sm = FindObjectOfType<StepManager>();
if (sm != null) sm.RecordPingStep(pingIndex, false);
}
@@ -124,7 +131,27 @@ public class PingClickHandler : MonoBehaviour
}
}
public void ReEnableBorder() { _isBlinking = true; if (_outlineMesh != null) { _outlineMesh.enabled = true; StopAllCoroutines(); StartCoroutine(BlinkOutline()); } }
public void ReEnableBorder()
{
// 如果它已经被隐藏(包扎完毕),则不应该重新激活边框!
var col = GetComponent<Collider>();
if (col != null && !col.enabled) return;
_isBlinking = true;
if (_outlineMesh != null)
{
_outlineMesh.enabled = true;
StopAllCoroutines();
StartCoroutine(BlinkOutline());
}
}
public void DisableBorder()
{
_isBlinking = false;
if (_outlineMesh != null) _outlineMesh.enabled = false;
StopAllCoroutines();
}
public void UndoSecondClick()
{