From bcd53cf8346583570725db2e9a1fe0dd1b119fcd Mon Sep 17 00:00:00 2001 From: hevinci Date: Fri, 25 Mar 2022 15:02:21 +0800 Subject: [PATCH] Update PatchSystem --- .../PatchSystem/PlayMode/HostPlayModeImpl.cs | 66 +++---------------- .../PlayMode/OfflinePlayModeImpl.cs | 14 +++- Assets/YooAsset/Runtime/Utility/YooHelper.cs | 59 +++++++++++++++++ Assets/YooAsset/Runtime/YooAssets.cs | 6 +- 4 files changed, 82 insertions(+), 63 deletions(-) diff --git a/Assets/YooAsset/Runtime/PatchSystem/PlayMode/HostPlayModeImpl.cs b/Assets/YooAsset/Runtime/PatchSystem/PlayMode/HostPlayModeImpl.cs index a1f1343..07d358d 100644 --- a/Assets/YooAsset/Runtime/PatchSystem/PlayMode/HostPlayModeImpl.cs +++ b/Assets/YooAsset/Runtime/PatchSystem/PlayMode/HostPlayModeImpl.cs @@ -160,51 +160,20 @@ namespace YooAsset /// public DownloaderOperation CreateUnpackerByTags(string[] tags, int fileUpackingMaxNumber, int failedTryAgain) { - List unpcakList = GetUnpackListByTags(tags); + List unpcakList = PatchHelper.GetUnpackListByTags(AppPatchManifest, 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 = SandboxHelper.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) + public string GetPatchDownloadMainURL(int resourceVersion, string fileName) { if (IgnoreResourceVersion) return $"{_defaultHostServer}/{fileName}"; else return $"{_defaultHostServer}/{resourceVersion}/{fileName}"; } - internal string GetPatchDownloadFallbackURL(int resourceVersion, string fileName) + public string GetPatchDownloadFallbackURL(int resourceVersion, string fileName) { if (IgnoreResourceVersion) return $"{_fallbackHostServer}/{fileName}"; @@ -213,15 +182,6 @@ namespace YooAsset } // 下载相关 - private BundleInfo ConvertToDownloadInfo(PatchBundle patchBundle) - { - // 注意:资源版本号只用于确定下载路径 - string sandboxPath = SandboxHelper.MakeSandboxCacheFilePath(patchBundle.Hash); - string remoteMainURL = GetPatchDownloadMainURL(patchBundle.Version, patchBundle.Hash); - string remoteFallbackURL = GetPatchDownloadFallbackURL(patchBundle.Version, patchBundle.Hash); - BundleInfo bundleInfo = new BundleInfo(patchBundle, sandboxPath, remoteMainURL, remoteFallbackURL); - return bundleInfo; - } private List ConvertToDownloadList(List downloadList) { List result = new List(downloadList.Count); @@ -232,25 +192,15 @@ namespace YooAsset } return result; } - - // 解压相关 - private BundleInfo ConvertToUnpackInfo(PatchBundle patchBundle) + private BundleInfo ConvertToDownloadInfo(PatchBundle patchBundle) { + // 注意:资源版本号只用于确定下载路径 string sandboxPath = SandboxHelper.MakeSandboxCacheFilePath(patchBundle.Hash); - string streamingLoadPath = PathHelper.MakeStreamingLoadPath(patchBundle.Hash); - BundleInfo bundleInfo = new BundleInfo(patchBundle, sandboxPath, streamingLoadPath, streamingLoadPath); + string remoteMainURL = GetPatchDownloadMainURL(patchBundle.Version, patchBundle.Hash); + string remoteFallbackURL = GetPatchDownloadFallbackURL(patchBundle.Version, patchBundle.Hash); + BundleInfo bundleInfo = new BundleInfo(patchBundle, sandboxPath, remoteMainURL, remoteFallbackURL); 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接口 BundleInfo IBundleServices.GetBundleInfo(string bundleName) diff --git a/Assets/YooAsset/Runtime/PatchSystem/PlayMode/OfflinePlayModeImpl.cs b/Assets/YooAsset/Runtime/PatchSystem/PlayMode/OfflinePlayModeImpl.cs index fb6b6ad..9453c39 100644 --- a/Assets/YooAsset/Runtime/PatchSystem/PlayMode/OfflinePlayModeImpl.cs +++ b/Assets/YooAsset/Runtime/PatchSystem/PlayMode/OfflinePlayModeImpl.cs @@ -7,7 +7,7 @@ namespace YooAsset internal class OfflinePlayModeImpl : IBundleServices { internal PatchManifest AppPatchManifest; - + /// /// 异步初始化 /// @@ -24,10 +24,20 @@ namespace YooAsset public int GetResourceVersion() { if (AppPatchManifest == null) - return 0; + return 0; return AppPatchManifest.ResourceVersion; } + /// + /// 创建解压器 + /// + public DownloaderOperation CreateUnpackerByTags(string[] tags, int fileUpackingMaxNumber, int failedTryAgain) + { + List unpcakList = PatchHelper.GetUnpackListByTags(AppPatchManifest, tags); + var operation = new DownloaderOperation(unpcakList, fileUpackingMaxNumber, failedTryAgain); + return operation; + } + #region IBundleServices接口 BundleInfo IBundleServices.GetBundleInfo(string bundleName) { diff --git a/Assets/YooAsset/Runtime/Utility/YooHelper.cs b/Assets/YooAsset/Runtime/Utility/YooHelper.cs index 21797cf..1418362 100644 --- a/Assets/YooAsset/Runtime/Utility/YooHelper.cs +++ b/Assets/YooAsset/Runtime/Utility/YooHelper.cs @@ -1,4 +1,5 @@ using System.IO; +using System.Collections.Generic; namespace YooAsset { @@ -220,4 +221,62 @@ namespace YooAsset return PathHelper.MakePersistentLoadPath($"{StrCacheFolderName}/{fileName}"); } } + + /// + /// 补丁包帮助类 + /// + internal static class PatchHelper + { + /// + /// 获取内置资源解压列表 + /// + public static List GetUnpackListByTags(PatchManifest appPatchManifest, string[] tags) + { + List downloadList = new List(1000); + foreach (var patchBundle in appPatchManifest.BundleList) + { + // 如果已经在沙盒内 + string filePath = SandboxHelper.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); + } + private static List ConvertToUnpackList(List unpackList) + { + List result = new List(unpackList.Count); + foreach (var patchBundle in unpackList) + { + var bundleInfo = ConvertToUnpackInfo(patchBundle); + result.Add(bundleInfo); + } + return result; + } + private static BundleInfo ConvertToUnpackInfo(PatchBundle patchBundle) + { + string sandboxPath = SandboxHelper.MakeSandboxCacheFilePath(patchBundle.Hash); + string streamingLoadPath = PathHelper.MakeStreamingLoadPath(patchBundle.Hash); + BundleInfo bundleInfo = new BundleInfo(patchBundle, sandboxPath, streamingLoadPath, streamingLoadPath); + return bundleInfo; + } + } } \ No newline at end of file diff --git a/Assets/YooAsset/Runtime/YooAssets.cs b/Assets/YooAsset/Runtime/YooAssets.cs index 315e358..bb99eb3 100644 --- a/Assets/YooAsset/Runtime/YooAssets.cs +++ b/Assets/YooAsset/Runtime/YooAssets.cs @@ -538,9 +538,9 @@ namespace YooAsset } else if (_playMode == EPlayMode.OfflinePlayMode) { - List downloadList = new List(); - var operation = new DownloaderOperation(downloadList, unpackingMaxNumber, failedTryAgain); - return operation; + if (_offlinePlayModeImpl == null) + throw new Exception("YooAsset is not initialized."); + return _offlinePlayModeImpl.CreateUnpackerByTags(tags, unpackingMaxNumber, failedTryAgain); } else if (_playMode == EPlayMode.HostPlayMode) {