Patch DownLoader added a method to download all resources.

补丁下载器新增下载全部资源的方法。
pull/9/head
hevinci 2022-05-01 15:26:48 +08:00
parent b0397981ce
commit 47af58bb5b
2 changed files with 63 additions and 18 deletions

View File

@ -59,6 +59,38 @@ namespace YooAsset
return LocalPatchManifest.ResourceVersion; return LocalPatchManifest.ResourceVersion;
} }
/// <summary>
/// 创建下载器
/// </summary>
public DownloaderOperation CreateDownloaderByAll(int fileLoadingMaxNumber, int failedTryAgain)
{
List<BundleInfo> downloadList = GetDownloadListByAll();
var operation = new DownloaderOperation(downloadList, fileLoadingMaxNumber, failedTryAgain);
return operation;
}
private List<BundleInfo> GetDownloadListByAll()
{
List<PatchBundle> downloadList = new List<PatchBundle>(1000);
foreach (var patchBundle in LocalPatchManifest.BundleList)
{
// 忽略缓存文件
if (DownloadSystem.ContainsVerifyFile(patchBundle.Hash))
continue;
// 忽略APP资源
// 注意如果是APP资源并且哈希值相同则不需要下载
if (AppPatchManifest.Bundles.TryGetValue(patchBundle.BundleName, out PatchBundle appPatchBundle))
{
if (appPatchBundle.IsBuildin && appPatchBundle.Hash == patchBundle.Hash)
continue;
}
downloadList.Add(patchBundle);
}
return ConvertToDownloadList(downloadList);
}
/// <summary> /// <summary>
/// 创建下载器 /// 创建下载器
/// </summary> /// </summary>

View File

@ -396,7 +396,7 @@ namespace YooAsset
throw new NotImplementedException(); throw new NotImplementedException();
} }
} }
/// <summary> /// <summary>
/// 同步加载资源对象 /// 同步加载资源对象
@ -500,7 +500,7 @@ namespace YooAsset
#region 资源下载接口 #region 资源下载接口
/// <summary> /// <summary>
/// 创建补丁下载器 /// 创建补丁下载器,用于更新下载资源标签指定的文件
/// </summary> /// </summary>
/// <param name="tag">资源标签</param> /// <param name="tag">资源标签</param>
/// <param name="downloadingMaxNumber">同时下载的最大文件数</param> /// <param name="downloadingMaxNumber">同时下载的最大文件数</param>
@ -511,20 +511,14 @@ namespace YooAsset
} }
/// <summary> /// <summary>
/// 创建补丁下载器 /// 创建补丁下载器,用于更新下载资源标签指定的文件
/// </summary> /// </summary>
/// <param name="tags">资源标签列表</param> /// <param name="tags">资源标签列表</param>
/// <param name="downloadingMaxNumber">同时下载的最大文件数</param> /// <param name="downloadingMaxNumber">同时下载的最大文件数</param>
/// <param name="failedTryAgain">下载失败的重试次数</param> /// <param name="failedTryAgain">下载失败的重试次数</param>
public static DownloaderOperation CreatePatchDownloader(string[] tags, int downloadingMaxNumber, int failedTryAgain) public static DownloaderOperation CreatePatchDownloader(string[] tags, int downloadingMaxNumber, int failedTryAgain)
{ {
if (_playMode == EPlayMode.EditorPlayMode) if (_playMode == EPlayMode.EditorPlayMode || _playMode == EPlayMode.OfflinePlayMode)
{
List<BundleInfo> downloadList = new List<BundleInfo>();
var operation = new DownloaderOperation(downloadList, downloadingMaxNumber, failedTryAgain);
return operation;
}
else if (_playMode == EPlayMode.OfflinePlayMode)
{ {
List<BundleInfo> downloadList = new List<BundleInfo>(); List<BundleInfo> downloadList = new List<BundleInfo>();
var operation = new DownloaderOperation(downloadList, downloadingMaxNumber, failedTryAgain); var operation = new DownloaderOperation(downloadList, downloadingMaxNumber, failedTryAgain);
@ -543,20 +537,39 @@ namespace YooAsset
} }
/// <summary> /// <summary>
/// 创建资源包下载器 /// 创建补丁下载器,用于更新下载所有文件
/// </summary>
/// <param name="downloadingMaxNumber">同时下载的最大文件数</param>
/// <param name="failedTryAgain">下载失败的重试次数</param>
public static DownloaderOperation CreatePatchDownloader(int downloadingMaxNumber, int failedTryAgain)
{
if (_playMode == EPlayMode.EditorPlayMode || _playMode == EPlayMode.OfflinePlayMode)
{
List<BundleInfo> downloadList = new List<BundleInfo>();
var operation = new DownloaderOperation(downloadList, downloadingMaxNumber, failedTryAgain);
return operation;
}
else if (_playMode == EPlayMode.HostPlayMode)
{
if (_hostPlayModeImpl == null)
throw new Exception("YooAsset is not initialized.");
return _hostPlayModeImpl.CreateDownloaderByAll(downloadingMaxNumber, failedTryAgain);
}
else
{
throw new NotImplementedException();
}
}
/// <summary>
/// 创建资源包下载器,用于更新下载指定的资源列表
/// </summary> /// </summary>
/// <param name="locations">资源列表</param> /// <param name="locations">资源列表</param>
/// <param name="downloadingMaxNumber">同时下载的最大文件数</param> /// <param name="downloadingMaxNumber">同时下载的最大文件数</param>
/// <param name="failedTryAgain">下载失败的重试次数</param> /// <param name="failedTryAgain">下载失败的重试次数</param>
public static DownloaderOperation CreateBundleDownloader(string[] locations, int downloadingMaxNumber, int failedTryAgain) public static DownloaderOperation CreateBundleDownloader(string[] locations, int downloadingMaxNumber, int failedTryAgain)
{ {
if (_playMode == EPlayMode.EditorPlayMode) if (_playMode == EPlayMode.EditorPlayMode || _playMode == EPlayMode.OfflinePlayMode)
{
List<BundleInfo> downloadList = new List<BundleInfo>();
var operation = new DownloaderOperation(downloadList, downloadingMaxNumber, failedTryAgain);
return operation;
}
else if (_playMode == EPlayMode.OfflinePlayMode)
{ {
List<BundleInfo> downloadList = new List<BundleInfo>(); List<BundleInfo> downloadList = new List<BundleInfo>();
var operation = new DownloaderOperation(downloadList, downloadingMaxNumber, failedTryAgain); var operation = new DownloaderOperation(downloadList, downloadingMaxNumber, failedTryAgain);