AlicizaX/Client/Assets/Scripts/Startup/Framework/Procedure/PatchUpdater/ProcedureDownloadWebFiles.cs

55 lines
2.1 KiB
C#
Raw Normal View History

2025-01-23 19:06:48 +08:00
using System.Collections;
using Cysharp.Threading.Tasks;
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 ProcedureDownloadWebFiles : ProcedureBase
{
protected override void OnEnter(IFsm<IProcedureManager> procedureOwner)
{
base.OnEnter(procedureOwner);
GameApp.Event.Fire(this, AssetPatchStatesChangeEventArgs.Create(ResourceComponent.BuildInPackageName, EPatchStates.DownloadWebFiles));
BeginDownload(procedureOwner).Forget();
}
private async UniTaskVoid BeginDownload(IFsm<IProcedureManager> procedureOwner)
{
var downloader = (ResourceDownloaderOperation)procedureOwner.GetData<VarObject>("Downloader").GetValue();
// 注册下载回调
void DownloaderOnDownloadErrorCallback(string packageName, string name, string error)
{
GameApp.Event.Fire(this, AssetWebFileDownloadFailedEventArgs.Create(packageName, name, error));
ChangeState<ProcedureCreateDownloader>(procedureOwner);
}
downloader.OnDownloadErrorCallback = DownloaderOnDownloadErrorCallback;
downloader.OnDownloadProgressCallback = OnDownloadProgressCallback;
downloader.BeginDownload();
await downloader;
// 检测下载结果
if (downloader.Status != EOperationStatus.Succeed)
{
Log.Debug("全部下载完毕!");
return;
}
ChangeState<ProcedurePatchDone>(procedureOwner);
}
private void OnDownloadProgressCallback(string packageName, int totalDownloadCount, int currentDownloadCount, long totalDownloadBytes, long currentDownloadBytes)
{
GameApp.Event.Fire(this, AssetDownloadProgressUpdateEventArgs.Create(packageName, totalDownloadCount, currentDownloadCount, totalDownloadBytes, currentDownloadBytes));
}
}
}