using Cysharp.Threading.Tasks;
using AlicizaX;
namespace Unity.Startup.Procedure
{
///
/// 启动游戏
///
public class ProcedureLauncherState : StateBase
{
private bool _gameSettingInitFinish;
protected override async void OnEnter()
{
await UniTask.Delay(1000);
LauncherUIHandler.Start().Forget();
InitlizeGameSetting();
}
private async void Start()
{
await UniTask.NextFrame();
SwitchState(UpdateProcedureState.ProcedureGetGlobalInfoState);
}
protected override void OnUpdate(float deltaTime)
{
base.OnUpdate(deltaTime);
if (_gameSettingInitFinish)
{
Start();
}
}
private void InitlizeGameSetting()
{
bool isWrited = Utility.PlayerPrefsX.GetBool(PrefsKey.Setting.WirtedSetting, false);
if (!isWrited)
{
WriteDefaultSetting();
}
InitSoundSettings();
_gameSettingInitFinish = true;
}
private void WriteDefaultSetting()
{
Utility.PlayerPrefsX.SetBool(PrefsKey.Setting.WirtedSetting, true);
Utility.PlayerPrefsX.SetBool(PrefsKey.Setting.MusicMuted, false);
Utility.PlayerPrefsX.SetFloat(PrefsKey.Setting.MusicVolume, 1f);
Utility.PlayerPrefsX.SetBool(PrefsKey.Setting.SoundMuted, false);
Utility.PlayerPrefsX.SetFloat(PrefsKey.Setting.SoundVolume, 1f);
Utility.PlayerPrefsX.SetBool(PrefsKey.Setting.UISoundMuted, false);
Utility.PlayerPrefsX.SetFloat(PrefsKey.Setting.UISoundVolume, 1f);
}
private void InitSoundSettings()
{
GameApp.Audio.MusicEnable = !Utility.PlayerPrefsX.GetBool(PrefsKey.Setting.MusicMuted, false);
GameApp.Audio.MusicVolume = Utility.PlayerPrefsX.GetFloat(PrefsKey.Setting.MusicVolume, 1f);
GameApp.Audio.SoundEnable = !Utility.PlayerPrefsX.GetBool(PrefsKey.Setting.SoundMuted, false);
GameApp.Audio.SoundVolume = Utility.PlayerPrefsX.GetFloat(PrefsKey.Setting.SoundVolume, 1f);
GameApp.Audio.UISoundEnable = !Utility.PlayerPrefsX.GetBool(PrefsKey.Setting.UISoundMuted, false);
GameApp.Audio.UISoundVolume = Utility.PlayerPrefsX.GetFloat(PrefsKey.Setting.UISoundVolume, 1f);
}
}
}