From efce2422b8a676eb181a87410d04e8d0286b55de Mon Sep 17 00:00:00 2001 From: yangbear Date: Wed, 1 Jul 2026 22:10:30 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=88=A0=E9=99=A4PageController?= =?UTF-8?q?=E4=B8=AD=E6=89=80=E6=9C=89=E6=97=A7=E9=9F=B3=E9=A2=91=E6=AD=BB?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=E2=80=94=E5=8F=AA=E7=95=99BGMController?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 旧PlayHomeBg/PlayExperimentBg/StopBgMusic/FadeInBg/PlayWomanAudioSequence 和对应字段全部删除,避免与BGMController静态方法共存 --- Assets/Scripts/UI/PageController.cs | 63 ----------------------------- 1 file changed, 63 deletions(-) diff --git a/Assets/Scripts/UI/PageController.cs b/Assets/Scripts/UI/PageController.cs index e193840..d4fcad4 100644 --- a/Assets/Scripts/UI/PageController.cs +++ b/Assets/Scripts/UI/PageController.cs @@ -321,73 +321,10 @@ public class PageController : MonoBehaviour #endregion [Header("=== 音频 ===")] - [SerializeField] private AudioClip _homeBgClip; - [SerializeField] private AudioClip _experimentBgClip; - [SerializeField] private AudioClip[] _womanClips; - private AudioSource _bgAudioSource; - private Coroutine _fadeCoroutine; - private void PlayHomeBg() - { - if (_homeBgClip == null) { -#if UNITY_EDITOR - _homeBgClip = UnityEditor.AssetDatabase.LoadAssetAtPath("Assets/Audio/homeBackgroundMusic.mp3"); -#endif - if (_homeBgClip == null) return; } - if (_bgAudioSource == null) { _bgAudioSource = gameObject.AddComponent(); _bgAudioSource.loop = true; _bgAudioSource.playOnAwake = false; - _bgAudioSource.spatialBlend = 0f; } - _bgAudioSource.enabled = true; - _bgAudioSource.clip = _homeBgClip; - _bgAudioSource.volume = 0.5f; - _bgAudioSource.Play(); - Debug.Log("PageController: 播放首页背景音乐 vol=0.5 isPlaying=" + _bgAudioSource.isPlaying + " clip=" + (_bgAudioSource.clip!=null?_bgAudioSource.clip.name:"null")); - } - private void StopBgMusic() - { - if (_fadeCoroutine != null) { StopCoroutine(_fadeCoroutine); _fadeCoroutine = null; } - var allSrcs = gameObject.GetComponents(); - foreach (var s in allSrcs) - { - if (s == null) continue; - Debug.Log("PageController: 停止AudioSource clip=" + (s.clip != null ? s.clip.name : "null")); - s.Stop(); - } Debug.Log("PageController: 停止背景音乐 (共" + allSrcs.Length + "个AudioSource)"); } - private void PlayExperimentBg() - { - StopBgMusic(); - if (_experimentBgClip == null) { -#if UNITY_EDITOR - _experimentBgClip = UnityEditor.AssetDatabase.LoadAssetAtPath("Assets/Audio/backgroundMusic.mp3"); -#endif - if (_experimentBgClip == null) return; } - if (_bgAudioSource == null) { _bgAudioSource = gameObject.AddComponent(); _bgAudioSource.loop = true; _bgAudioSource.playOnAwake = false; - _bgAudioSource.spatialBlend = 0f; } - _bgAudioSource.enabled = true; - _bgAudioSource.clip = _experimentBgClip; - _bgAudioSource.volume = 0f; - _bgAudioSource.Play(); - if (_fadeCoroutine != null) StopCoroutine(_fadeCoroutine); - _fadeCoroutine = StartCoroutine(FadeInBg()); - Debug.Log("PageController: 播放实验背景音乐"); - } - private System.Collections.IEnumerator FadeInBg(float duration = 1.5f) - { - if (_bgAudioSource == null) yield break; - float targetVolume = _bgAudioSource.volume > 0.01f ? _bgAudioSource.volume : 0.5f; - Debug.Log("PageController: FadeInBg 目标音量=" + targetVolume + " spatialBlend=" + _bgAudioSource.spatialBlend); - _bgAudioSource.volume = 0f; - float elapsed = 0f; - while (elapsed < duration) - { - elapsed += Time.deltaTime; - if (_bgAudioSource != null) _bgAudioSource.volume = Mathf.Lerp(0f, targetVolume, elapsed / duration); - yield return null; - } if (_bgAudioSource != null) _bgAudioSource.volume = targetVolume; - } -}