using AlicizaX.Resource.Runtime; using AlicizaX.Fsm.Runtime; using AlicizaX.Procedure.Runtime; using AlicizaX.Runtime; using UnityEngine; using YooAsset; namespace Unity.Startup.Procedure { internal sealed class ProcedureCreateDownloader : ProcedureBase { protected override void OnEnter(IFsm procedureOwner) { base.OnEnter(procedureOwner); GameApp.Event.Fire(this, AssetPatchStatesChangeEventArgs.Create(EPatchStates.CreateDownloader)); CreateDownloader(procedureOwner); } void CreateDownloader(IFsm procedureOwner) { // Debug.Log("创建补丁下载器."); int downloadingMaxNum = 10; int failedTryAgain = 3; ResourceDownloaderOperation downloader = YooAssets.CreateResourceDownloader(downloadingMaxNum, failedTryAgain); var downloaderVarObject = new VarObject(); downloaderVarObject.SetValue(downloader); procedureOwner.SetData("Downloader", downloaderVarObject); if (downloader.TotalDownloadCount == 0) { Log.Info("没有发现需要下载的资源"); ChangeState(procedureOwner); } else { Debug.Log($"一共发现了{downloader.TotalDownloadCount}个资源需要更新下载。"); // 发现新更新文件后,挂起流程系统 int totalDownloadCount = downloader.TotalDownloadCount; long totalDownloadBytes = downloader.TotalDownloadBytes; float sizeMb = totalDownloadBytes / 1048576f; sizeMb = Mathf.Clamp(sizeMb, 0.1f, float.MaxValue); string totalSizeMb = sizeMb.ToString("f1"); Debug.Log($"总共需要下载文件大小为:{totalSizeMb}"); //这里进行确认 如果要下载在进行跳转到Download GameApp.Event.Fire(this, AssetFoundUpdateFilesEventArgs.Create(downloader.GetPackageName(), totalDownloadCount, totalDownloadBytes)); ChangeState(procedureOwner); } } } }