From 00bf2f3db6bb031a21fe0463b0a72b43377233bd Mon Sep 17 00:00:00 2001
From: yyl <yyl>
Date: 星期五, 13 三月 2026 11:38:47 +0800
Subject: [PATCH] 111 音效问题
---
Main/System/Battle/BattleField/BattleField.cs | 3 +++
Main/Common/EventName.cs | 4 ++++
Main/System/SystemSetting/SystemSetting.cs | 2 ++
Main/System/Battle/Sound/BattleSoundManager.cs | 38 ++++++++++++++++++++++++++++++++++++++
4 files changed, 47 insertions(+), 0 deletions(-)
diff --git a/Main/Common/EventName.cs b/Main/Common/EventName.cs
index ca978ab..dffe95c 100644
--- a/Main/Common/EventName.cs
+++ b/Main/Common/EventName.cs
@@ -20,4 +20,8 @@
public const string BATTLE_TIANZI_REFRESH_HP = "BATTLE_TIANZI_REFRESH_HP";//澶╁瓙鑰冮獙 鍒锋柊琛�閲�
public const string BATTLE_CLICK_HERO = "BATTLE_CLICK_HERO";//鐐瑰嚮鑻遍泟
+
+ public const string SOUND_EFFECT_VOLUME_CHANGE = "SOUND_EFFECT_VOLUME_CHANGE"; //闊虫晥澹伴煶澶у皬璋冩暣
+
+ public const string SOUND_EFFECT_MUTE_CHANGE = "SOUND_EFFECT_MUTE_CHANGE";// 闊虫晥闈欓煶璋冩暣
}
\ No newline at end of file
diff --git a/Main/System/Battle/BattleField/BattleField.cs b/Main/System/Battle/BattleField/BattleField.cs
index 1dae6a2..7de937b 100644
--- a/Main/System/Battle/BattleField/BattleField.cs
+++ b/Main/System/Battle/BattleField/BattleField.cs
@@ -144,6 +144,8 @@
battleEffectMgr.Init(this);
battleTweenMgr.Init(this);
recordPlayer.Init(this);
+ soundManager.Init();
+
if (blueTeamList == null)
{
@@ -351,6 +353,7 @@
battleEffectMgr.Release();
battleTweenMgr.Release();
recordPlayer.Release();
+ soundManager.Release();
// 娓呯悊姝讳骸澶勭悊璁板綍
processingDeathObjIds.Clear();
diff --git a/Main/System/Battle/Sound/BattleSoundManager.cs b/Main/System/Battle/Sound/BattleSoundManager.cs
index 33f3439..3d80805 100644
--- a/Main/System/Battle/Sound/BattleSoundManager.cs
+++ b/Main/System/Battle/Sound/BattleSoundManager.cs
@@ -53,6 +53,12 @@
UnityEditor.EditorApplication.pauseStateChanged += OnEditorPauseStateChanged;
#endif
}
+
+ public void Init()
+ {
+ EventBroadcast.Instance.AddListener<bool>(EventName.SOUND_EFFECT_MUTE_CHANGE, OnSoundEffectMuteChange);
+ EventBroadcast.Instance.AddListener<float>(EventName.SOUND_EFFECT_VOLUME_CHANGE, OnSoundEffectVolumeChange);
+ }
#if UNITY_EDITOR
/// <summary>
@@ -166,6 +172,7 @@
// 璁剧疆闊抽噺锛堜娇鐢ㄩ煶鏁堥煶閲忚缃級
source.volume = SystemSetting.Instance.GetSoundEffect();
+ source.mute = SystemSetting.Instance.GetMuteSoundEffect();
// 璁剧疆鎾斁閫熷害锛屼娇鐢╬itch鏉ユ帶鍒�
// pitch鑼冨洿寤鸿鍦�0.5-2.0涔嬮棿浠ラ伩鍏嶅け鐪�
@@ -358,6 +365,34 @@
}
}
+ private void OnSoundEffectMuteChange(bool isMute)
+ {
+ // Debug.Log($"<color=magenta>BattleSoundManager [{battleField.guid}]: OnSoundEffectMuteChange({isMute}) - 褰撳墠娲昏穬闊虫晥鏁�={activeAudioSources.Count}</color>");
+
+ // 鏇存柊鎵�鏈夋鍦ㄦ挱鏀剧殑闊虫晥鐨勯潤闊崇姸鎬�
+ foreach (var source in activeAudioSources)
+ {
+ if (source != null)
+ {
+ source.mute = isMute;
+ }
+ }
+ }
+
+ private void OnSoundEffectVolumeChange(float volume)
+ {
+ // Debug.Log($"<color=magenta>BattleSoundManager [{battleField.guid}]: OnSoundEffectVolumeChange({volume}) - 褰撳墠娲昏穬闊虫晥鏁�={activeAudioSources.Count}</color>");
+
+ // 鏇存柊鎵�鏈夋鍦ㄦ挱鏀剧殑闊虫晥鐨勯煶閲�
+ foreach (var source in activeAudioSources)
+ {
+ if (source != null)
+ {
+ source.volume = volume;
+ }
+ }
+ }
+
/// <summary>
/// 鐒︾偣鍙樺寲鍥炶皟
/// </summary>
@@ -458,6 +493,9 @@
battleField.OnSpeedRatioChange -= OnSpeedRatioChanged;
battleField.OnFocusChange -= OnFocusChanged;
}
+
+ EventBroadcast.Instance.RemoveListener<bool>(EventName.SOUND_EFFECT_MUTE_CHANGE, OnSoundEffectMuteChange);
+ EventBroadcast.Instance.RemoveListener<float>(EventName.SOUND_EFFECT_VOLUME_CHANGE, OnSoundEffectVolumeChange);
#if UNITY_EDITOR
// 鍙栨秷璁㈤槄缂栬緫鍣ㄦ殏鍋滀簨浠�
diff --git a/Main/System/SystemSetting/SystemSetting.cs b/Main/System/SystemSetting/SystemSetting.cs
index fdc9e4f..94f1b4a 100644
--- a/Main/System/SystemSetting/SystemSetting.cs
+++ b/Main/System/SystemSetting/SystemSetting.cs
@@ -51,6 +51,7 @@
public void SetSoundEffect(float value)
{
LocalSave.SetFloat(SOUND_EFFECT_KEY, Mathf.Clamp01(value));
+ EventBroadcast.Instance.Broadcast(EventName.SOUND_EFFECT_VOLUME_CHANGE, value);
}
public float GetSoundEffect()
@@ -73,6 +74,7 @@
{
LocalSave.SetBool(MUTE_SOUND_EFFECT_KEY, _mute);
SoundPlayer.Instance.MuteSoundEffect(_mute);
+ EventBroadcast.Instance.Broadcast(EventName.SOUND_EFFECT_MUTE_CHANGE, _mute);
}
public bool GetMuteSoundEffect()
--
Gitblit v1.8.0