Files
VFSUnity/Assets/Scripts/Interaction/TouchPositionHandler.cs
T
yangbear f68e675022 fix: bg音乐缓入+语音打断+代码碎片清理
- PlayHomeBg/PlayExperimentBg 增加 FadeInBg 缓入协程(1.5s)
- TouchPositionHandler 使用静态共享 AudioSource 避免语音重叠
- 清理 PageController 中因多次编辑产生的代码碎片和括号混乱
2026-07-01 21:18:34 +08:00

87 lines
2.6 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using UnityEngine;
/// <summary>
/// 挂在 touchArray 子球体上。球体用双Pass膨胀描边shaderCustom/OutlineUnlit),
/// 闪烁提示用户点击。点击后移动到对应位置并顺序显示下一个。
/// </summary>
public class TouchPositionHandler : MonoBehaviour
{
public Transform targetPosition;
public GameObject womanObject;
public GameObject nextTouchObject;
public AudioClip voiceClip;
private MeshRenderer _meshRenderer;
private void Start()
{
_meshRenderer = GetComponent<MeshRenderer>();
StartCoroutine(BlinkMesh());
}
private void OnEnable()
{
_meshRenderer = GetComponent<MeshRenderer>();
if (_meshRenderer != null) _meshRenderer.enabled = true;
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}");
}
int stepIndex = transform.GetSiblingIndex() + 1;
var sm = FindObjectOfType<StepManager>();
if (sm != null) sm.RecordWomanStep(stepIndex);
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<AudioSource>();
else { var g = new GameObject("SharedVoice"); _sharedVoice = g.AddComponent<AudioSource>(); }
}
_sharedVoice.Stop();
_sharedVoice.clip = voiceClip;
_sharedVoice.Play();
}
}