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()