feat: 音频系统重构 - bg音乐流程修复 + woman语音按点位播放

改动:
1. TouchPositionHandler新增voiceClip字段, 点击时播放对应语音
2. PageController.ShowPage: 首页播放homeBg
3. OnFixationSelected: StopBgMusic()(开场动画开始时停bg)
4. ActivateExperimentObjects: 移除PlayWomanAudioSequence, 保留PlayExperimentBg
5. 新增PlayHomeBg/StopBgMusic/PlayExperimentBg方法
6. 删除_audioManager冗余引用

流程:
首页→homeBg播 → 选固定方式→bg停 → 开场动画→实验bg播
woman语音1→点击point1播, 语音2→point2, 语音3→point3
This commit is contained in:
yangbear
2026-07-01 19:51:41 +08:00
parent 9548492391
commit 8dadc6a58d
14 changed files with 200 additions and 143 deletions
@@ -9,6 +9,7 @@ public class TouchPositionHandler : MonoBehaviour
public Transform targetPosition;
public GameObject womanObject;
public GameObject nextTouchObject;
public AudioClip voiceClip;
private MeshRenderer _meshRenderer;
@@ -37,7 +38,7 @@ public class TouchPositionHandler : MonoBehaviour
womanObject.transform.position = targetPosition.position;
womanObject.transform.rotation = targetPosition.rotation;
Debug.Log($"[TouchPosition] woman 移动到 {targetPosition.name}");
}
if (voiceClip != null) { var asrc = gameObject.AddComponent<AudioSource>(); asrc.PlayOneShot(voiceClip); Debug.Log("[TouchPosition] 播放语音: " + voiceClip.name); } }
// 通知 StepManager 记录步骤
int stepIndex = transform.GetSiblingIndex() + 1;
+32 -4
View File
@@ -122,7 +122,8 @@ public class PageController : MonoBehaviour
if (_uiManager != null)
_uiManager.enabled = (page == Page.Experiment);
// 背景音乐: 首页播 homeBg, 选固定方式时停, 实验启动时播 experimentBg
if (page == Page.Home) PlayHomeBg();
Debug.Log($"PageController(编辑器预览): 切换到 [{page}]");
}
#endif
@@ -140,7 +141,8 @@ public class PageController : MonoBehaviour
if (_experimentPanel != null) _experimentPanel.SetActive(page == Page.Experiment);
if (_uiManager != null) _uiManager.enabled = (page == Page.Experiment);
// 背景音乐: 首页播 homeBg, 选固定方式时停, 实验启动时播 experimentBg
if (page == Page.Home) PlayHomeBg();
// 背景音乐控制
if (page == Page.Home) PlayHomeBg();
else if (page != Page.Experiment) StopBgMusic();
@@ -261,7 +263,7 @@ public class PageController : MonoBehaviour
Debug.Log($"PageController: GameManager 已设置 Mode=[{gm.CurrentMode}] Fixation=[{gm.CurrentFixationMethod}]");
// 隐藏所有UI面板,准备播放片头动画
HideAllPages();
StopBgMusic(); HideAllPages();
// 找到 OpeningFlowController 播放片头动画
var openingFlow = FindObjectOfType<OpeningFlowController>();
@@ -304,7 +306,6 @@ public class PageController : MonoBehaviour
Debug.Log("PageController: [ActivateExperimentObjects] 显示实验物件");
PlayExperimentBg();
StartCoroutine(PlayWomanAudioSequence());
var allObjects = FindObjectsOfType<GameObject>(true);
foreach (var go in allObjects)
@@ -375,3 +376,30 @@ public class PageController : MonoBehaviour
[SerializeField] private AudioClip[] _womanClips;
private AudioSource _bgAudioSource;
}
private void PlayHomeBg()
{
if (_bgAudioSource == null) _bgAudioSource = gameObject.AddComponent<AudioSource>();
_bgAudioSource.loop = true;
_bgAudioSource.playOnAwake = false;
if (_homeBgClip != null && _bgAudioSource.clip != _homeBgClip)
{
_bgAudioSource.clip = _homeBgClip;
_bgAudioSource.Play();
Debug.Log("PageController: 播放首页背景音乐");
}
}
private void StopBgMusic()
{
if (_bgAudioSource != null && _bgAudioSource.isPlaying) { _bgAudioSource.Stop(); Debug.Log("PageController: 停止背景音乐"); }
}
private void PlayExperimentBg()
{
StopBgMusic();
if (_bgAudioSource == null) _bgAudioSource = gameObject.AddComponent<AudioSource>();
_bgAudioSource.loop = true;
_bgAudioSource.playOnAwake = false;
if (_experimentBgClip != null) { _bgAudioSource.clip = _experimentBgClip; _bgAudioSource.Play(); Debug.Log("PageController: 播放实验背景音乐"); }
}