AlicizaX/Client/Assets/Scripts/Startup/Framework/Procedure/PatchUpdater/ProcedureCreateDownloader.cs
2025-01-24 16:21:00 +08:00

57 lines
2.2 KiB
C#

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<IProcedureManager> procedureOwner)
{
base.OnEnter(procedureOwner);
GameApp.Event.Fire(this, AssetPatchStatesChangeEventArgs.Create(EPatchStates.CreateDownloader));
CreateDownloader(procedureOwner);
}
void CreateDownloader(IFsm<IProcedureManager> procedureOwner)
{
// Debug.Log("创建补丁下载器.");
int downloadingMaxNum = 10;
int failedTryAgain = 3;
ResourceDownloaderOperation downloader = YooAssets.CreateResourceDownloader(downloadingMaxNum, failedTryAgain);
var downloaderVarObject = new VarObject();
downloaderVarObject.SetValue(downloader);
procedureOwner.SetData<VarObject>("Downloader", downloaderVarObject);
if (downloader.TotalDownloadCount == 0)
{
Log.Info("没有发现需要下载的资源");
ChangeState<ProcedurePatchDone>(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<ProcedureDownloadWebFiles>(procedureOwner);
}
}
}
}