From 9d163fe992a427e8643f2f1d80d1dad2d918ce51 Mon Sep 17 00:00:00 2001 From: Lim0_C Date: Mon, 12 May 2025 09:22:01 +0900 Subject: [PATCH] =?UTF-8?q?DEG-136=20[Feat]=20=EC=82=AC=EC=9A=B4=EB=93=9C?= =?UTF-8?q?=20=EC=84=A4=EC=A0=95=20=EC=A0=80=EC=9E=A5=20=EB=B0=8F=20?= =?UTF-8?q?=EB=B6=88=EB=9F=AC=EC=98=A4=EA=B8=B0=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/LYM/Scripts/PlayerPrefsManager.cs | 31 +++++++++++++++++++ Assets/LYM/Scripts/PlayerPrefsManager.cs.meta | 11 +++++++ Assets/LYM/Scripts/SettingsPanelController.cs | 12 +++---- .../Scripts/Common/GameUtility/GameSound.cs | 25 ++++++++------- 4 files changed, 60 insertions(+), 19 deletions(-) create mode 100644 Assets/LYM/Scripts/PlayerPrefsManager.cs create mode 100644 Assets/LYM/Scripts/PlayerPrefsManager.cs.meta diff --git a/Assets/LYM/Scripts/PlayerPrefsManager.cs b/Assets/LYM/Scripts/PlayerPrefsManager.cs new file mode 100644 index 00000000..04676545 --- /dev/null +++ b/Assets/LYM/Scripts/PlayerPrefsManager.cs @@ -0,0 +1,31 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public static class PlayerPrefsManager +{ + //사운드 설정 저장 + public static void SaveSettings(float sfxVolume, float bgmVolume, bool sfxIsActive, bool bgmIsActive) + { + //볼륨 + sfxVolume = Mathf.Clamp01(sfxVolume); + bgmVolume = Mathf.Clamp01(bgmVolume); + PlayerPrefs.SetFloat("SFXVolume", sfxVolume); + PlayerPrefs.SetFloat("BGMVolume", bgmVolume); + //뮤트 + PlayerPrefs.SetInt("SFXIsActive", sfxIsActive ? 1 : 0); + PlayerPrefs.SetInt("BGMIsActive", bgmIsActive ? 1 : 0); + //즉시 저장 + PlayerPrefs.Save(); + } + + //사운드 설정 불러오기 + public static (float sfxVolume, float bgmVolume, bool sfxIsActive, bool bgmIsActive) LoadSettings() + { + var sfxVolume = PlayerPrefs.GetFloat("SFXVolume", 1f); + var bgmVolume = PlayerPrefs.GetFloat("BGMVolume", 1f); + var sfxIsActive = PlayerPrefs.GetInt("SFXIsActive", 1) == 1; + var bgmIsActive = PlayerPrefs.GetInt("BGMIsActive", 1) == 1; + return (sfxVolume, bgmVolume, sfxIsActive, bgmIsActive); + } +} diff --git a/Assets/LYM/Scripts/PlayerPrefsManager.cs.meta b/Assets/LYM/Scripts/PlayerPrefsManager.cs.meta new file mode 100644 index 00000000..962050fb --- /dev/null +++ b/Assets/LYM/Scripts/PlayerPrefsManager.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 083089baf7a258646917ef5c4fc63979 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/LYM/Scripts/SettingsPanelController.cs b/Assets/LYM/Scripts/SettingsPanelController.cs index f9e551dd..a07c56c4 100644 --- a/Assets/LYM/Scripts/SettingsPanelController.cs +++ b/Assets/LYM/Scripts/SettingsPanelController.cs @@ -19,16 +19,11 @@ public class SettingsPanelController : PanelController private void InitSettings() { - //todo:저장된 데이터를 가져오게 해야함 - var sfxIsActive = true; - var bgmIsActive = true; + var (sfxVolume, bgmVolume, sfxIsActive, bgmIsActive) = PlayerPrefsManager.LoadSettings(); sfxSliderButton.Init(sfxIsActive); bgmSliderButton.Init(bgmIsActive); - //todo:저장된 데이터를 가져오게 해야함 - var sfxSliderValue = 1f; - var bgmSliderValue = 1f; - sfxSlider.value = sfxSliderValue; - bgmSlider.value = bgmSliderValue; + sfxSlider.value = sfxVolume; + bgmSlider.value = bgmVolume; Show(); } @@ -73,6 +68,7 @@ public class SettingsPanelController : PanelController public void OnCloseButtonClicked() { //todo: 설정 저장 필요 + PlayerPrefsManager.SaveSettings(sfxSlider.value, bgmSlider.value, sfxSliderButton.IsActive, bgmSliderButton.IsActive); Hide(); } } diff --git a/Assets/Scripts/Common/GameUtility/GameSound.cs b/Assets/Scripts/Common/GameUtility/GameSound.cs index 13159b5d..0ef8b6a7 100644 --- a/Assets/Scripts/Common/GameUtility/GameSound.cs +++ b/Assets/Scripts/Common/GameUtility/GameSound.cs @@ -1,3 +1,4 @@ +using System; using UnityEngine; using System.Collections; using System.Collections.Generic; @@ -95,7 +96,7 @@ public partial class GameManager if (beamSFX != null) SafeSoundManager?.LoadAudioClip("Beam", beamSFX); // 저장된 볼륨 설정 로드 - // LoadVolumeSettings(); + LoadVolumeSettings(); // 현재 씬에 맞는 배경음 재생 string currentSceneName = UnityEngine.SceneManagement.SceneManager.GetActiveScene().name; @@ -132,16 +133,18 @@ public partial class GameManager } // PlayerPrefs에 저장된 볼륨 설정 불러오기 - // private void LoadVolumeSettings() - // { - // float bgmVolume = PlayerPrefs.GetFloat("BGMVolume", 1.0f); - // float sfxVolume = PlayerPrefs.GetFloat("SFXVolume", 1.0f); - // - // - // SafeSoundManager?.SetBGMVolume(bgmVolume); - // SafeSoundManager?.SetSFXVolume(sfxVolume); - // - // } + private void LoadVolumeSettings() + { + // float bgmVolume = PlayerPrefs.GetFloat("BGMVolume", 1.0f); + // float sfxVolume = PlayerPrefs.GetFloat("SFXVolume", 1.0f); + // + // + // SafeSoundManager?.SetBGMVolume(bgmVolume); + // SafeSoundManager?.SetSFXVolume(sfxVolume); + var (sfxVolume, bgmVolume, sfxIsActive, bgmIsActive) = PlayerPrefsManager.LoadSettings(); + SafeSoundManager?.SetSFXVolume(sfxIsActive? sfxVolume : 0); + SafeSoundManager?.SetBGMVolume(bgmIsActive? bgmVolume : 0); + } #endregion