【UI设置】设置存至本地

main
zhangaotian 2023-12-08 14:16:12 +08:00
parent 22249ee663
commit a274b151db
7 changed files with 201 additions and 63 deletions

View File

@ -4,7 +4,6 @@ using Gameplay.Net;
using Gameplay.Performance;
using PhxhSDK;
using UnityEditor;
using UnityEngine;
using Constants = Framework.Constants;
namespace Gameplay
@ -27,11 +26,13 @@ namespace Gameplay
{
_destProgress = 30f;
await LoadLoginUI();
_destProgress = 90f;
_destProgress = 80f;
await LoadConfig();
_destProgress = 100f;
_destProgress = 90f;
await _PreloadOthers();
await _LoadPerformance();
await InitGameSetting();
_destProgress = 100f;
}
}
@ -119,5 +120,10 @@ namespace Gameplay
await PerformanceManager.instance.LoadRes();
PerformanceManager.SetPerformance(PerformanceManager.instance.data);
}
private async UniTask InitGameSetting()
{
GameSettingManager.Instance.Init();
}
}
}

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: cff1d654c202fe640a78b9b842bdafbe
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,10 @@
public class GameSettingData
{
public bool IsHighQuality = true;
public int FrameRate = 60;
public float BGMValue = 0.8f;
public float EffectValue = 0.8f;
public float TalkValue = 0.8f;
public bool IsOpenGrid = true;
}

View File

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

View File

@ -0,0 +1,67 @@
using Gameplay.Performance;
public class GameSettingManager
{
private static GameSettingManager instance;
public static GameSettingManager Instance
{
get
{
if (instance == null)
{
CreateInstance();
}
return instance;
}
}
public static void CreateInstance()
{
if (instance != null)
{
return;
}
instance = new GameSettingManager();
}
public GameSettingData SettingData;
private GameSettingData _defaultSettingData;
public void Init()
{
_defaultSettingData = new GameSettingData();
SettingData = StorageMgr.Instance.GetStorage<GameSettingData>("SettingData");
ChangeGameSettings();
}
public void ChangeGameSettings()
{
AudioManager.Instance.GlobalMusicVolume = SettingData.BGMValue;
AudioManager.Instance.GlobalSoundsVolume = SettingData.EffectValue;
PerformanceManager.instance.SetFrameRate(SettingData.FrameRate);
//TODO 画质高低 开启格子 语音
//PerformanceManager.instance.SetQuality()
//保存至本地
StorageMgr.Instance.SyncForce = true;
}
public void RevertDefault()
{
SettingData.IsHighQuality = _defaultSettingData.IsHighQuality;
SettingData.FrameRate = _defaultSettingData.FrameRate;
SettingData.BGMValue = _defaultSettingData.BGMValue;
SettingData.EffectValue = _defaultSettingData.EffectValue;
SettingData.TalkValue = _defaultSettingData.TalkValue;
SettingData.IsOpenGrid = _defaultSettingData.IsOpenGrid;
ChangeGameSettings();
//保存至本地
StorageMgr.Instance.SyncForce = true;
}
}

View File

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

View File

@ -3,7 +3,6 @@ using UnityEngine;
using Button = UnityEngine.UI.Button;
using Image = UnityEngine.UI.Image;
using Slider = UnityEngine.UI.Slider;
using Gameplay.Performance;
public class UI_SettingController : UIWindow
{
@ -46,80 +45,92 @@ public class UI_SettingController : UIWindow
public Button Button_Cancel;
public Button Button_Save;
private bool _isHighQuality;
private int _frameRate;
private bool _isCloseBGM;
private bool _isCloseEffect;
private bool _isCloseTalk;
private float _valueBGM;
private float _valueEffect;
private float _valueTalk;
private bool _isShowGrid;
private GameSettingData _settings;
public override void OnAwake()
{
UI_SettingBinder.GetComponents(this);
Init();
BindButton(Button_Close, () => CloseWindow());
BindButton(Button_LowQ2, LowQuality);
BindButton(Button_HighQ2, HighQuality);
BindButton(Button_60F, Set60FrameRate);
BindButton(Button_30F, Set30FrameRate);
//静音
BindButton(Button_Close_BGM, CloseBGM);
BindButton(Button_Close_Effect, CloseEffect);
BindButton(Button_Close_Talk, CloseTalk);
//取消静音
BindButton(Button_Open_BGM, OpenBGM);
BindButton(Button_Open_Effect, OpenEffect);
BindButton(Button_Open_Talk, OpenTalk);
BindButton(Button_Open_Map, delegate { Button_Close_Map.gameObject.SetActive(true); });
BindButton(Button_Close_Map, delegate { Button_Close_Map.gameObject.SetActive(false); });
BindButton(Button_Close, () => CloseWindow());
BindButton(Button_Open_Map, OpenGrid);
BindButton(Button_Close_Map, CloseGrid);
BindButton(Button_Cancel, Cancel);
BindButton(Button_Save, Save);
Slider_HaveVoice_BGM.onValueChanged.AddListener(OnValueChangedBGM);
Slider_HaveVoice_Effect.onValueChanged.AddListener(OnValueChangedEffect);
Slider_HaveVoice_Talk.onValueChanged.AddListener(OnValueChangedTalk);
Init();
}
private void Init()
{
_valueBGM = AudioManager.Instance.GlobalMusicVolume;
_valueEffect = AudioManager.Instance.GlobalSoundsVolume;
_valueTalk = 1f;
_settings = GameSettingManager.Instance.SettingData;
InitSlider();
if (_settings.IsHighQuality)
HighQuality();
else
LowQuality();
if (_settings.FrameRate.Equals(30))
Set30FrameRate();
else
Set60FrameRate();
if (_settings.IsOpenGrid)
CloseGrid();
else
OpenGrid();
}
private void InitSlider()
{
Slider_NoVoice_BGM.interactable = false;
Slider_NoVoice_Effect.interactable = false;
Slider_NoVoice_Talk.interactable = false;
Slider_HaveVoice_BGM.value = _valueBGM;
Slider_NoVoice_BGM.value = _valueBGM;
Slider_HaveVoice_Effect.value = _valueEffect;
Slider_NoVoice_Effect.value = _valueEffect;
//TODO 语音初始化
//Slider_HaveVoice_Talk.value = AudioManager.Instance...;
//Slider_NoVoice_Talk.value = AudioManager.Instance...;
Slider_HaveVoice_BGM.onValueChanged.AddListener(OnValueChangedBGM);
Slider_HaveVoice_Effect.onValueChanged.AddListener(OnValueChangedEffect);
Slider_HaveVoice_Talk.onValueChanged.AddListener(OnValueChangedTalk);
Slider_HaveVoice_BGM.value = _settings.BGMValue;
Slider_NoVoice_BGM.value = _settings.BGMValue;
Slider_HaveVoice_Effect.value = _settings.EffectValue;
Slider_NoVoice_Effect.value = _settings.EffectValue;
Slider_HaveVoice_Talk.value = _settings.TalkValue;
Slider_NoVoice_Talk.value = _settings.TalkValue;
if (_settings.BGMValue <= 0)
CloseBGM();
else
OpenBGM();
if (_settings.EffectValue <= 0)
CloseEffect();
else
OpenEffect();
if (_settings.TalkValue <= 0)
CloseTalk();
else
OpenTalk();
}
private void HighQuality()
{
//TODO 高画质接口
_settings.IsHighQuality = true;
Button_LowQ1.gameObject.SetActive(false);
Button_LowQ2.gameObject.SetActive(true);
Button_HighQ1.gameObject.SetActive(true);
@ -128,7 +139,7 @@ public class UI_SettingController : UIWindow
private void LowQuality()
{
//TODO 低画质接口
_settings.IsHighQuality = false;
Button_LowQ1.gameObject.SetActive(true);
Button_LowQ2.gameObject.SetActive(false);
Button_HighQ1.gameObject.SetActive(false);
@ -137,14 +148,14 @@ public class UI_SettingController : UIWindow
private void Set60FrameRate()
{
PerformanceManager.instance.SetFrameRate(60);
_settings.FrameRate = 60;
Image_BPot_60.gameObject.SetActive(false);
Image_BPot_30.gameObject.SetActive(true);
}
private void Set30FrameRate()
{
PerformanceManager.instance.SetFrameRate(30);
_settings.FrameRate = 30;
Image_BPot_60.gameObject.SetActive(true);
Image_BPot_30.gameObject.SetActive(false);
}
@ -152,7 +163,7 @@ public class UI_SettingController : UIWindow
private void CloseBGM()
{
_isCloseBGM = true;
_settings.BGMValue = 0;
Button_Open_BGM.gameObject.SetActive(true);
Slider_NoVoice_BGM.gameObject.SetActive(true);
Slider_HaveVoice_BGM.gameObject.SetActive(false);
@ -160,7 +171,7 @@ public class UI_SettingController : UIWindow
private void CloseEffect()
{
_isCloseEffect = true;
_settings.EffectValue = 0;
Button_Open_Effect.gameObject.SetActive(true);
Slider_NoVoice_Effect.gameObject.SetActive(true);
Slider_HaveVoice_Effect.gameObject.SetActive(false);
@ -168,7 +179,7 @@ public class UI_SettingController : UIWindow
private void CloseTalk()
{
_isCloseTalk = true;
_settings.TalkValue = 0;
Button_Open_Talk.gameObject.SetActive(true);
Slider_NoVoice_Talk.gameObject.SetActive(true);
Slider_HaveVoice_Talk.gameObject.SetActive(false);
@ -176,39 +187,39 @@ public class UI_SettingController : UIWindow
private void OpenBGM()
{
_isCloseBGM = false;
Button_Open_BGM.gameObject.SetActive(false);
Slider_NoVoice_BGM.gameObject.SetActive(false);
Slider_HaveVoice_BGM.gameObject.SetActive(true);
if (Slider_HaveVoice_BGM.value <= 0)
Slider_HaveVoice_BGM.value = 0.5f;
_settings.BGMValue = Slider_HaveVoice_BGM.value;
}
private void OpenEffect()
{
_isCloseEffect = false;
Button_Open_Effect.gameObject.SetActive(false);
Slider_NoVoice_Effect.gameObject.SetActive(false);
Slider_HaveVoice_Effect.gameObject.SetActive(true);
if (Slider_HaveVoice_Effect.value <= 0)
Slider_HaveVoice_Effect.value = 0.5f;
_settings.EffectValue = Slider_HaveVoice_Effect.value;
}
private void OpenTalk()
{
_isCloseTalk = false;
Button_Open_Talk.gameObject.SetActive(false);
Slider_NoVoice_Talk.gameObject.SetActive(false);
Slider_HaveVoice_Talk.gameObject.SetActive(true);
if (Slider_HaveVoice_Talk.value <= 0)
Slider_HaveVoice_Talk.value = 0.5f;
_settings.TalkValue = Slider_HaveVoice_Talk.value;
}
private void OnValueChangedBGM(float value)
{
_valueBGM = value;
Text_Rate_BGM.text = Mathf.RoundToInt(value * 100).ToString();
_settings.BGMValue = value;
FormatText(Text_Rate_BGM, value);
Slider_NoVoice_BGM.value = Slider_HaveVoice_BGM.value;
if (value <= 0)
CloseBGM();
@ -216,8 +227,8 @@ public class UI_SettingController : UIWindow
private void OnValueChangedEffect(float value)
{
_valueEffect = value;
Text_Rate_Effect.text = Mathf.RoundToInt(value * 100).ToString();
_settings.EffectValue = value;
FormatText(Text_Rate_Effect, value);
Slider_NoVoice_Effect.value = Slider_HaveVoice_Effect.value;
if (value <= 0)
CloseEffect();
@ -225,25 +236,39 @@ public class UI_SettingController : UIWindow
private void OnValueChangedTalk(float value)
{
_valueTalk = value;
Text_Rate_Talk.text = Mathf.RoundToInt(value * 100).ToString();
_settings.TalkValue = value;
FormatText(Text_Rate_Talk, value);
Slider_NoVoice_Talk.value = Slider_HaveVoice_Effect.value;
if (value <= 0)
CloseTalk();
}
private void OpenGrid()
{
_settings.IsOpenGrid = false;
Button_Close_Map.gameObject.SetActive(true);
}
private void CloseGrid()
{
_settings.IsOpenGrid = true;
Button_Close_Map.gameObject.SetActive(false);
}
private void FormatText(TMP_Text tmpText, float value)
{
tmpText.text = Mathf.RoundToInt(value * 100).ToString();
}
private void Save()
{
AudioManager.Instance.GlobalMusicVolume = _isCloseBGM ? 0 : _valueBGM;
AudioManager.Instance.GlobalSoundsVolume = _isCloseEffect ? 0 : _valueEffect;
// ... AudioManager.Instance.GlobalTalkVolume = _valueTalk;
GameSettingManager.Instance.SettingData = _settings;
GameSettingManager.Instance.ChangeGameSettings();
}
private void Cancel()
{
Slider_HaveVoice_BGM.value = AudioManager.Instance.GlobalMusicVolume;
Slider_HaveVoice_Effect.value = AudioManager.Instance.GlobalSoundsVolume;
Slider_NoVoice_BGM.value = AudioManager.Instance.GlobalMusicVolume;
Slider_NoVoice_Effect.value = AudioManager.Instance.GlobalMusicVolume;
GameSettingManager.Instance.RevertDefault();
Init();
}
}