From 7789222416b7f43b1b425e8048bb49b4b8b0685c Mon Sep 17 00:00:00 2001
From: yyl <yyl>
Date: 星期四, 11 十二月 2025 17:44:24 +0800
Subject: [PATCH] 125 战斗 切换到后台的战斗不播放任何声音

---
 Main/System/Battle/BaseBattleWin.cs            |    2 ++
 Main/System/Battle/Sound/BattleSoundManager.cs |   44 ++++++++++++++++++++++++++++++++++++++++++++
 Main/Component/UI/Effect/BattleEffectPlayer.cs |    4 ++--
 3 files changed, 48 insertions(+), 2 deletions(-)

diff --git a/Main/Component/UI/Effect/BattleEffectPlayer.cs b/Main/Component/UI/Effect/BattleEffectPlayer.cs
index 4883e23..5c89ea8 100644
--- a/Main/Component/UI/Effect/BattleEffectPlayer.cs
+++ b/Main/Component/UI/Effect/BattleEffectPlayer.cs
@@ -411,7 +411,7 @@
         Spine.Animation animation = spineAnimationState.Data.SkeletonData.Animations.First();
         spineAnimationState.SetAnimation(0, animation, effectConfig.isLoop != 0);
 
-        SoundPlayer.Instance.PlayUIAudio(effectConfig.audio);
+        // SoundPlayer.Instance.PlayUIAudio(effectConfig.audio);
 
     }
 
@@ -467,7 +467,7 @@
 
         blocker.onSortingChanged = OnSortingChanged;
 
-        SoundPlayer.Instance.PlayUIAudio(effectConfig.audio);
+        // SoundPlayer.Instance.PlayUIAudio(effectConfig.audio);
 
     }
 
diff --git a/Main/System/Battle/BaseBattleWin.cs b/Main/System/Battle/BaseBattleWin.cs
index b6e68ed..fce8ae1 100644
--- a/Main/System/Battle/BaseBattleWin.cs
+++ b/Main/System/Battle/BaseBattleWin.cs
@@ -65,6 +65,8 @@
         if (BattleManager.Instance.storyBattleField != null)
             BattleManager.Instance.storyBattleField.IsPause = false;
 
+        battleField?.SetFocus(false);
+
         if (battleField != null)
         {
             battleField.OnRoundChange -= OnRoundChange;
diff --git a/Main/System/Battle/Sound/BattleSoundManager.cs b/Main/System/Battle/Sound/BattleSoundManager.cs
index e538206..9ffa4c5 100644
--- a/Main/System/Battle/Sound/BattleSoundManager.cs
+++ b/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 缁勪欢

--
Gitblit v1.8.0