Add package update method

新增指定资源版本的资源更新下载方法。
This commit is contained in:
hevinci
2022-05-01 20:33:50 +08:00
parent 47af58bb5b
commit ce70eebda6
10 changed files with 403 additions and 75 deletions
@@ -3,11 +3,12 @@ using System.Collections.Generic;
namespace YooAsset
{
public class DownloaderOperation : AsyncOperationBase
public abstract class DownloaderOperation : AsyncOperationBase
{
private enum ESteps
{
None,
Check,
Loading,
Done,
}
@@ -17,8 +18,8 @@ namespace YooAsset
public delegate void OnDownloadOver(bool isSucceed);
public delegate void OnDownloadProgress(int totalDownloadCount, int currentDownloadCount, long totalDownloadBytes, long currentDownloadBytes);
public delegate void OnDownloadFileFailed(string fileName);
private readonly int _fileLoadingMaxNumber;
private readonly int _downloadingMaxNumber;
private readonly int _failedTryAgain;
private readonly List<BundleInfo> _downloadList;
private readonly List<BundleInfo> _loadFailedList = new List<BundleInfo>();
@@ -67,28 +68,45 @@ namespace YooAsset
public OnDownloadFileFailed OnDownloadFileFailedCallback { set; get; }
internal DownloaderOperation(List<BundleInfo> downloadList, int fileLoadingMaxNumber, int failedTryAgain)
internal DownloaderOperation(List<BundleInfo> downloadList, int downloadingMaxNumber, int failedTryAgain)
{
_downloadList = downloadList;
_fileLoadingMaxNumber = UnityEngine.Mathf.Clamp(fileLoadingMaxNumber, 1, MAX_LOADER_COUNT); ;
_downloadingMaxNumber = UnityEngine.Mathf.Clamp(downloadingMaxNumber, 1, MAX_LOADER_COUNT); ;
_failedTryAgain = failedTryAgain;
TotalDownloadCount = downloadList.Count;
foreach (var patchBundle in downloadList)
if (downloadList != null)
{
TotalDownloadBytes += patchBundle.SizeBytes;
TotalDownloadCount = downloadList.Count;
foreach (var patchBundle in downloadList)
{
TotalDownloadBytes += patchBundle.SizeBytes;
}
}
}
internal override void Start()
{
YooLogger.Log($"Begine to download : {TotalDownloadCount} files and {TotalDownloadBytes} bytes");
_steps = ESteps.Loading;
_steps = ESteps.Check;
}
internal override void Update()
{
if (_steps == ESteps.None || _steps == ESteps.Done)
return;
if (_steps == ESteps.Check)
{
if (_downloadList == null)
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = "Download list is null.";
}
else
{
_steps = ESteps.Loading;
}
}
if (_steps == ESteps.Loading)
{
// 检测下载器结果
@@ -134,7 +152,7 @@ namespace YooAsset
// 注意:如果期间有下载失败的文件,暂停动态创建下载器
if (_downloadList.Count > 0 && _loadFailedList.Count == 0)
{
if (_downloaders.Count < _fileLoadingMaxNumber)
if (_downloaders.Count < _downloadingMaxNumber)
{
int index = _downloadList.Count - 1;
var operation = DownloadSystem.BeginDownload(_downloadList[index], _failedTryAgain);
@@ -177,4 +195,26 @@ namespace YooAsset
}
}
}
public sealed class PackageDownloaderOperation : DownloaderOperation
{
internal PackageDownloaderOperation(List<BundleInfo> downloadList, int downloadingMaxNumber, int failedTryAgain)
: base(downloadList, downloadingMaxNumber, failedTryAgain)
{
}
}
public sealed class PatchDownloaderOperation : DownloaderOperation
{
internal PatchDownloaderOperation(List<BundleInfo> downloadList, int downloadingMaxNumber, int failedTryAgain)
: base(downloadList, downloadingMaxNumber, failedTryAgain)
{
}
}
public sealed class PatchUnpackerOperation : DownloaderOperation
{
internal PatchUnpackerOperation(List<BundleInfo> downloadList, int downloadingMaxNumber, int failedTryAgain)
: base(downloadList, downloadingMaxNumber, failedTryAgain)
{
}
}
}