From a174ff42f9b28ad17c64d53ae32118a728eb9209 Mon Sep 17 00:00:00 2001 From: Tungdv Date: Fri, 15 May 2026 20:23:46 +0700 Subject: [PATCH] fix: Update UI dlg setting. --- .../ModelRenderer/Art/music/AudioMixer.mixer | 13 +- .../PerfectWorld/Prefab/UI/DlgSetting.prefab | 20 ++- .../Scripts/Common/AutoInitializer.cs | 7 + .../PerfectWorld/Scripts/MainFiles/EC_Game.cs | 125 +++++++++++++++--- .../Scripts/UI/Dialogs/Setting/DlgSetting.cs | 49 +++++++ .../UI/Dialogs/Setting/SettingInterface.cs | 82 ++++++++++-- .../UI/Dialogs/Setting/SettingSound.cs | 52 ++++++-- .../UI/Dialogs/Setting/SliderController.cs | 42 +++--- 8 files changed, 328 insertions(+), 62 deletions(-) diff --git a/Assets/ModelRenderer/Art/music/AudioMixer.mixer b/Assets/ModelRenderer/Art/music/AudioMixer.mixer index 3ea5da9c16..efe8d433e8 100644 --- a/Assets/ModelRenderer/Art/music/AudioMixer.mixer +++ b/Assets/ModelRenderer/Art/music/AudioMixer.mixer @@ -15,7 +15,15 @@ AudioMixerController: m_SuspendThreshold: -80 m_EnableSuspend: 1 m_UpdateMode: 0 - m_ExposedParameters: [] + m_ExposedParameters: + - guid: c70051188a2b45d47913547284bd20c9 + name: Embien + - guid: e6047e4635949884d8c295c97f0fce16 + name: Master + - guid: efca7bbb62585cc4b9af42bd7a4d8fc7 + name: Music + - guid: 1f9dd418cef5b684e8e38e42f4bb5011 + name: SFX m_AudioMixerGroupViews: - guids: - 6c7ceeaecc4101f428a095a7c22f80b6 @@ -69,7 +77,8 @@ AudioMixerSnapshotController: m_Name: Snapshot m_AudioMixer: {fileID: 24100000} m_SnapshotID: b262f163ad71db94abd9bf7edbb8700c - m_FloatValues: {} + m_FloatValues: + e6047e4635949884d8c295c97f0fce16: 0 m_TransitionOverrides: {} --- !u!243 &217038053835239290 AudioMixerGroupController: diff --git a/Assets/PerfectWorld/Prefab/UI/DlgSetting.prefab b/Assets/PerfectWorld/Prefab/UI/DlgSetting.prefab index da9ebb0a2d..5a9f0ee227 100644 --- a/Assets/PerfectWorld/Prefab/UI/DlgSetting.prefab +++ b/Assets/PerfectWorld/Prefab/UI/DlgSetting.prefab @@ -2220,7 +2220,7 @@ MonoBehaviour: m_EditorClassIdentifier: m_Material: {fileID: 0} m_Color: {r: 1, g: 1, b: 1, a: 1} - m_RaycastTarget: 1 + m_RaycastTarget: 0 m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0} m_Maskable: 1 m_OnCullStateChanged: @@ -2248,9 +2248,12 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 6683dd582fa268c45af1ece39633a804, type: 3} m_Name: m_EditorClassIdentifier: - txt_level_of_foresight: {fileID: 6815914334339467742} - txt_level_of_distance_npc_and_mst: {fileID: 6757030218926432192} - txt_level_of_distance_player_other: {fileID: 7832569378395798648} + slideCtrlViewDistance: {fileID: 8696581003082592840} + slideCtrlViewDistanceNPC: {fileID: 7374187120158384910} + slideCtrlViewDistanceEP: {fileID: 7472743271469780325} + tog_shadow: {fileID: 7259619490849805827} + tog_fog: {fileID: 651538557502335558} + tog_fullResolution: {fileID: 4715089688479236368} --- !u!1 &2318400620048361636 GameObject: m_ObjectHideFlags: 0 @@ -4924,6 +4927,8 @@ MonoBehaviour: tab_unactive: {fileID: 21300000, guid: 7639c755994ee114e9a7e89a404e3e7b, type: 3} activeTextColor: {r: 1, g: 1, b: 1, a: 1} inactiveTextColor: {r: 0.8078432, g: 0.70980394, b: 0.4784314, a: 1} + settingSoundCtrl: {fileID: 434286385280809297} + settingGraphicCtrl: {fileID: 8600430431389761751} --- !u!1 &5199199209685304065 GameObject: m_ObjectHideFlags: 0 @@ -5420,7 +5425,7 @@ MonoBehaviour: m_EditorClassIdentifier: m_Material: {fileID: 0} m_Color: {r: 1, g: 1, b: 1, a: 1} - m_RaycastTarget: 1 + m_RaycastTarget: 0 m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0} m_Maskable: 1 m_OnCullStateChanged: @@ -5462,6 +5467,9 @@ MonoBehaviour: txt_level_of_bgm: {fileID: 3978261999845214409} txt_level_of_sfx: {fileID: 284675133552538515} txt_level_of_master: {fileID: 7313494243364841233} + slideCtrlBgrMusic: {fileID: 6513137742691945821} + slideCtrlSFX: {fileID: 8468446591860041645} + slideCtrlMaster: {fileID: 8903301988286719733} --- !u!1 &5328116772109506526 GameObject: m_ObjectHideFlags: 0 @@ -7778,12 +7786,12 @@ RectTransform: m_ConstrainProportionsScale: 0 m_Children: - {fileID: 3036543998602838576} - - {fileID: 4557984836195278630} - {fileID: 8038141400472399988} - {fileID: 2519067213881106736} - {fileID: 6578534598388793505} - {fileID: 8529560139773339323} - {fileID: 3317306654959440989} + - {fileID: 4557984836195278630} m_Father: {fileID: 3172616695210653156} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0.5, y: 0.5} diff --git a/Assets/PerfectWorld/Scripts/Common/AutoInitializer.cs b/Assets/PerfectWorld/Scripts/Common/AutoInitializer.cs index c81e944db7..8687facfb5 100644 --- a/Assets/PerfectWorld/Scripts/Common/AutoInitializer.cs +++ b/Assets/PerfectWorld/Scripts/Common/AutoInitializer.cs @@ -1,5 +1,6 @@ using BrewMonster.Network; using System; +using System.Collections; using System.Collections.Generic; using System.Reflection; using UnityEngine; @@ -18,6 +19,12 @@ namespace BrewMonster DontDestroyOnLoad(gameObject); } + private IEnumerator Start() + { + yield return null; + EC_Game.InitSettingAudio(); + } + void OnDestroy() { BMLogger.Log("AutoInitializer: OnDestroy called, disposing auto initializers"); diff --git a/Assets/PerfectWorld/Scripts/MainFiles/EC_Game.cs b/Assets/PerfectWorld/Scripts/MainFiles/EC_Game.cs index 60e5eaccb2..afa8116487 100644 --- a/Assets/PerfectWorld/Scripts/MainFiles/EC_Game.cs +++ b/Assets/PerfectWorld/Scripts/MainFiles/EC_Game.cs @@ -14,6 +14,7 @@ using UnityEngine.AddressableAssets; using UnityEngine.Rendering; using UnityEngine.Rendering.Universal; using UnityEngine.ResourceManagement.AsyncOperations; +using UnityEngine.UIElements; namespace BrewMonster.Network { @@ -655,12 +656,19 @@ namespace BrewMonster.Network public static void InitSetting() { - int index = PlayerPrefs.GetInt(keySettingViewDistance, defaultValue: 5); - m_viewDistance = GameRunConfigSO.GetViewDistanceCfg[index]; - index = PlayerPrefs.GetInt(keySettingViewDistanceNPC, defaultValue: 5); - m_viewDistanceNPC = GameRunConfigSO.GetViewDistanceNPCCfg[index]; - index = PlayerPrefs.GetInt(keySettingViewDistanceEP, defaultValue: 5); - m_viewDistanceEP = GameRunConfigSO.GetViewDistanceEPCfg[index]; + int index = PlayerPrefs.GetInt(keySettingViewDistance, defaultValue: 6); + m_viewDistance = GameRunConfigSO.GetViewDistanceCfg[index - 1]; + index = PlayerPrefs.GetInt(keySettingViewDistanceNPC, defaultValue: 6); + m_viewDistanceNPC = GameRunConfigSO.GetViewDistanceNPCCfg[index - 1]; + index = PlayerPrefs.GetInt(keySettingViewDistanceEP, defaultValue: 6); + m_viewDistanceEP = GameRunConfigSO.GetViewDistanceEPCfg[index - 1]; + } + + public static void InitSettingAudio() + { + SetVolumeBgrMusic(GetVolumeBgrMusic()); + SetVolumeSoundSFX(GetVolumeSoundSFX()); + SetVolumeSoundMaster(GetVolumeSoundMaster()); } public static ViewDistance GetSettingViewDistance() @@ -686,23 +694,78 @@ namespace BrewMonster.Network public static void SetSettingActiveShadow(bool value) { - + PlayerPrefs.SetInt(keySettingActiveShadow, value ? 1 : 0); + if (value) + { + + } + else + { + + } } public static void SetSettingActiveFullResolution(bool value) { - + PlayerPrefs.SetInt(keySettingActiveFullResolution, value ? 1 : 0); + if (value) + { + + } + else + { + + } + } + + public static void SetSettingActiveFog(bool value) + { + PlayerPrefs.SetInt(keySettingActiveFog, value ? 1 : 0); + RenderSettings.fog = value; + } + + public static void SetSettingViewDistance(int value) + { + PlayerPrefs.SetInt(keySettingViewDistance, value); + m_viewDistance = GameRunConfigSO.GetViewDistanceCfg[value - 1]; + } + + public static void SetSettingViewDistanceNPC(int value) + { + PlayerPrefs.SetInt(keySettingViewDistanceNPC, value); + m_viewDistanceNPC = GameRunConfigSO.GetViewDistanceNPCCfg[value - 1]; + } + + public static void SetSettingViewDistanceEP(int value) + { + PlayerPrefs.SetInt(keySettingViewDistanceEP, value); + m_viewDistanceEP = GameRunConfigSO.GetViewDistanceEPCfg[value - 1]; + } + + public static int GetValueSettingViewDistance() + { + return PlayerPrefs.GetInt(keySettingViewDistance, defaultValue: 6); + } + + public static int GetValueSettingViewDistanceNPC() + { + return PlayerPrefs.GetInt(keySettingViewDistanceNPC, defaultValue: 6); + } + + public static int GetValueSettingViewDistanceEP() + { + return PlayerPrefs.GetInt(keySettingViewDistanceEP, defaultValue: 6); } public static bool GetSettingActiveFullResolution() { - int index = PlayerPrefs.GetInt(keySettingActiveFullResolution, defaultValue: 1); + int index = PlayerPrefs.GetInt(keySettingActiveFullResolution, defaultValue: 6); return index == 1; } public static bool GetSettingActiveFog() { - int index = PlayerPrefs.GetInt(keySettingActiveFog, defaultValue: 1); + int index = PlayerPrefs.GetInt(keySettingActiveFog, defaultValue: 6); return index == 1; } @@ -727,6 +790,11 @@ namespace BrewMonster.Network return PlayerPrefs.GetInt(keySettingSoundMaster, 1) == 1; } + public static int GetVolumeSoundMaster() + { + return PlayerPrefs.GetInt(keySettingVolumeSoundMaster, 6); + } + public static void SetVolumeSoundMaster(int value) { bool isActive = GetActiveSoundMaster(); @@ -736,6 +804,11 @@ namespace BrewMonster.Network float dB = Mathf.Log10(value / 6) * 20; // setting sound is 6 GameRunConfigSO.GetAudioMixer.SetFloat(keyMaster, dB); } + else + { + float dB = Mathf.Log10(0.0001f) * 20; // setting sound is 6 + GameRunConfigSO.GetAudioMixer.SetFloat(keyMaster, dB); + } } public static void SetActiveSoundSFX(bool value) @@ -762,21 +835,31 @@ namespace BrewMonster.Network public static void SetVolumeSoundSFX(int value) { bool isActive = GetActiveSoundMaster() && GetActiveSoundSFX(); - PlayerPrefs.SetInt(keySettingVolumeSoundMaster, value); + PlayerPrefs.SetInt(keySettingVolumeSoundSFX, value); if (isActive) { - float dB = Mathf.Log10(value / 6) * 20; // setting sound is 6 + float dB = Mathf.Log10(value / 6f) * 20; // setting sound is 6 + GameRunConfigSO.GetAudioMixer.SetFloat(keySFX, dB); + } + else + { + float dB = Mathf.Log10(0.0001f) * 20; // setting sound is 6 GameRunConfigSO.GetAudioMixer.SetFloat(keySFX, dB); } } - public static void SetActiveSoundMusic(bool value) + public static int GetVolumeSoundSFX() + { + return PlayerPrefs.GetInt(keySettingVolumeSoundSFX, 6); + } + + public static void SetActiveBgrMusic(bool value) { PlayerPrefs.SetInt(keySettingBgrMusic, value ? 1 : 0); if (value) { float index = PlayerPrefs.GetInt(keySettingVolumeBgrMusic, defaultValue: 6); - float dB = Mathf.Log10(index / 6) * 20; // setting sound is 6 + float dB = Mathf.Log10(index / 6f) * 20; // setting sound is 6 GameRunConfigSO.GetAudioMixer.SetFloat(keyMusic, dB); } else @@ -794,12 +877,22 @@ namespace BrewMonster.Network public static void SetVolumeBgrMusic(int value) { bool isActive = GetActiveSoundMaster() && GetActiveBgrMusic(); - PlayerPrefs.SetInt(keySettingVolumeSoundMaster, value); + PlayerPrefs.SetInt(keySettingVolumeBgrMusic, value); if (isActive) { - float dB = Mathf.Log10(value / 6) * 20; // setting sound is 6 + float dB = Mathf.Log10(value / 6f) * 20; // setting sound is 6 GameRunConfigSO.GetAudioMixer.SetFloat(keyMusic, dB); } + else + { + float dB = Mathf.Log10(0.0001f) * 20; // setting sound is 6 + GameRunConfigSO.GetAudioMixer.SetFloat(keyMusic, dB); + } + } + + public static int GetVolumeBgrMusic() + { + return PlayerPrefs.GetInt(keySettingVolumeBgrMusic, 6); } #endregion diff --git a/Assets/PerfectWorld/Scripts/UI/Dialogs/Setting/DlgSetting.cs b/Assets/PerfectWorld/Scripts/UI/Dialogs/Setting/DlgSetting.cs index 60b772a5e1..9a715f4d46 100644 --- a/Assets/PerfectWorld/Scripts/UI/Dialogs/Setting/DlgSetting.cs +++ b/Assets/PerfectWorld/Scripts/UI/Dialogs/Setting/DlgSetting.cs @@ -1,3 +1,4 @@ +using BrewMonster.Network; using BrewMonster.UI; using System.Collections; using TMPro; @@ -31,6 +32,11 @@ namespace BrewMonster private Button[] tabButtons; + [SerializeField] private SettingSound settingSoundCtrl; + [SerializeField] private SettingInterface settingGraphicCtrl; + + int curTab = 1; + public override void Awake() { tabButtons = new[] @@ -49,6 +55,11 @@ namespace BrewMonster btn_setting.onClick.AddListener(OnBtnSetting); btn_sound.onClick.AddListener(OnBtnSound); btn_close.onClick.AddListener(OnBtnClose); + btn_confirm.onClick.AddListener(OnClickBtnConfirm); + + curTab = 1; + UpdateUITabs(); + OnBtnInterface(); } public override void OnDisable() @@ -58,11 +69,14 @@ namespace BrewMonster btn_setting.onClick.RemoveListener(OnBtnSetting); btn_sound.onClick.RemoveListener(OnBtnSound); btn_close.onClick.RemoveListener(OnBtnClose); + btn_confirm.onClick.RemoveListener(OnClickBtnConfirm); } private void OnBtnSystem() { SetActiveTab(btn_system); + curTab = 0; + UpdateUITabs(); } private void OnBtnInterface() @@ -70,11 +84,15 @@ namespace BrewMonster SetActiveTab(btn_interface); content_interface.SetActive(true); content_sound.SetActive(false); + curTab = 1; + UpdateUITabs(); } private void OnBtnSetting() { SetActiveTab(btn_setting); + curTab = 2; + UpdateUITabs(); } private void OnBtnSound() @@ -82,6 +100,8 @@ namespace BrewMonster SetActiveTab(btn_sound); content_interface.SetActive(false); content_sound.SetActive(true); + curTab = 3; + UpdateUITabs(); } private void SetActiveTab(Button activeButton) @@ -109,5 +129,34 @@ namespace BrewMonster { CECUIManager.Instance.HideCurrentUIInStack(); } + + private void OnClickBtnConfirm() + { + EC_Game.SetActiveSoundMaster(settingSoundCtrl.GetActiveSoundMaster()); + EC_Game.SetActiveSoundSFX(settingSoundCtrl.GetActiveSFX()); + EC_Game.SetActiveBgrMusic(settingSoundCtrl.GetActiveBgrMusic()); + + EC_Game.SetSettingActiveShadow(settingGraphicCtrl.GetValueToggleShadow()); + EC_Game.SetSettingActiveFullResolution(settingGraphicCtrl.GetValueToggleFullResolution()); + EC_Game.SetSettingActiveFog(settingGraphicCtrl.GetValueToggleFog()); + + EC_Game.SetVolumeBgrMusic(settingSoundCtrl.GetVolumeBgrMusic()); + EC_Game.SetVolumeSoundMaster(settingSoundCtrl.GetVolumeMaster()); + EC_Game.SetVolumeSoundSFX(settingSoundCtrl.GetVolumeSFX()); + + EC_Game.SetSettingViewDistance(settingGraphicCtrl.GetValueViewDistance()); + EC_Game.SetSettingViewDistanceEP(settingGraphicCtrl.GetValueViewDistanceEP()); + EC_Game.SetSettingViewDistanceNPC(settingGraphicCtrl.GetValueViewDistanceNPC()); + + OnBtnClose(); + } + + private void UpdateUITabs() + { + for(int i = 0; i < tabButtons.Length; i++) + { + tabButtons[i].image.sprite = (curTab == i) ? tab_active: tab_unactive; + } + } } } diff --git a/Assets/PerfectWorld/Scripts/UI/Dialogs/Setting/SettingInterface.cs b/Assets/PerfectWorld/Scripts/UI/Dialogs/Setting/SettingInterface.cs index c3cc3e7d98..dc48199612 100644 --- a/Assets/PerfectWorld/Scripts/UI/Dialogs/Setting/SettingInterface.cs +++ b/Assets/PerfectWorld/Scripts/UI/Dialogs/Setting/SettingInterface.cs @@ -1,6 +1,7 @@ using BrewMonster.Assets.PerfectWorld.Scripts.UI; using BrewMonster.Common; using BrewMonster.Managers; +using BrewMonster.Network; using BrewMonster.Scripts; using BrewMonster.Scripts.Managers; using BrewMonster.UI; @@ -19,27 +20,84 @@ namespace BrewMonster { public class SettingInterface : MonoBehaviour { - [Header("Slider Value Level")] - private float valueLevel1 = 0; - private float valueLevel2 = 0.194f; - private float valueLevel3 = 0.409f; - private float valueLevel4 = 0.603f; - private float valueLevel5 = 0.793f; - private float valueLevel6 = 1f; + [SerializeField] private SliderController slideCtrlViewDistance; + [SerializeField] private SliderController slideCtrlViewDistanceNPC; + [SerializeField] private SliderController slideCtrlViewDistanceEP; - [Header("slider Text Level")] - [SerializeField] private TextMeshProUGUI txt_level_of_foresight; - [SerializeField] private TextMeshProUGUI txt_level_of_distance_npc_and_mst; - [SerializeField] private TextMeshProUGUI txt_level_of_distance_player_other; + [SerializeField] private Toggle tog_shadow; + [SerializeField] private Toggle tog_fog; + [SerializeField] private Toggle tog_fullResolution; private void OnEnable() { - + UpdateUIPanel(); } private void OnDisable() { + tog_shadow.onValueChanged.RemoveAllListeners(); + tog_fog.onValueChanged.RemoveAllListeners(); + tog_fullResolution.onValueChanged.RemoveAllListeners(); + } + private void UpdateUIPanel() + { + tog_shadow.isOn = EC_Game.GetSettingActiveShadow(); + tog_fog.isOn = EC_Game.GetSettingActiveFog(); + tog_fullResolution.isOn = EC_Game.GetSettingActiveFullResolution(); + + tog_shadow.onValueChanged.AddListener(OnToggleShadowChange); + tog_fog.onValueChanged.AddListener(OnToggleFog); + tog_fullResolution.onValueChanged.AddListener(OnToggleFullResolution); + + slideCtrlViewDistance.InitSlide(EC_Game.GetValueSettingViewDistance()); + slideCtrlViewDistanceNPC.InitSlide(EC_Game.GetValueSettingViewDistanceNPC()); + slideCtrlViewDistanceEP.InitSlide(EC_Game.GetValueSettingViewDistanceEP()); + } + + private void OnToggleShadowChange(bool value) + { + tog_shadow.isOn = value; + } + + private void OnToggleFog(bool value) + { + tog_fog.isOn = value; + } + + private void OnToggleFullResolution(bool value) + { + tog_fullResolution.isOn = value; + } + + public int GetValueViewDistance() + { + return slideCtrlViewDistance.GetValueCurrentSlide(); + } + + public int GetValueViewDistanceEP() + { + return slideCtrlViewDistanceEP.GetValueCurrentSlide(); + } + + public int GetValueViewDistanceNPC() + { + return slideCtrlViewDistanceNPC.GetValueCurrentSlide(); + } + + public bool GetValueToggleShadow() + { + return tog_shadow.isOn; + } + + public bool GetValueToggleFog() + { + return tog_fog.isOn; + } + + public bool GetValueToggleFullResolution() + { + return tog_fullResolution.isOn; } } } diff --git a/Assets/PerfectWorld/Scripts/UI/Dialogs/Setting/SettingSound.cs b/Assets/PerfectWorld/Scripts/UI/Dialogs/Setting/SettingSound.cs index d8777062db..be6cc1ebe4 100644 --- a/Assets/PerfectWorld/Scripts/UI/Dialogs/Setting/SettingSound.cs +++ b/Assets/PerfectWorld/Scripts/UI/Dialogs/Setting/SettingSound.cs @@ -1,6 +1,7 @@ using BrewMonster.Assets.PerfectWorld.Scripts.UI; using BrewMonster.Common; using BrewMonster.Managers; +using BrewMonster.Network; using BrewMonster.Scripts; using BrewMonster.Scripts.Managers; using BrewMonster.UI; @@ -43,14 +44,6 @@ namespace BrewMonster private Color textOnColor = new Color(0.96f, 0.84f, 0.61f); private Color textOffColor = new Color(0.6f, 0.6f, 0.6f); - [Header("Slider Value Level")] - private float valueLevel1 = 0; - private float valueLevel2 = 0.173f; - private float valueLevel3 = 0.393f; - private float valueLevel4 = 0.603f; - private float valueLevel5 = 0.797f; - private float valueLevel6 = 1f; - [Header("slider Text Level")] [SerializeField] private TextMeshProUGUI txt_level_of_bgm; [SerializeField] private TextMeshProUGUI txt_level_of_sfx; @@ -60,16 +53,26 @@ namespace BrewMonster private Coroutine sfxCoroutine; private Coroutine masterCoroutine; + [SerializeField] private SliderController slideCtrlBgrMusic; + [SerializeField] private SliderController slideCtrlSFX; + [SerializeField] private SliderController slideCtrlMaster; private void OnEnable() { + tog_bgm.isOn = EC_Game.GetActiveBgrMusic(); UpdateSwitchInstant(tog_bgm, handle_bmg, txt_bgm); + tog_sfx.isOn = EC_Game.GetActiveSoundSFX(); UpdateSwitchInstant(tog_sfx, handle_sfx, txt_sfx); + tog_master.isOn = EC_Game.GetActiveSoundMaster(); UpdateSwitchInstant(tog_master, handle_master, txt_master); tog_bgm.onValueChanged.AddListener(OnBgmChanged); tog_sfx.onValueChanged.AddListener(OnSfxChanged); tog_master.onValueChanged.AddListener(OnMasterChanged); + + slideCtrlBgrMusic.InitSlide(EC_Game.GetVolumeBgrMusic()); + slideCtrlSFX.InitSlide(EC_Game.GetVolumeSoundSFX()); + slideCtrlMaster.InitSlide(EC_Game.GetVolumeSoundMaster()); } private void OnDisable() @@ -87,6 +90,7 @@ namespace BrewMonster } bgmCoroutine = StartCoroutine(SlideSwitchCoroutine(tog_bgm, handle_bmg, txt_bgm)); // TODO: Add logic to change BGM volume or mute state + //EC_Game.SetActiveBgrMusic(isOn); } private void OnSfxChanged(bool isOn) @@ -97,6 +101,7 @@ namespace BrewMonster } sfxCoroutine = StartCoroutine(SlideSwitchCoroutine(tog_sfx, handle_sfx, txt_sfx)); // TODO: Add logic to change SFX volume or mute state + //EC_Game.SetActiveSoundSFX(isOn); } private void OnMasterChanged(bool isOn) @@ -107,6 +112,7 @@ namespace BrewMonster } masterCoroutine = StartCoroutine(SlideSwitchCoroutine(tog_master, handle_master, txt_master)); // TODO: Add logic to change Master volume or mute state + //EC_Game.SetActiveSoundMaster(isOn); } private void UpdateSwitchInstant(Toggle toggle, RectTransform handle, TextMeshProUGUI statusText) @@ -183,5 +189,35 @@ namespace BrewMonster statusText.rectTransform.anchoredPosition = new Vector2(textTargetX, statusText.rectTransform.anchoredPosition.y); } } + + public int GetVolumeBgrMusic() + { + return slideCtrlBgrMusic.GetValueCurrentSlide(); + } + + public int GetVolumeSFX() + { + return slideCtrlSFX.GetValueCurrentSlide(); + } + + public int GetVolumeMaster() + { + return slideCtrlMaster.GetValueCurrentSlide(); + } + + public bool GetActiveBgrMusic() + { + return tog_bgm.isOn; + } + + public bool GetActiveSFX() + { + return tog_sfx.isOn; + } + + public bool GetActiveSoundMaster() + { + return tog_master.isOn; + } } } diff --git a/Assets/PerfectWorld/Scripts/UI/Dialogs/Setting/SliderController.cs b/Assets/PerfectWorld/Scripts/UI/Dialogs/Setting/SliderController.cs index 56c9f95ae1..3a1c0bdf97 100644 --- a/Assets/PerfectWorld/Scripts/UI/Dialogs/Setting/SliderController.cs +++ b/Assets/PerfectWorld/Scripts/UI/Dialogs/Setting/SliderController.cs @@ -1,6 +1,7 @@ using BrewMonster.Assets.PerfectWorld.Scripts.UI; using BrewMonster.Common; using BrewMonster.Managers; +using BrewMonster.Network; using BrewMonster.Scripts; using BrewMonster.Scripts.Managers; using BrewMonster.UI; @@ -25,17 +26,17 @@ namespace BrewMonster public Slider slider; public TextMeshProUGUI sliderValueText; - [Header("Action Event")] - private UnityEvent[] levelEvents = new UnityEvent[6]; + //[Header("Action Event")] + //private UnityEvent[] levelEvents = new UnityEvent[6]; - private int currentLevel = -1; + //private int currentLevel = -1; + //Action OnSlideValueChange = null; private void OnEnable() { if(slider != null) { slider.onValueChanged.AddListener(OnSliderValueChange); - UpdateLevelFromSlider(); } } @@ -47,6 +48,12 @@ namespace BrewMonster } } + public void InitSlide(int curlevel) + { + slider.value = curlevel; + UpdateSliderText(curlevel); + } + private void OnSliderValueChange(float value) { UpdateLevelFromSlider(); @@ -58,12 +65,6 @@ namespace BrewMonster return; int level = GetLevelFromValue(slider.value); - if(level != currentLevel) - { - currentLevel = level; - Invoke(level); - } - UpdateSliderText(level); } @@ -82,15 +83,20 @@ namespace BrewMonster sliderValueText.text = $"Mức {level}"; } - public void Invoke(int level) + public int GetValueCurrentSlide() { - int index = level - 1; - if(index < 0 || index >= levelEvents.Length) - { - return; - } - - levelEvents[index]?.Invoke(); + return (int)slider.value; } + + //public void Invoke(int level) + //{ + // int index = level - 1; + // if(index < 0 || index >= levelEvents.Length) + // { + // return; + // } + + // levelEvents[index]?.Invoke(); + //} } }