diff --git a/Assets/YooAsset/Runtime/PatchSystem/PlayMode/HostPlayModeImpl.cs b/Assets/YooAsset/Runtime/PatchSystem/PlayMode/HostPlayModeImpl.cs index 5447b10..660b50c 100644 --- a/Assets/YooAsset/Runtime/PatchSystem/PlayMode/HostPlayModeImpl.cs +++ b/Assets/YooAsset/Runtime/PatchSystem/PlayMode/HostPlayModeImpl.cs @@ -59,6 +59,38 @@ namespace YooAsset return LocalPatchManifest.ResourceVersion; } + /// + /// 创建下载器 + /// + public DownloaderOperation CreateDownloaderByAll(int fileLoadingMaxNumber, int failedTryAgain) + { + List downloadList = GetDownloadListByAll(); + var operation = new DownloaderOperation(downloadList, fileLoadingMaxNumber, failedTryAgain); + return operation; + } + private List GetDownloadListByAll() + { + List downloadList = new List(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); + } + /// /// 创建下载器 /// diff --git a/Assets/YooAsset/Runtime/YooAssets.cs b/Assets/YooAsset/Runtime/YooAssets.cs index e328466..106a4cf 100644 --- a/Assets/YooAsset/Runtime/YooAssets.cs +++ b/Assets/YooAsset/Runtime/YooAssets.cs @@ -396,7 +396,7 @@ namespace YooAsset throw new NotImplementedException(); } } - + /// /// 同步加载资源对象 @@ -500,7 +500,7 @@ namespace YooAsset #region 资源下载接口 /// - /// 创建补丁下载器 + /// 创建补丁下载器,用于更新下载资源标签指定的文件 /// /// 资源标签 /// 同时下载的最大文件数 @@ -511,20 +511,14 @@ namespace YooAsset } /// - /// 创建补丁下载器 + /// 创建补丁下载器,用于更新下载资源标签指定的文件 /// /// 资源标签列表 /// 同时下载的最大文件数 /// 下载失败的重试次数 public static DownloaderOperation CreatePatchDownloader(string[] tags, int downloadingMaxNumber, int failedTryAgain) { - if (_playMode == EPlayMode.EditorPlayMode) - { - List downloadList = new List(); - var operation = new DownloaderOperation(downloadList, downloadingMaxNumber, failedTryAgain); - return operation; - } - else if (_playMode == EPlayMode.OfflinePlayMode) + if (_playMode == EPlayMode.EditorPlayMode || _playMode == EPlayMode.OfflinePlayMode) { List downloadList = new List(); var operation = new DownloaderOperation(downloadList, downloadingMaxNumber, failedTryAgain); @@ -543,20 +537,39 @@ namespace YooAsset } /// - /// 创建资源包下载器 + /// 创建补丁下载器,用于更新下载所有文件 + /// + /// 同时下载的最大文件数 + /// 下载失败的重试次数 + public static DownloaderOperation CreatePatchDownloader(int downloadingMaxNumber, int failedTryAgain) + { + if (_playMode == EPlayMode.EditorPlayMode || _playMode == EPlayMode.OfflinePlayMode) + { + List downloadList = new List(); + 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(); + } + } + + /// + /// 创建资源包下载器,用于更新下载指定的资源列表 /// /// 资源列表 /// 同时下载的最大文件数 /// 下载失败的重试次数 public static DownloaderOperation CreateBundleDownloader(string[] locations, int downloadingMaxNumber, int failedTryAgain) { - if (_playMode == EPlayMode.EditorPlayMode) - { - List downloadList = new List(); - var operation = new DownloaderOperation(downloadList, downloadingMaxNumber, failedTryAgain); - return operation; - } - else if (_playMode == EPlayMode.OfflinePlayMode) + if (_playMode == EPlayMode.EditorPlayMode || _playMode == EPlayMode.OfflinePlayMode) { List downloadList = new List(); var operation = new DownloaderOperation(downloadList, downloadingMaxNumber, failedTryAgain);