From 511ef8a61a561258027b5f2d6e34561341d733f6 Mon Sep 17 00:00:00 2001 From: yangbear Date: Wed, 1 Jul 2026 21:47:46 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20PlayHomeBg/PlayExperimentBg=E7=94=A8Asse?= =?UTF-8?q?tDatabase.LoadAssetAtPath=E5=85=9C=E5=BA=95=E5=8A=A0=E8=BD=BDcl?= =?UTF-8?q?ip?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit SerializerField引用因脚本重编译频繁丢失,改为代码中硬加载音频文件路径 不再依赖Inspector赋值 --- Assets/Scripts/UI/PageController.cs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/Assets/Scripts/UI/PageController.cs b/Assets/Scripts/UI/PageController.cs index d4762e9..c161f7c 100644 --- a/Assets/Scripts/UI/PageController.cs +++ b/Assets/Scripts/UI/PageController.cs @@ -323,7 +323,11 @@ public class PageController : MonoBehaviour private void PlayHomeBg() { - if (_homeBgClip == null) return; + 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.enabled = true; _bgAudioSource.clip = _homeBgClip; @@ -351,7 +355,11 @@ public class PageController : MonoBehaviour private void PlayExperimentBg() { StopBgMusic(); - if (_experimentBgClip == null) return; + 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.enabled = true; _bgAudioSource.clip = _experimentBgClip;