using System;
using Cysharp.Threading.Tasks;
using AlicizaX.Fsm.Runtime;
using AlicizaX.Procedure.Runtime;
using AlicizaX.Runtime;
using UnityEngine;
using YooAsset;
using Version = System.Version;
namespace Unity.Startup.Procedure
{
///
/// 获取版本信息
///
public sealed class ProcedureGetAppVersionInfoState : ProcedureBase
{
protected override void OnEnter(IFsm procedureOwner)
{
base.OnEnter(procedureOwner);
// 编辑器下的模拟模式
if (GameApp.Resource.GamePlayMode == EPlayMode.EditorSimulateMode)
{
ChangeState(procedureOwner);
return;
}
GetAppVersionInfo(procedureOwner);
}
private async void GetAppVersionInfo(IFsm procedureOwner)
{
try
{
if (GlobalSetting.PatchData == null)
{
Log.Error("GlobalConfig PatchData Is Null!");
return;
}
if (GlobalSetting.PatchData.Version != AppVersion.GameVersion)
{
Log.Warning($"Version inconsistency : {AppVersion.GameVersion}->{GlobalSetting.PatchData.Version} ");
#if UNITY_EDITOR
UnityEditor.EditorApplication.isPlaying = false;
#else
Application.OpenURL(GlobalConfig.PatchData.AppDownloadUrl);
Application.Quit();
#endif
return;
}
ChangeState(procedureOwner);
}
catch (Exception e)
{
Log.Error(e);
await UniTask.Delay(3000);
GetAppVersionInfo(procedureOwner);
}
}
}
}