【设置】分离设置需求
parent
76af4a7d66
commit
cb5bbe82ba
|
@ -14,8 +14,8 @@ namespace Framework.Manager
|
|||
|
||||
public AudioClip BGM;
|
||||
public AudioClip BGMInLevel;
|
||||
|
||||
|
||||
|
||||
|
||||
private Dictionary<string, AudioClip> _soundDic;
|
||||
|
||||
private SingleAudio _soundAudio;
|
||||
|
@ -30,11 +30,6 @@ namespace Framework.Manager
|
|||
{
|
||||
_soundDic = new Dictionary<string, AudioClip>();
|
||||
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()
|
||||
|
@ -89,6 +84,11 @@ namespace Framework.Manager
|
|||
|
||||
public void SetMusic(float volume)
|
||||
{
|
||||
if (_bgmAudio != null)
|
||||
{
|
||||
_bgmAudio.audioSource.volume = volume;
|
||||
}
|
||||
|
||||
AudioUnityMgr.Instance.GlobalMusicVolume = volume;
|
||||
}
|
||||
|
||||
|
@ -104,6 +104,12 @@ namespace Framework.Manager
|
|||
|
||||
public void MuteMusic(bool isEnable)
|
||||
{
|
||||
var volume = isEnable ? 1f : 0f;
|
||||
if (_bgmAudio != null)
|
||||
{
|
||||
_bgmAudio.audioSource.volume = volume;
|
||||
}
|
||||
|
||||
AudioUnityMgr.Instance.SetMusicEnable(isEnable);
|
||||
}
|
||||
|
||||
|
@ -122,8 +128,8 @@ namespace Framework.Manager
|
|||
{
|
||||
AudioUnityMgr.Instance.SetVolumeEnable(isEnable);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public void PlayMusic(AudioType type, AudioClip clip, UnityAudio audioData,
|
||||
Transform trans = null, Vector3 pos = new())
|
||||
{
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 2547a1a1f16b34289b1cd986570d1c7b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -141,17 +141,5 @@ namespace Framework.Manager
|
|||
_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("存档数据已成功删除");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -32,16 +32,9 @@ namespace Framework.UI
|
|||
EN,
|
||||
}
|
||||
|
||||
public void InitLanguage()
|
||||
public void InitLanguage(string language)
|
||||
{
|
||||
if (UnityEngine.PlayerPrefs.HasKey(LevelConstants.Language))
|
||||
{
|
||||
CurLanguage = String2LanguageType(UnityEngine.PlayerPrefs.GetString(LevelConstants.Language));
|
||||
}
|
||||
else
|
||||
{
|
||||
CurLanguage = System2LanguageType(Application.systemLanguage);
|
||||
}
|
||||
CurLanguage = !string.IsNullOrEmpty(language) ? String2LanguageType(language) : System2LanguageType(Application.systemLanguage);
|
||||
|
||||
EventManager.Instance.Send(EventManager.EventName.RefreshLanguage);
|
||||
}
|
||||
|
|
|
@ -14,9 +14,7 @@ namespace Framework.Constants
|
|||
public const string English = "English";
|
||||
|
||||
//设置本地存档Key
|
||||
public const string Music = "Music";
|
||||
public const string Sound = "Sound";
|
||||
public const string Language = "Language";
|
||||
|
||||
public const string FirstLaunch = "Launch";
|
||||
|
||||
//BI事件
|
||||
|
|
|
@ -32,7 +32,7 @@ namespace Gameplay.LoadingExecutor
|
|||
_destProgress = 40f;
|
||||
await PreLoadSelectLevel();
|
||||
_destProgress = 50f;
|
||||
StringManager.Instance.InitLanguage();
|
||||
SettingManager.Instance.Init();
|
||||
await InitBuildScene();
|
||||
_destProgress = 60f;
|
||||
await InitGfx();
|
||||
|
|
|
@ -23,9 +23,7 @@ public class UISettingPanelController : UIWindow
|
|||
private GameObject _tipConfirm;
|
||||
|
||||
private TMP_Dropdown _lanDropdown;
|
||||
|
||||
private TMP_Text _account;
|
||||
|
||||
|
||||
private bool _isMuteMusic;
|
||||
private bool _isMuteSound;
|
||||
|
||||
|
@ -40,7 +38,6 @@ public class UISettingPanelController : UIWindow
|
|||
_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;
|
||||
_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", () =>
|
||||
{
|
||||
EventManager.Instance.Send(EventManager.EventName.ShowGfx);
|
||||
|
@ -99,13 +96,11 @@ public class UISettingPanelController : UIWindow
|
|||
EventManager.Instance.Send(EventManager.EventName.RefreshLanguage);
|
||||
BIManager.Instance.TrackEvent(biEvent);
|
||||
|
||||
PlayerPrefs.SetString(LevelConstants.Language, language.ToString());
|
||||
PlayerPrefs.Save();
|
||||
SettingManager.Instance.SetLanguage(language.ToString());
|
||||
}
|
||||
|
||||
protected override void OnOpenWindow(object data)
|
||||
{
|
||||
UpdateID();
|
||||
EventManager.Instance.Send(EventManager.EventName.HideGfx);
|
||||
_rawImageGaussianBlurMask.texture = CommonUIUtils.RenderTexture;
|
||||
}
|
||||
|
@ -117,18 +112,12 @@ public class UISettingPanelController : UIWindow
|
|||
UpdateUI();
|
||||
}
|
||||
|
||||
void UpdateID()
|
||||
{
|
||||
_account.text = LoginManager.Instance.Account;
|
||||
}
|
||||
|
||||
private void UpdateUI()
|
||||
{
|
||||
_uiBtnOpenM.SetActive(!_isMuteMusic);
|
||||
_uiBtnCloseM.SetActive(_isMuteMusic);
|
||||
_uiBtnOpenS.SetActive(!_isMuteSound);
|
||||
_uiBtnCloseS.SetActive(_isMuteSound);
|
||||
_account.text = LoginManager.Instance.Account;
|
||||
}
|
||||
|
||||
private void ChangeMusic()
|
||||
|
@ -139,8 +128,7 @@ public class UISettingPanelController : UIWindow
|
|||
UpdateUI();
|
||||
var eventName = _isMuteMusic ? cfg.BI.Event.music_off : cfg.BI.Event.music_on;
|
||||
BIManager.Instance.TrackEvent(eventName);
|
||||
PlayerPrefs.SetFloat(LevelConstants.Music, AudioManager.Instance.MusicVolume);
|
||||
PlayerPrefs.Save();
|
||||
SettingManager.Instance.SetMusic(AudioManager.Instance.MusicVolume);
|
||||
}
|
||||
|
||||
private void ChangeSound()
|
||||
|
@ -151,7 +139,6 @@ public class UISettingPanelController : UIWindow
|
|||
UpdateUI();
|
||||
var eventName = _isMuteSound ? cfg.BI.Event.sfx_off : cfg.BI.Event.sfx_on;
|
||||
BIManager.Instance.TrackEvent(eventName);
|
||||
PlayerPrefs.SetFloat(LevelConstants.Sound, AudioManager.Instance.SoundVolume);
|
||||
PlayerPrefs.Save();
|
||||
SettingManager.Instance.SetSound(AudioManager.Instance.SoundVolume);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue