AlicizaX/Client/Assets/Scripts/Startup/Framework/Procedure/ProcedureGetAppVersionInfoState.cs
2025-01-26 20:55:39 +08:00

64 lines
1.8 KiB
C#

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
{
/// <summary>
/// 获取版本信息
/// </summary>
public sealed class ProcedureGetAppVersionInfoState : ProcedureBase
{
protected override void OnEnter(IFsm<IProcedureManager> procedureOwner)
{
base.OnEnter(procedureOwner);
// 编辑器下的模拟模式
if (GameApp.Resource.GamePlayMode == EPlayMode.EditorSimulateMode)
{
ChangeState<ProcedurePatchInit>(procedureOwner);
return;
}
GetAppVersionInfo(procedureOwner);
}
private async void GetAppVersionInfo(IFsm<IProcedureManager> procedureOwner)
{
try
{
if (GlobalConfig.PatchData == null)
{
Log.Error("GlobalConfig PatchData Is Null!");
return;
}
if (GlobalConfig.PatchData.Version != AppVersion.GameVersion)
{
Log.Warning($"Version inconsistency : {AppVersion.GameVersion}->{GlobalConfig.PatchData.Version} ");
#if UNITY_EDITOR
UnityEditor.EditorApplication.isPlaying = false;
#else
Application.OpenURL(GlobalConfig.PatchData.AppDownloadUrl);
Application.Quit();
#endif
return;
}
ChangeState<ProcedurePatchInit>(procedureOwner);
}
catch (Exception e)
{
Log.Error(e);
await UniTask.Delay(3000);
GetAppVersionInfo(procedureOwner);
}
}
}
}