From 9730f684db422b54a4b7beea28d6eb229934b3b2 Mon Sep 17 00:00:00 2001
From: yyl <yyl>
Date: 星期四, 04 十二月 2025 10:40:39 +0800
Subject: [PATCH] 125 战斗 修复音效播放完没有把isPlaying标为true导致回收失败的问题

---
 Main/System/Battle/Sound/BattleSoundManager.cs |   32 ++++++++++++++++++++++----------
 1 files changed, 22 insertions(+), 10 deletions(-)

diff --git a/Main/System/Battle/Sound/BattleSoundManager.cs b/Main/System/Battle/Sound/BattleSoundManager.cs
index de14247..8e211b5 100644
--- a/Main/System/Battle/Sound/BattleSoundManager.cs
+++ b/Main/System/Battle/Sound/BattleSoundManager.cs
@@ -84,7 +84,6 @@
         {
             return;
         }
-        
         PlaySound(audioId, pitchControl);
     }
     
@@ -132,10 +131,10 @@
         {
             source.pitch = 1.0f;
         }
-
         
-        // 鎾斁闊虫晥
-        source.PlayOneShot(audioClip);
+        // 璁剧疆闊抽鍓緫骞舵挱鏀撅紙浣跨敤 Play() 鑰屼笉鏄� PlayOneShot()锛屼互渚� isPlaying 鐘舵�佹纭級
+        source.clip = audioClip;
+        source.Play();
         
         // 鏍囪涓烘椿璺�
         if (!activeAudioSources.Contains(source))
@@ -198,15 +197,13 @@
         if (config == null)
             return null;
         
-        // ===== 淇锛氭坊鍔� Audio/ 鍓嶇紑 =====
-        AudioClip audioClip = BattleResManager.Instance.GetAudioResource(
-            "Audio/" + config.Folder,  // 鈫� 淇锛氭坊鍔� Audio/ 鍓嶇紑
-            config.Audio, 
-            battleField.guid
+        AudioClip audioClip = ResManager.Instance.LoadAsset<AudioClip>(
+            "Audio/" + config.Folder,
+            config.Audio,
+            false
         );
         
         return audioClip;
-        // ================================
     }
     
     /// <summary>
@@ -260,15 +257,28 @@
                 activeAudioSources.RemoveAt(i);
                 if (source != null)
                 {
+                    // 娓呯┖ clip 寮曠敤锛岄噴鏀惧唴瀛�
+                    source.clip = null;
                     audioSourcePool.Enqueue(source);
                 }
             }
         }
         
         // 娓呯悊 audioIdToSources 涓凡鍋滄鎾斁鐨� AudioSource
+        var keysToRemove = new List<int>();
         foreach (var kvp in audioIdToSources)
         {
             kvp.Value.RemoveAll(s => s == null || !s.isPlaying);
+            if (kvp.Value.Count == 0)
+            {
+                keysToRemove.Add(kvp.Key);
+            }
+        }
+        
+        // 绉婚櫎绌虹殑闊虫晥ID璁板綍
+        foreach (var key in keysToRemove)
+        {
+            audioIdToSources.Remove(key);
         }
     }
     
@@ -322,6 +332,8 @@
         {
             if (source != null)
             {
+                // 娓呯┖ clip 寮曠敤
+                source.clip = null;
                 audioSourcePool.Enqueue(source);
             }
         }

--
Gitblit v1.8.0