fix: AudioSource搬到[Managers]+关多余AudioListener+跳过FadeInBg直设音量0.5

- [Managers]是始终活跃的非UI/非摄像机物体,切换摄像机不影响
- 禁用camera2/camera3的AudioListener消除多Listener冲突
- 暂时跳过FadeInBg直接设vol=0.5排除淡入干扰
This commit is contained in:
yangbear
2026-07-01 21:56:12 +08:00
parent 01ca708a43
commit fa380b2ea5
+8 -7
View File
@@ -50,12 +50,15 @@ public class PageController : MonoBehaviour
Debug.Log("=== PageController 初始化开始 ===");
// 背景音乐 AudioSource
var mainCam = GameObject.Find("Main Camera");
if (mainCam != null) { _bgAudioSource = mainCam.GetComponent<AudioSource>(); if (_bgAudioSource == null) _bgAudioSource = mainCam.AddComponent<AudioSource>(); }
else _bgAudioSource = gameObject.AddComponent<AudioSource>();
var mgr = GameObject.Find("[Managers]");
if (mgr != null) { _bgAudioSource = mgr.AddComponent<AudioSource>(); }
else { _bgAudioSource = gameObject.AddComponent<AudioSource>(); }
_bgAudioSource.loop = true;
_bgAudioSource.playOnAwake = false;
_bgAudioSource.spatialBlend = 0f;
// 关掉多余AudioListener(只留Main Camera的)
var cam2 = GameObject.Find("camera2"); if (cam2 != null) { var al = cam2.GetComponent<AudioListener>(); if (al != null) al.enabled = false; }
var cam3 = GameObject.Find("camera3"); if (cam3 != null) { var al = cam3.GetComponent<AudioListener>(); if (al != null) al.enabled = false; }
// 绑定首页按钮
if (_btnStart != null) { _btnStart.onClick.AddListener(OnStartClicked); Debug.Log("PageController: _btnStart 绑定成功"); }
@@ -335,11 +338,9 @@ public class PageController : MonoBehaviour
_bgAudioSource.spatialBlend = 0f; }
_bgAudioSource.enabled = true;
_bgAudioSource.clip = _homeBgClip;
_bgAudioSource.volume = 0f;
_bgAudioSource.volume = 0.5f;
_bgAudioSource.Play();
if (_fadeCoroutine != null) StopCoroutine(_fadeCoroutine);
_fadeCoroutine = StartCoroutine(FadeInBg());
Debug.Log("PageController: 播放首页背景音乐, isPlaying=" + _bgAudioSource.isPlaying + " clip=" + (_bgAudioSource.clip!=null?_bgAudioSource.clip.name:"null"));
Debug.Log("PageController: 播放首页背景音乐 vol=0.5 isPlaying=" + _bgAudioSource.isPlaying + " clip=" + (_bgAudioSource.clip!=null?_bgAudioSource.clip.name:"null"));
}
private void StopBgMusic()