diff --git a/Assets/Scripts/Audio/AudioManager.cs b/Assets/Scripts/Audio/AudioManager.cs index 1a8a949..8eccad4 100644 --- a/Assets/Scripts/Audio/AudioManager.cs +++ b/Assets/Scripts/Audio/AudioManager.cs @@ -131,15 +131,7 @@ public class AudioManager : MonoBehaviour c2.enabled = false; c3.enabled = true; - // 在这里把 woman 的 IsCheck 设为 true - var woman = GameObject.Find("woman"); - if (woman != null) - { - var anim = woman.GetComponent(); - if (anim != null) anim.SetBool("IsCheck", true); - } - - float duration = 1.0f; +float duration = 1.0f; float elapsed = 0f; while (elapsed < duration) diff --git a/Assets/Scripts/Core/StepManager.cs b/Assets/Scripts/Core/StepManager.cs index f358c6b..65b0925 100644 --- a/Assets/Scripts/Core/StepManager.cs +++ b/Assets/Scripts/Core/StepManager.cs @@ -154,6 +154,17 @@ public class StepManager : MonoBehaviour private bool TryClickActiveHandler() { + var point2s = Object.FindObjectsOfType(); + foreach (var p in point2s) + { + if (p.gameObject.activeInHierarchy && p.CanBeClicked()) + { + Debug.LogError($"====== StepManager: 模拟点击了 {p.name}! ======"); + p.PerformClick(); + return true; + } + } + var touches = Object.FindObjectsOfType(); System.Array.Sort(touches, (a, b) => string.Compare(a.name, b.name)); foreach (var t in touches) diff --git a/Assets/Scripts/Core/UndoManager.cs b/Assets/Scripts/Core/UndoManager.cs index 0d9ac55..85fdd35 100644 --- a/Assets/Scripts/Core/UndoManager.cs +++ b/Assets/Scripts/Core/UndoManager.cs @@ -5,6 +5,7 @@ public static class ActionHistory { public enum ActionType { + Point2, Shose, ChanraoTuibu, PingFirst, @@ -62,7 +63,12 @@ public static class ActionHistory return true; } - if (item.Type == ActionType.Shose) + if (item.Type == ActionType.Point2) + { + var h = item.Handler as Point2ClickHandler; + if (h != null) h.ResetState(); + } + else if (item.Type == ActionType.Shose) { var h = item.Handler as ShoseClickHandler; if (h != null) h.ResetState(); diff --git a/Assets/Scripts/Interaction/Point2ClickHandler.cs b/Assets/Scripts/Interaction/Point2ClickHandler.cs new file mode 100644 index 0000000..d6e6e73 --- /dev/null +++ b/Assets/Scripts/Interaction/Point2ClickHandler.cs @@ -0,0 +1,98 @@ +using UnityEngine; + +public class Point2ClickHandler : MonoBehaviour +{ + public GameObject nextObject; // This will be Shose + private MeshRenderer _outlineMesh; + private bool _clicked; + + public bool CanBeClicked() { return !_clicked; } + + void OnEnable() + { + if (GetComponent() == null) gameObject.AddComponent().radius = 0.5f; + foreach (var r in GetComponentsInChildren(true)) r.enabled = false; + CreateOutlineMesh(); + _clicked = false; + StopAllCoroutines(); + StartCoroutine(BlinkOutline()); + } + + void CreateOutlineMesh() + { + if (_outlineMesh != null) return; + var mf = GetComponent(); + if (mf == null) mf = GetComponentInChildren(); + if (mf == null || mf.sharedMesh == null) return; + var shader = Shader.Find("Custom/OutlineUnlit"); + if (shader == null) return; + var mat = new Material(shader); + mat.SetColor("_OutlineColor", new Color(0.2f, 0.5f, 1f, 1f)); + mat.SetColor("_MainColor", new Color(0, 0, 0, 0)); + mat.SetFloat("_OutlineWidth", OutlineConfig.Width); + var go = new GameObject("Outline"); + go.transform.SetParent(transform, false); + go.AddComponent().sharedMesh = mf.sharedMesh; + _outlineMesh = go.AddComponent(); + _outlineMesh.material = mat; + } + + System.Collections.IEnumerator BlinkOutline() + { + if (_outlineMesh != null) _outlineMesh.enabled = true; + yield return new WaitForSeconds(0.4f); + while (true) { if (_outlineMesh != null) _outlineMesh.enabled = !_outlineMesh.enabled; yield return new WaitForSeconds(0.4f); } + } + + void OnMouseDown() + { + PerformClick(); + } + + public void PerformClick() + { + if (_clicked) return; + _clicked = true; + + Debug.Log("[Point2Click] ★ 被点击 ★"); + ActionHistory.Push(ActionHistory.ActionType.Point2, this); + + StopAllCoroutines(); + if (_outlineMesh != null) _outlineMesh.enabled = false; + + var woman = GameObject.Find("woman"); + if (woman != null) + { + var anim = woman.GetComponent(); + if (anim != null) + { + anim.SetBool("IsCheck", true); + } + } + + if (nextObject != null) nextObject.SetActive(true); + gameObject.SetActive(false); + } + + public void ResetState() + { + _clicked = false; + if (_outlineMesh != null) _outlineMesh.enabled = true; + + if (nextObject != null) nextObject.SetActive(false); + + var woman = GameObject.Find("woman"); + if (woman != null) + { + var anim = woman.GetComponent(); + if (anim != null) + { + anim.SetBool("IsCheck", false); + } + } + + gameObject.SetActive(true); + StopAllCoroutines(); + StartCoroutine(BlinkOutline()); + } +} diff --git a/Assets/Scripts/Interaction/ShoseClickHandler.cs b/Assets/Scripts/Interaction/ShoseClickHandler.cs index 6bbc0a6..5441274 100644 --- a/Assets/Scripts/Interaction/ShoseClickHandler.cs +++ b/Assets/Scripts/Interaction/ShoseClickHandler.cs @@ -207,7 +207,7 @@ public class ShoseClickHandler : MonoBehaviour if (anim != null) { anim.SetBool("isCrouch", false); - anim.SetBool("IsCheck", false); + } // 移回原位?如果最初在某个位置,PageController里有记录。这里只要不穿帮即可 diff --git a/Assets/Scripts/UI/PageController.cs b/Assets/Scripts/UI/PageController.cs index a4f89e2..cdeed42 100644 --- a/Assets/Scripts/UI/PageController.cs +++ b/Assets/Scripts/UI/PageController.cs @@ -420,14 +420,21 @@ public class PageController : MonoBehaviour } // ------------------------------ - // 实验刚开始,立刻激活鞋子,不等语音播完 + // 实验刚开始,立刻激活point2,不等语音播完 var shose = GameObject.Find("Shose"); if (shose == null) { - // 如果被禁用了,找它的最顶层引用 var allTransforms = Resources.FindObjectsOfTypeAll(); foreach(var t in allTransforms) { if (t.parent == null && t.name == "Shose") { shose = t.gameObject; break; } } } + + var point2 = GameObject.Find("point2"); + if (point2 == null) + { + var allTransforms = Resources.FindObjectsOfTypeAll(); + foreach(var t in allTransforms) { if (t.name == "point2") { point2 = t.gameObject; break; } } + } + if (shose != null) { var h = shose.GetComponent(); @@ -443,8 +450,20 @@ public class PageController : MonoBehaviour } h.nextObject = chanraotuibu; } - shose.SetActive(true); - Debug.Log("PageController: 开场动画结束,Shose 已立刻激活"); + shose.SetActive(false); // 确保一开始隐藏 + } + + if (point2 != null) + { + var oldHandler = point2.GetComponent(); + if (oldHandler != null) Destroy(oldHandler); + + var h2 = point2.GetComponent(); + if (h2 == null) h2 = point2.AddComponent(); + if (h2.nextObject == null) h2.nextObject = shose; + + point2.SetActive(true); + Debug.Log("PageController: 开场动画结束,point2 已立刻激活"); } // 1. 强制播放第一句语音:“周围环境安全,我是救护志愿者,我可以帮助您吗”