AlicizaX/Client/Assets/Scripts/Startup/Framework/Procedure/ProcedureGetGlobalInfoState.cs

74 lines
2.2 KiB
C#
Raw Normal View History

2025-01-23 19:06:48 +08:00
using System;
using Cysharp.Threading.Tasks;
using AlicizaX.Fsm.Runtime;
using AlicizaX.Procedure.Runtime;
using AlicizaX.Resource.Runtime;
using AlicizaX.Runtime;
using UnityEngine;
using YooAsset;
namespace Unity.Startup.Procedure
{
/// <summary>
/// 获取全局信息
/// </summary>
public sealed class ProcedureGetGlobalInfoState : ProcedureBase
{
protected override void OnEnter(IFsm<IProcedureManager> procedureOwner)
{
base.OnEnter(procedureOwner);
if (GameApp.Resource.GamePlayMode == EPlayMode.EditorSimulateMode)
{
ChangeState<ProcedureGetAppVersionInfoState>(procedureOwner);
return;
}
if (GameApp.Resource.GamePlayMode == EPlayMode.OfflinePlayMode)
{
ChangeState<ProcedurePatchInit>(procedureOwner);
return;
}
//检查设备是否能够访问互联网
if (Application.internetReachability == NetworkReachability.NotReachable)
{
Log.Warning("The device is not connected to the network");
return;
}
GetGlobalInfo(procedureOwner);
}
private async void GetGlobalInfo(IFsm<IProcedureManager> procedureOwner)
{
try
{
2025-03-04 18:40:14 +08:00
string checkVersionUrl = HttpHelper.CDN_URL;
2025-01-23 19:06:48 +08:00
if (string.IsNullOrEmpty(checkVersionUrl))
{
Log.Error($"版本更新地址不存在!");
return;
}
var updateDataStr = await Utility.Http.Get(checkVersionUrl);
if (string.IsNullOrEmpty(updateDataStr))
{
Log.Error($"远端更新数据为空: {checkVersionUrl}");
return;
}
2025-03-07 18:00:59 +08:00
GlobalSetting.PatchData = Utility.Json.ToObject<ResourcePatchData>(updateDataStr);
2025-01-23 19:06:48 +08:00
ChangeState<ProcedureGetAppVersionInfoState>(procedureOwner);
}
catch (Exception e)
{
Log.Error(e.Message);
await UniTask.Delay(3000);
GetGlobalInfo(procedureOwner);
}
}
}
2025-01-26 20:55:39 +08:00
}