From fa380b2ea587151a2cc919cf01d187b67f3aa801 Mon Sep 17 00:00:00 2001 From: yangbear Date: Wed, 1 Jul 2026 21:56:12 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20AudioSource=E6=90=AC=E5=88=B0[Managers]+?= =?UTF-8?q?=E5=85=B3=E5=A4=9A=E4=BD=99AudioListener+=E8=B7=B3=E8=BF=87Fade?= =?UTF-8?q?InBg=E7=9B=B4=E8=AE=BE=E9=9F=B3=E9=87=8F0.5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - [Managers]是始终活跃的非UI/非摄像机物体,切换摄像机不影响 - 禁用camera2/camera3的AudioListener消除多Listener冲突 - 暂时跳过FadeInBg直接设vol=0.5排除淡入干扰 --- Assets/Scripts/UI/PageController.cs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/Assets/Scripts/UI/PageController.cs b/Assets/Scripts/UI/PageController.cs index f94aa41..2f9363c 100644 --- a/Assets/Scripts/UI/PageController.cs +++ b/Assets/Scripts/UI/PageController.cs @@ -50,12 +50,15 @@ public class PageController : MonoBehaviour Debug.Log("=== PageController 初始化开始 ==="); // 背景音乐 AudioSource - var mainCam = GameObject.Find("Main Camera"); - if (mainCam != null) { _bgAudioSource = mainCam.GetComponent(); if (_bgAudioSource == null) _bgAudioSource = mainCam.AddComponent(); } - else _bgAudioSource = gameObject.AddComponent(); + var mgr = GameObject.Find("[Managers]"); + if (mgr != null) { _bgAudioSource = mgr.AddComponent(); } + else { _bgAudioSource = gameObject.AddComponent(); } _bgAudioSource.loop = true; _bgAudioSource.playOnAwake = false; _bgAudioSource.spatialBlend = 0f; + // 关掉多余AudioListener(只留Main Camera的) + var cam2 = GameObject.Find("camera2"); if (cam2 != null) { var al = cam2.GetComponent(); if (al != null) al.enabled = false; } + var cam3 = GameObject.Find("camera3"); if (cam3 != null) { var al = cam3.GetComponent(); 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()