AlicizaX/Client/Assets/Scripts/Startup/Framework/Procedure/ProcedureGetGlobalInfoState.cs
陈思海 eb38f67131 init
2025-01-23 19:06:48 +08:00

76 lines
2.5 KiB
C#

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)
{
Log.Debug("当前为编辑器模式,直接启动 ProcedureGetAppVersionInfoState");
ChangeState<ProcedureGetAppVersionInfoState>(procedureOwner);
return;
}
if (GameApp.Resource.GamePlayMode == EPlayMode.OfflinePlayMode)
{
Log.Debug("当前为离线模式,直接启动 ProcedurePatchInit");
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
{
string checkVersionUrl = FrameworkSettingsUtils.FrameworkPublishSettings.GetConfig()?.CheckUrl;
if (string.IsNullOrEmpty(checkVersionUrl))
{
Log.Error($"版本更新地址不存在!");
return;
}
var updateDataStr = await Utility.Http.Get(checkVersionUrl);
if (string.IsNullOrEmpty(updateDataStr))
{
Log.Error($"远端更新数据为空: {checkVersionUrl}");
return;
}
GlobalConfig.PatchData = Utility.Json.ToObject<ResourcePatchData>(updateDataStr);
ChangeState<ProcedureGetAppVersionInfoState>(procedureOwner);
}
catch (Exception e)
{
Log.Error(e.Message);
await UniTask.Delay(3000);
GetGlobalInfo(procedureOwner);
}
}
}
}