fix: resolve Next/Previous step and UI skipping bugs

This commit is contained in:
yangbear
2026-07-08 09:38:42 +08:00
parent 2018c6813e
commit a33435a827
9 changed files with 553 additions and 83 deletions
+144 -24
View File
@@ -124,12 +124,98 @@ public class StepManager : MonoBehaviour
public void NextStep()
{
// Woman 自由步进优先
if (_pingObjects != null && _pingObjects.Length > 0 && _pingStepIndex < _pingMaxStep) { PingStepNext(); return; }
if (_womanObject != null && _womanPositions != null) { WomanStepNext(); return; }
if (_activeSteps == null) return;
if (_currentStepIndex >= _activeSteps.Length - 1) { CompleteExperiment(); return; }
GoToStep(_currentStepIndex + 1);
Debug.LogError("====== StepManager: 接收到 NextStep 指令! ======");
// 首先尝试是否存在可以点击的 3D 物品,如果有,优先执行 3D 交互
if (TryClickActiveHandler())
{
Debug.Log("====== StepManager: 成功模拟 3D 物品点击,不进行常规的 NextStep 流程 ======");
return;
}
Debug.Log("====== StepManager: 未找到 3D 物品,执行常规 NextStep 流程 ======");
if (_activeSteps != null && _currentStepIndex < _activeSteps.Length - 1)
{
GoToStep(_currentStepIndex + 1);
}
else if (_activeSteps != null && _currentStepIndex == _activeSteps.Length - 1)
{
CompleteExperiment();
}
}
public void TryInteractCurrent3DStep()
{
Debug.Log("====== StepManager: 接收到 3D 自动交互指令 ======");
if (TryClickActiveHandler()) return;
Debug.Log("====== StepManager: 当前没有可自动交互的 3D 物品 ======");
}
private bool TryClickActiveHandler()
{
var touches = Object.FindObjectsOfType<TouchPositionHandler>();
System.Array.Sort(touches, (a, b) => string.Compare(a.name, b.name));
foreach (var t in touches)
{
if (t.gameObject.activeInHierarchy && t.CanBeClicked())
{
Debug.LogError($"====== StepManager: 模拟点击了 {t.name} ======");
t.PerformClick();
return true;
}
}
var shoses = Object.FindObjectsOfType<ShoseClickHandler>();
foreach (var h in shoses)
{
if (h.gameObject.activeInHierarchy && h.CanBeClicked())
{
Debug.LogError($"====== StepManager: 模拟点击了 {h.name} ======");
h.PerformClick();
return true;
}
}
var chanraos = Object.FindObjectsOfType<ChanraoTuibuHandler>();
foreach (var h in chanraos)
{
if (h.gameObject.activeInHierarchy && h.CanBeClicked())
{
Debug.LogError($"====== StepManager: 模拟点击了 {h.name} ======");
h.PerformClick();
return true;
}
}
var pings = Object.FindObjectsOfType<PingClickHandler>();
System.Array.Sort(pings, (a, b) => string.Compare(b.name, a.name));
foreach (var p in pings)
{
if (p.gameObject.activeInHierarchy && p.CanBeClicked())
{
Debug.LogError($"====== StepManager: 模拟点击了 {p.name} ======");
p.PerformClick();
return true;
}
}
return false;
}
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;
}
private void PingStepPrevious()
@@ -151,15 +237,33 @@ public class StepManager : MonoBehaviour
}
else
{
// Undo first click: hide current ping, show previous ping (if any)
// 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) h.UndoShow();
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();
}
}
// If going back to start, show ping.004
if (idx == 0 && _pingObjects != null && _pingObjects.Length > 0 && _pingObjects[0] != null)
_pingObjects[0].SetActive(true);
}
_pingStepIndex--;
Debug.Log($"StepManager: Ping撤销 -> {_pingStepIndex}");
@@ -215,12 +319,23 @@ public class StepManager : MonoBehaviour
public void PreviousStep()
{
// Woman 自由步进优先
if (_pingObjects != null && _pingObjects.Length > 0 && _pingStepIndex > 0) { PingStepPrevious(); return; }
if (_womanObject != null && _womanPositions != null) { WomanStepPrevious(); return; }
if (_activeSteps == null) return;
if (_currentStepIndex <= 0) return;
GoToStep(_currentStepIndex - 1);
Debug.LogError("====== StepManager: 接收到 PreviousStep 指令! ======");
// 如果尝试撤销 3D 交互成功,就不再回退 UI
if (TryUndoActiveHandler())
{
Debug.Log("====== StepManager: 成功撤销 3D 交互,不进行常规的 PreviousStep 流程 ======");
return;
}
if (_currentStepIndex > 0)
{
GoToStep(_currentStepIndex - 1);
}
else
{
Debug.LogWarning("====== StepManager: 已经是第一步,无法后退 ======");
}
}
public StepData GetCurrentStep()
@@ -290,15 +405,20 @@ public class StepManager : MonoBehaviour
if (mi == null) return;
_pingObjects = new GameObject[4];
_chanraoObjects = new GameObject[4];
for (int i = 1; i <= 4; i++)
var pings = Object.FindObjectsOfType<PingClickHandler>(true);
foreach (var p in pings)
{
string pn = "ping." + i.ToString("D3");
string cn = "chanrao." + i.ToString("D3");
var pt = mi.transform.Find(pn);
var ct = mi.transform.Find(cn);
if (pt != null) _pingObjects[i-1] = pt.gameObject;
if (ct != null) _chanraoObjects[i-1] = ct.gameObject;
if (p.pingIndex >= 0 && p.pingIndex < 4)
{
_pingObjects[p.pingIndex] = p.gameObject;
if (p.chanraoObject != null)
{
_chanraoObjects[p.pingIndex] = p.chanraoObject;
}
}
}
_pingStepIndex = 0;
Debug.Log("StepManager: Ping步进已初始化");
}