yyl
6 天以前 7789222416b7f43b1b425e8048bb49b4b8b0685c
Main/System/Battle/Sound/BattleSoundManager.cs
@@ -46,7 +46,46 @@
            currentSpeedRatio = battleField.speedRatio;
            hasFocus = battleField.IsFocus();
        }
#if UNITY_EDITOR
        // 监听编辑器暂停事件
        UnityEditor.EditorApplication.pauseStateChanged -= OnEditorPauseStateChanged;
        UnityEditor.EditorApplication.pauseStateChanged += OnEditorPauseStateChanged;
#endif
    }
#if UNITY_EDITOR
    /// <summary>
    /// 编辑器暂停状态变化回调
    /// </summary>
    private void OnEditorPauseStateChanged(UnityEditor.PauseState pauseState)
    {
        if (pauseState == UnityEditor.PauseState.Paused)
        {
            BattleDebug.LogError($"<color=yellow>BattleSoundManager [{battleField.guid}]: 编辑器暂停,停止所有音效</color>");
            for (int i = activeAudioSources.Count - 1; i >= 0; i--)
            {
                var source = activeAudioSources[i];
                if (source != null)
                {
                    source.Stop();
                }
            }
        }
        else if (pauseState == UnityEditor.PauseState.Unpaused)
        {
            BattleDebug.LogError($"<color=green>BattleSoundManager [{battleField.guid}]: 编辑器恢复</color>");
            for (int i = activeAudioSources.Count - 1; i >= 0; i--)
            {
                var source = activeAudioSources[i];
                if (source != null)
                {
                    source.Play();
                }
            }
        }
    }
#endif
    
    /// <summary>
    /// 初始化音频源池
@@ -409,6 +448,11 @@
            battleField.OnFocusChange -= OnFocusChanged;
        }
        
#if UNITY_EDITOR
        // 取消订阅编辑器暂停事件
        UnityEditor.EditorApplication.pauseStateChanged -= OnEditorPauseStateChanged;
#endif
        StopAllSounds();
        
        // 销毁所有 AudioSource 组件