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 { /// /// 获取全局信息 /// public sealed class ProcedureGetGlobalInfoState : ProcedureBase { protected override void OnEnter(IFsm procedureOwner) { base.OnEnter(procedureOwner); if (GameApp.Resource.GamePlayMode == EPlayMode.EditorSimulateMode) { ChangeState(procedureOwner); return; } if (GameApp.Resource.GamePlayMode == EPlayMode.OfflinePlayMode) { ChangeState(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 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(updateDataStr); ChangeState(procedureOwner); } catch (Exception e) { Log.Error(e.Message); await UniTask.Delay(3000); GetGlobalInfo(procedureOwner); } } } }