【设置】分离设置需求

Android_release
zhangaotian 2024-08-08 14:17:03 +08:00
parent 76af4a7d66
commit cb5bbe82ba
8 changed files with 93 additions and 51 deletions

View File

@ -14,8 +14,8 @@ namespace Framework.Manager
public AudioClip BGM; public AudioClip BGM;
public AudioClip BGMInLevel; public AudioClip BGMInLevel;
private Dictionary<string, AudioClip> _soundDic; private Dictionary<string, AudioClip> _soundDic;
private SingleAudio _soundAudio; private SingleAudio _soundAudio;
@ -30,11 +30,6 @@ namespace Framework.Manager
{ {
_soundDic = new Dictionary<string, AudioClip>(); _soundDic = new Dictionary<string, AudioClip>();
AudioUnityMgr.Instance.Init(); AudioUnityMgr.Instance.Init();
MuteVolume(true);
MusicVolume = PlayerPrefs.GetFloat(LevelConstants.Music, 1);
SoundVolume = PlayerPrefs.GetFloat(LevelConstants.Sound, 1);
SetMusic(MusicVolume);
SetSound(SoundVolume);
} }
public async UniTask PreLoadAudio() public async UniTask PreLoadAudio()
@ -89,6 +84,11 @@ namespace Framework.Manager
public void SetMusic(float volume) public void SetMusic(float volume)
{ {
if (_bgmAudio != null)
{
_bgmAudio.audioSource.volume = volume;
}
AudioUnityMgr.Instance.GlobalMusicVolume = volume; AudioUnityMgr.Instance.GlobalMusicVolume = volume;
} }
@ -104,6 +104,12 @@ namespace Framework.Manager
public void MuteMusic(bool isEnable) public void MuteMusic(bool isEnable)
{ {
var volume = isEnable ? 1f : 0f;
if (_bgmAudio != null)
{
_bgmAudio.audioSource.volume = volume;
}
AudioUnityMgr.Instance.SetMusicEnable(isEnable); AudioUnityMgr.Instance.SetMusicEnable(isEnable);
} }
@ -122,8 +128,8 @@ namespace Framework.Manager
{ {
AudioUnityMgr.Instance.SetVolumeEnable(isEnable); AudioUnityMgr.Instance.SetVolumeEnable(isEnable);
} }
public void PlayMusic(AudioType type, AudioClip clip, UnityAudio audioData, public void PlayMusic(AudioType type, AudioClip clip, UnityAudio audioData,
Transform trans = null, Vector3 pos = new()) Transform trans = null, Vector3 pos = new())
{ {

View File

@ -0,0 +1,59 @@
using Framework.Manager;
using Framework.UI;
using UnityEngine;
using PhxhSDK;
public class SettingData
{
public float MusicVolume = 1f;
public float SoundVolume = 1f;
public string Language;
}
public class SettingManager : Singlenton<SettingManager>
{
private const string SettingKey = "SettingKey";
private SettingData _settingData;
public void Init()
{
_settingData = StorageManager.Instance.GetStorage<SettingData>(SettingKey);
_settingData ??= new SettingData();
//初始化音量
AudioManager.Instance.MuteVolume(true);
AudioManager.Instance.SoundVolume = _settingData.SoundVolume;
AudioManager.Instance.MusicVolume = _settingData.MusicVolume;
var muteMusic = Mathf.Approximately(_settingData.MusicVolume, 1f);
var muteSound = Mathf.Approximately(_settingData.SoundVolume, 1f);
AudioManager.Instance.MuteMusic(muteMusic);
AudioManager.Instance.MuteSound(muteSound);
//初始化语言
StringManager.Instance.InitLanguage(_settingData.Language);
}
public void SetMusic(float music)
{
_settingData.MusicVolume = music;
SaveSetting();
}
public void SetSound(float sound)
{
_settingData.SoundVolume = sound;
SaveSetting();
}
public void SetLanguage(string language)
{
_settingData.Language = language;
SaveSetting();
}
private void SaveSetting()
{
StorageManager.Instance.SaveWithoutUpdate();
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 2547a1a1f16b34289b1cd986570d1c7b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -141,17 +141,5 @@ namespace Framework.Manager
_serverDataIO.LoadToClass(jsonData, ref AppInfoManager.Instance.RemoteAppUserInfo); _serverDataIO.LoadToClass(jsonData, ref AppInfoManager.Instance.RemoteAppUserInfo);
} }
} }
public void DeleteSaveData()
{
foreach (var key in localStorageMap.Keys)
{
UnityEngine.PlayerPrefs.DeleteKey(key);
}
localStorageMap.Clear();
UnityEngine.PlayerPrefs.Save();
DebugUtil.LogWarning("存档数据已成功删除");
}
} }
} }

View File

@ -32,16 +32,9 @@ namespace Framework.UI
EN, EN,
} }
public void InitLanguage() public void InitLanguage(string language)
{ {
if (UnityEngine.PlayerPrefs.HasKey(LevelConstants.Language)) CurLanguage = !string.IsNullOrEmpty(language) ? String2LanguageType(language) : System2LanguageType(Application.systemLanguage);
{
CurLanguage = String2LanguageType(UnityEngine.PlayerPrefs.GetString(LevelConstants.Language));
}
else
{
CurLanguage = System2LanguageType(Application.systemLanguage);
}
EventManager.Instance.Send(EventManager.EventName.RefreshLanguage); EventManager.Instance.Send(EventManager.EventName.RefreshLanguage);
} }

View File

@ -14,9 +14,7 @@ namespace Framework.Constants
public const string English = "English"; public const string English = "English";
//设置本地存档Key //设置本地存档Key
public const string Music = "Music";
public const string Sound = "Sound";
public const string Language = "Language";
public const string FirstLaunch = "Launch"; public const string FirstLaunch = "Launch";
//BI事件 //BI事件

View File

@ -32,7 +32,7 @@ namespace Gameplay.LoadingExecutor
_destProgress = 40f; _destProgress = 40f;
await PreLoadSelectLevel(); await PreLoadSelectLevel();
_destProgress = 50f; _destProgress = 50f;
StringManager.Instance.InitLanguage(); SettingManager.Instance.Init();
await InitBuildScene(); await InitBuildScene();
_destProgress = 60f; _destProgress = 60f;
await InitGfx(); await InitGfx();

View File

@ -23,9 +23,7 @@ public class UISettingPanelController : UIWindow
private GameObject _tipConfirm; private GameObject _tipConfirm;
private TMP_Dropdown _lanDropdown; private TMP_Dropdown _lanDropdown;
private TMP_Text _account;
private bool _isMuteMusic; private bool _isMuteMusic;
private bool _isMuteSound; private bool _isMuteSound;
@ -40,7 +38,6 @@ public class UISettingPanelController : UIWindow
_uiBtnCloseM = FindObj("BG_SettingPanel/Music/Btn_Switch_M/UI_Btn_Close_M").gameObject; _uiBtnCloseM = FindObj("BG_SettingPanel/Music/Btn_Switch_M/UI_Btn_Close_M").gameObject;
_uiBtnOpenS = FindObj("BG_SettingPanel/Sound/Btn_Switch_S/UI_Btn_Open_S").gameObject; _uiBtnOpenS = FindObj("BG_SettingPanel/Sound/Btn_Switch_S/UI_Btn_Open_S").gameObject;
_uiBtnCloseS = FindObj("BG_SettingPanel/Sound/Btn_Switch_S/UI_Btn_Close_S").gameObject; _uiBtnCloseS = FindObj("BG_SettingPanel/Sound/Btn_Switch_S/UI_Btn_Close_S").gameObject;
_account = FindObj("Txt_Account").GetComponent<TMP_Text>();
BindButton("BG_SettingPanel/Btn_Close", () => BindButton("BG_SettingPanel/Btn_Close", () =>
{ {
EventManager.Instance.Send(EventManager.EventName.ShowGfx); EventManager.Instance.Send(EventManager.EventName.ShowGfx);
@ -99,13 +96,11 @@ public class UISettingPanelController : UIWindow
EventManager.Instance.Send(EventManager.EventName.RefreshLanguage); EventManager.Instance.Send(EventManager.EventName.RefreshLanguage);
BIManager.Instance.TrackEvent(biEvent); BIManager.Instance.TrackEvent(biEvent);
PlayerPrefs.SetString(LevelConstants.Language, language.ToString()); SettingManager.Instance.SetLanguage(language.ToString());
PlayerPrefs.Save();
} }
protected override void OnOpenWindow(object data) protected override void OnOpenWindow(object data)
{ {
UpdateID();
EventManager.Instance.Send(EventManager.EventName.HideGfx); EventManager.Instance.Send(EventManager.EventName.HideGfx);
_rawImageGaussianBlurMask.texture = CommonUIUtils.RenderTexture; _rawImageGaussianBlurMask.texture = CommonUIUtils.RenderTexture;
} }
@ -117,18 +112,12 @@ public class UISettingPanelController : UIWindow
UpdateUI(); UpdateUI();
} }
void UpdateID()
{
_account.text = LoginManager.Instance.Account;
}
private void UpdateUI() private void UpdateUI()
{ {
_uiBtnOpenM.SetActive(!_isMuteMusic); _uiBtnOpenM.SetActive(!_isMuteMusic);
_uiBtnCloseM.SetActive(_isMuteMusic); _uiBtnCloseM.SetActive(_isMuteMusic);
_uiBtnOpenS.SetActive(!_isMuteSound); _uiBtnOpenS.SetActive(!_isMuteSound);
_uiBtnCloseS.SetActive(_isMuteSound); _uiBtnCloseS.SetActive(_isMuteSound);
_account.text = LoginManager.Instance.Account;
} }
private void ChangeMusic() private void ChangeMusic()
@ -139,8 +128,7 @@ public class UISettingPanelController : UIWindow
UpdateUI(); UpdateUI();
var eventName = _isMuteMusic ? cfg.BI.Event.music_off : cfg.BI.Event.music_on; var eventName = _isMuteMusic ? cfg.BI.Event.music_off : cfg.BI.Event.music_on;
BIManager.Instance.TrackEvent(eventName); BIManager.Instance.TrackEvent(eventName);
PlayerPrefs.SetFloat(LevelConstants.Music, AudioManager.Instance.MusicVolume); SettingManager.Instance.SetMusic(AudioManager.Instance.MusicVolume);
PlayerPrefs.Save();
} }
private void ChangeSound() private void ChangeSound()
@ -151,7 +139,6 @@ public class UISettingPanelController : UIWindow
UpdateUI(); UpdateUI();
var eventName = _isMuteSound ? cfg.BI.Event.sfx_off : cfg.BI.Event.sfx_on; var eventName = _isMuteSound ? cfg.BI.Event.sfx_off : cfg.BI.Event.sfx_on;
BIManager.Instance.TrackEvent(eventName); BIManager.Instance.TrackEvent(eventName);
PlayerPrefs.SetFloat(LevelConstants.Sound, AudioManager.Instance.SoundVolume); SettingManager.Instance.SetSound(AudioManager.Instance.SoundVolume);
PlayerPrefs.Save();
} }
} }