From ac156080196541b821427c12ecee831d076f4b9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E6=80=9D=E6=B5=B7?= <1464576565@qq.com> Date: Thu, 23 Apr 2026 19:11:50 +0800 Subject: [PATCH] =?UTF-8?q?[fix]=E4=BF=AE=E5=A4=8D=E9=9F=B3=E9=A2=91?= =?UTF-8?q?=E5=AF=B9=E8=B1=A1=E6=B1=A0=E9=94=80=E6=AF=81bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Runtime/Audio/AudioService.cs | 74 +++++++---------------------------- 1 file changed, 15 insertions(+), 59 deletions(-) diff --git a/Runtime/Audio/AudioService.cs b/Runtime/Audio/AudioService.cs index f7c7a6a..81f3436 100644 --- a/Runtime/Audio/AudioService.cs +++ b/Runtime/Audio/AudioService.cs @@ -50,6 +50,7 @@ namespace AlicizaX.Audio.Runtime private bool _enable = true; private bool _unityAudioDisabled; private bool _initialized; + private bool _isShuttingDown; private bool _ownsInstanceRoot; public AudioMixer AudioMixer => _audioMixer; @@ -96,65 +97,6 @@ namespace AlicizaX.Audio.Runtime } } - internal float MusicVolume - { - get => GetCategoryVolume(AudioType.Music); - set => SetCategoryVolume(AudioType.Music, value); - } - - internal float SoundVolume - { - get => GetCategoryVolume(AudioType.Sound); - set => SetCategoryVolume(AudioType.Sound, value); - } - - internal float UISoundVolume - { - get => GetCategoryVolume(AudioType.UISound); - set => SetCategoryVolume(AudioType.UISound, value); - } - - internal float VoiceVolume - { - get => GetCategoryVolume(AudioType.Voice); - set => SetCategoryVolume(AudioType.Voice, value); - } - - internal float AmbientVolume - { - get => GetCategoryVolume(AudioType.Ambient); - set => SetCategoryVolume(AudioType.Ambient, value); - } - - internal bool MusicEnable - { - get => GetCategoryEnable(AudioType.Music); - set => SetCategoryEnable(AudioType.Music, value); - } - - internal bool SoundEnable - { - get => GetCategoryEnable(AudioType.Sound); - set => SetCategoryEnable(AudioType.Sound, value); - } - - internal bool UISoundEnable - { - get => GetCategoryEnable(AudioType.UISound); - set => SetCategoryEnable(AudioType.UISound, value); - } - - internal bool VoiceEnable - { - get => GetCategoryEnable(AudioType.Voice); - set => SetCategoryEnable(AudioType.Voice, value); - } - - internal bool AmbientEnable - { - get => GetCategoryEnable(AudioType.Ambient); - set => SetCategoryEnable(AudioType.Ambient, value); - } protected override void OnInitialize() { } @@ -563,6 +505,17 @@ namespace AlicizaX.Audio.Runtime sourceObject.Source.transform.SetParent(_instanceRoot, false); } + if (_sourcePool == null) + { + return; + } + + //在服务拆卸期间 对象池可能已经释放了包装器 在音频完成释放自身引用之前 清除ObjectBase.Target + if (_isShuttingDown && sourceObject.Target == null) + { + return; + } + _sourcePool.Unspawn(sourceObject); } @@ -1177,6 +1130,7 @@ namespace AlicizaX.Audio.Runtime private void Shutdown(bool destroyRoot) { + _isShuttingDown = true; StopAll(false); for (int i = 0; i < _categories.Length; i++) @@ -1213,6 +1167,8 @@ namespace AlicizaX.Audio.Runtime { DestroyOwnedRoot(); } + + _isShuttingDown = false; } private void DestroyOwnedRoot()