using UnityEngine; /// /// 挂在 touchArray 子球体上。球体用双Pass膨胀描边shader(Custom/OutlineUnlit), /// 闪烁提示用户点击。点击后移动到对应位置并顺序显示下一个。 /// public class TouchPositionHandler : MonoBehaviour { public Transform targetPosition; public GameObject womanObject; public GameObject nextTouchObject; public AudioClip voiceClip; private MeshRenderer _meshRenderer; private void Start() { _meshRenderer = GetComponent(); StartCoroutine(BlinkMesh()); } private void OnEnable() { _meshRenderer = GetComponent(); if (_meshRenderer != null) { _meshRenderer.enabled = true; var col = GetComponent(); if (col == null) { var sc = gameObject.AddComponent(); sc.radius = 0.3f; } // 只显示描边,填充透明 var mat = _meshRenderer.material; if (mat != null && mat.HasProperty("_MainColor")) { var c = mat.GetColor("_MainColor"); c.a = 0f; mat.SetColor("_MainColor", c); } } StopAllCoroutines(); StartCoroutine(BlinkMesh()); } private System.Collections.IEnumerator BlinkMesh() { while (true) { if (_meshRenderer != null) _meshRenderer.enabled = !_meshRenderer.enabled; yield return new WaitForSeconds(0.4f); } } private void OnMouseDown() { Debug.Log($"[TouchPosition] {name}: 被点击"); if (womanObject != null && targetPosition != null) { womanObject.transform.position = targetPosition.position; womanObject.transform.rotation = targetPosition.rotation; Debug.Log($"[TouchPosition] woman 移动到 {targetPosition.name}"); } if (voiceClip != null) { PlaySharedVoice(); Debug.Log($"[TouchPosition] 播放语音: {voiceClip.name}"); } // 点击point1时平滑切换到camera3 if (transform.GetSiblingIndex() == 0) StartCoroutine(SwitchToCamera3Smooth()); int stepIndex = transform.GetSiblingIndex() + 1; var sm = FindObjectOfType(); if (sm != null) sm.RecordWomanStep(stepIndex); // point1 点击后激活第一个 ping if (stepIndex == 1) { var mi = GameObject.Find("manInjury"); if (mi != null) { var ping4 = mi.transform.Find("ping.004"); if (ping4 != null) { ping4.gameObject.SetActive(true); Debug.Log("[TouchPosition] ping.004 已激活"); } FindObjectOfType()?.InitPingSteps(); } } StopAllCoroutines(); if (_meshRenderer != null) _meshRenderer.enabled = false; gameObject.SetActive(false); if (nextTouchObject != null) { nextTouchObject.SetActive(true); Debug.Log($"[TouchPosition] {name} → {nextTouchObject.name} 显示"); } } private static AudioSource _sharedVoice; private void PlaySharedVoice() { if (voiceClip == null) return; if (_sharedVoice == null) { var go = GameObject.Find("[Managers]"); if (go != null) _sharedVoice = go.AddComponent(); else { var g = new GameObject("SharedVoice"); _sharedVoice = g.AddComponent(); } } _sharedVoice.Stop(); _sharedVoice.clip = voiceClip; _sharedVoice.Play(); } System.Collections.IEnumerator SwitchToCamera3Smooth() { var black = GameObject.Find("BlackScreenPanel"); var blackImg = black != null ? black.GetComponent() : null; float duration = 0.8f; // 渐入黑 if (black != null && blackImg != null) { black.SetActive(true); for (float t = 0f; t < duration; t += Time.deltaTime) { blackImg.color = new Color(0, 0, 0, t / duration); yield return null; } blackImg.color = Color.black; } // 切换摄像机 var cam2 = GameObject.Find("camera2"); var cam3 = GameObject.Find("camera3"); if (cam2 != null) { var c = cam2.GetComponent(); if (c != null) c.enabled = false; } if (cam3 != null) { var c = cam3.GetComponent(); if (c != null) c.enabled = true; } Debug.Log("[TouchPosition] camera2→camera3 平滑切换完成"); yield return new WaitForSeconds(0.2f); // 渐出黑 if (black != null && blackImg != null) { for (float t = 0f; t < duration; t += Time.deltaTime) { blackImg.color = new Color(0, 0, 0, 1f - t / duration); yield return null; } blackImg.color = new Color(0, 0, 0, 0); black.SetActive(false); } } }