diff --git a/Assets/YooAsset/Runtime/PatchSystem/Operations/DownloaderOperation.cs b/Assets/YooAsset/Runtime/PatchSystem/Operations/DownloaderOperation.cs index 6dd7ee0..a3622de 100644 --- a/Assets/YooAsset/Runtime/PatchSystem/Operations/DownloaderOperation.cs +++ b/Assets/YooAsset/Runtime/PatchSystem/Operations/DownloaderOperation.cs @@ -15,9 +15,9 @@ namespace YooAsset private const int MAX_LOADER_COUNT = 64; public delegate void OnDownloadOver(bool isSucceed); - public delegate void OnDownloadProgress(int totalDownloadCount, int currentDownloadCoun, long totalDownloadBytes, long currentDownloadBytes); + 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 _failedTryAgain; private readonly List _downloadList; diff --git a/Assets/YooAsset/Runtime/PatchSystem/PlayMode/HostPlayModeImpl.cs b/Assets/YooAsset/Runtime/PatchSystem/PlayMode/HostPlayModeImpl.cs index 20ca85f..e2732fc 100644 --- a/Assets/YooAsset/Runtime/PatchSystem/PlayMode/HostPlayModeImpl.cs +++ b/Assets/YooAsset/Runtime/PatchSystem/PlayMode/HostPlayModeImpl.cs @@ -155,6 +155,47 @@ namespace YooAsset return ConvertToDownloadList(downloadList); } + /// + /// 创建解压器 + /// + public DownloaderOperation CreateUnpackerByTags(string[] tags, int fileUpackingMaxNumber, int failedTryAgain) + { + List unpcakList = GetUnpackListByTags(tags); + var operation = new DownloaderOperation(unpcakList, fileUpackingMaxNumber, failedTryAgain); + return operation; + } + private List GetUnpackListByTags(string[] tags) + { + List downloadList = new List(1000); + foreach (var patchBundle in AppPatchManifest.BundleList) + { + // 如果已经在沙盒内 + string filePath = PatchHelper.MakeSandboxCacheFilePath(patchBundle.Hash); + if (System.IO.File.Exists(filePath)) + continue; + + // 如果不是内置资源 + if (patchBundle.IsBuildin == false) + continue; + + // 如果是纯内置资源 + if (patchBundle.IsPureBuildin()) + { + downloadList.Add(patchBundle); + } + else + { + // 查询DLC资源 + if (patchBundle.HasTag(tags)) + { + downloadList.Add(patchBundle); + } + } + } + + return ConvertToUnpackList(downloadList); + } + // WEB相关 internal string GetPatchDownloadMainURL(int resourceVersion, string fileName) { @@ -192,6 +233,25 @@ namespace YooAsset return result; } + // 解压相关 + private AssetBundleInfo ConvertToUnpackInfo(PatchBundle patchBundle) + { + string sandboxPath = PatchHelper.MakeSandboxCacheFilePath(patchBundle.Hash); + string streamingLoadPath = AssetPathHelper.MakeStreamingLoadPath(patchBundle.Hash); + AssetBundleInfo bundleInfo = new AssetBundleInfo(patchBundle, sandboxPath, streamingLoadPath, streamingLoadPath); + return bundleInfo; + } + private List ConvertToUnpackList(List unpackList) + { + List result = new List(unpackList.Count); + foreach (var patchBundle in unpackList) + { + var bundleInfo = ConvertToUnpackInfo(patchBundle); + result.Add(bundleInfo); + } + return result; + } + #region IBundleServices接口 AssetBundleInfo IBundleServices.GetAssetBundleInfo(string bundleName) { diff --git a/Assets/YooAsset/Runtime/YooAssets.cs b/Assets/YooAsset/Runtime/YooAssets.cs index 4caf8cf..8c1c259 100644 --- a/Assets/YooAsset/Runtime/YooAssets.cs +++ b/Assets/YooAsset/Runtime/YooAssets.cs @@ -455,6 +455,51 @@ namespace YooAsset } #endregion + #region 资源解压接口 + /// + /// 创建补丁解压器 + /// + /// 资源标签 + /// 同时解压的最大文件数 + /// 解压失败的重试次数 + public static DownloaderOperation CreatePatchUnpacker(string tag, int unpackingMaxNumber, int failedTryAgain) + { + return CreatePatchUnpacker(new string[] { tag }, unpackingMaxNumber, failedTryAgain); + } + + /// + /// 创建补丁解压器 + /// + /// 资源标签列表 + /// 同时解压的最大文件数 + /// 解压失败的重试次数 + public static DownloaderOperation CreatePatchUnpacker(string[] tags, int unpackingMaxNumber, int failedTryAgain) + { + if (_playMode == EPlayMode.EditorPlayMode) + { + List downloadList = new List(); + var operation = new DownloaderOperation(downloadList, unpackingMaxNumber, failedTryAgain); + return operation; + } + else if (_playMode == EPlayMode.OfflinePlayMode) + { + List downloadList = new List(); + var operation = new DownloaderOperation(downloadList, unpackingMaxNumber, failedTryAgain); + return operation; + } + else if (_playMode == EPlayMode.HostPlayMode) + { + if (_hostPlayModeImpl == null) + throw new Exception("YooAsset is not initialized."); + return _hostPlayModeImpl.CreateUnpackerByTags(tags, unpackingMaxNumber, failedTryAgain); + } + else + { + throw new NotImplementedException(); + } + } + #endregion + #region 沙盒相关 /// /// 清空沙盒目录