fix: StopBgMusic加enabled=false彻底禁用AudioSource防止后续恢复
- StopBgMusic: Stop后加s.enabled=false, 日志打印clip名 - PlayHomeBg/PlayExperimentBg: 播放前设enabled=true, 先停旧fade再开新 - FadeInBg从volume=0渐入
This commit is contained in:
@@ -325,8 +325,11 @@ public class PageController : MonoBehaviour
|
||||
{
|
||||
if (_homeBgClip == null) return;
|
||||
if (_bgAudioSource == null) { _bgAudioSource = gameObject.AddComponent<AudioSource>(); _bgAudioSource.loop = true; _bgAudioSource.playOnAwake = false; }
|
||||
_bgAudioSource.enabled = true;
|
||||
_bgAudioSource.clip = _homeBgClip;
|
||||
_bgAudioSource.volume = 0f;
|
||||
_bgAudioSource.Play();
|
||||
if (_fadeCoroutine != null) StopCoroutine(_fadeCoroutine);
|
||||
_fadeCoroutine = StartCoroutine(FadeInBg());
|
||||
Debug.Log("PageController: 播放首页背景音乐");
|
||||
}
|
||||
@@ -335,7 +338,13 @@ public class PageController : MonoBehaviour
|
||||
{
|
||||
if (_fadeCoroutine != null) { StopCoroutine(_fadeCoroutine); _fadeCoroutine = null; }
|
||||
var allSrcs = gameObject.GetComponents<AudioSource>();
|
||||
foreach (var s in allSrcs) { if (s != null) s.Stop(); }
|
||||
foreach (var s in allSrcs)
|
||||
{
|
||||
if (s == null) continue;
|
||||
Debug.Log("PageController: 停止AudioSource clip=" + (s.clip != null ? s.clip.name : "null"));
|
||||
s.Stop();
|
||||
s.enabled = false;
|
||||
}
|
||||
Debug.Log("PageController: 停止背景音乐 (共" + allSrcs.Length + "个AudioSource)");
|
||||
}
|
||||
|
||||
@@ -344,8 +353,11 @@ public class PageController : MonoBehaviour
|
||||
StopBgMusic();
|
||||
if (_experimentBgClip == null) return;
|
||||
if (_bgAudioSource == null) { _bgAudioSource = gameObject.AddComponent<AudioSource>(); _bgAudioSource.loop = true; _bgAudioSource.playOnAwake = false; }
|
||||
_bgAudioSource.enabled = true;
|
||||
_bgAudioSource.clip = _experimentBgClip;
|
||||
_bgAudioSource.volume = 0f;
|
||||
_bgAudioSource.Play();
|
||||
if (_fadeCoroutine != null) StopCoroutine(_fadeCoroutine);
|
||||
_fadeCoroutine = StartCoroutine(FadeInBg());
|
||||
Debug.Log("PageController: 播放实验背景音乐");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user