From ce70eebda648e76a157f83da8dd992e6f377207f Mon Sep 17 00:00:00 2001 From: hevinci Date: Sun, 1 May 2022 20:33:50 +0800 Subject: [PATCH] Add package update method MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 新增指定资源版本的资源更新下载方法。 --- .../Operations/InstantiateOperation.cs | 2 +- .../Operations/UnloadSceneOperation.cs | 2 +- .../OperationSystem/AsyncOperationBase.cs | 6 +- .../Operations/DownloaderOperation.cs | 60 ++++- .../Operations/UpdateManifestOperation.cs | 41 ++-- .../Operations/UpdatePackageOperation.cs | 231 ++++++++++++++++++ .../Operations/UpdatePackageOperation.cs.meta | 11 + .../PatchSystem/PlayMode/HostPlayModeImpl.cs | 34 ++- .../PlayMode/OfflinePlayModeImpl.cs | 4 +- Assets/YooAsset/Runtime/YooAssets.cs | 87 +++++-- 10 files changed, 403 insertions(+), 75 deletions(-) create mode 100644 Assets/YooAsset/Runtime/PatchSystem/Operations/UpdatePackageOperation.cs create mode 100644 Assets/YooAsset/Runtime/PatchSystem/Operations/UpdatePackageOperation.cs.meta diff --git a/Assets/YooAsset/Runtime/AssetSystem/Operations/InstantiateOperation.cs b/Assets/YooAsset/Runtime/AssetSystem/Operations/InstantiateOperation.cs index 9265be6..7ce6d6f 100644 --- a/Assets/YooAsset/Runtime/AssetSystem/Operations/InstantiateOperation.cs +++ b/Assets/YooAsset/Runtime/AssetSystem/Operations/InstantiateOperation.cs @@ -2,7 +2,7 @@ namespace YooAsset { - public class InstantiateOperation : AsyncOperationBase + public sealed class InstantiateOperation : AsyncOperationBase { private enum ESteps { diff --git a/Assets/YooAsset/Runtime/AssetSystem/Operations/UnloadSceneOperation.cs b/Assets/YooAsset/Runtime/AssetSystem/Operations/UnloadSceneOperation.cs index a1e453d..12ba3d3 100644 --- a/Assets/YooAsset/Runtime/AssetSystem/Operations/UnloadSceneOperation.cs +++ b/Assets/YooAsset/Runtime/AssetSystem/Operations/UnloadSceneOperation.cs @@ -6,7 +6,7 @@ namespace YooAsset /// /// 场景卸载异步操作类 /// - public class UnloadSceneOperation : AsyncOperationBase + public sealed class UnloadSceneOperation : AsyncOperationBase { private enum EFlag { diff --git a/Assets/YooAsset/Runtime/OperationSystem/AsyncOperationBase.cs b/Assets/YooAsset/Runtime/OperationSystem/AsyncOperationBase.cs index a342fa3..9af6f04 100644 --- a/Assets/YooAsset/Runtime/OperationSystem/AsyncOperationBase.cs +++ b/Assets/YooAsset/Runtime/OperationSystem/AsyncOperationBase.cs @@ -77,14 +77,14 @@ namespace YooAsset } #region 异步编程相关 - public bool MoveNext() + bool IEnumerator.MoveNext() { return !IsDone; } - public void Reset() + void IEnumerator.Reset() { } - public object Current => null; + object IEnumerator.Current => null; private TaskCompletionSource _taskCompletionSource; #endregion diff --git a/Assets/YooAsset/Runtime/PatchSystem/Operations/DownloaderOperation.cs b/Assets/YooAsset/Runtime/PatchSystem/Operations/DownloaderOperation.cs index 1a99adc..ddf6135 100644 --- a/Assets/YooAsset/Runtime/PatchSystem/Operations/DownloaderOperation.cs +++ b/Assets/YooAsset/Runtime/PatchSystem/Operations/DownloaderOperation.cs @@ -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 _downloadList; private readonly List _loadFailedList = new List(); @@ -67,28 +68,45 @@ namespace YooAsset public OnDownloadFileFailed OnDownloadFileFailedCallback { set; get; } - internal DownloaderOperation(List downloadList, int fileLoadingMaxNumber, int failedTryAgain) + internal DownloaderOperation(List 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 downloadList, int downloadingMaxNumber, int failedTryAgain) + : base(downloadList, downloadingMaxNumber, failedTryAgain) + { + } + } + public sealed class PatchDownloaderOperation : DownloaderOperation + { + internal PatchDownloaderOperation(List downloadList, int downloadingMaxNumber, int failedTryAgain) + : base(downloadList, downloadingMaxNumber, failedTryAgain) + { + } + } + public sealed class PatchUnpackerOperation : DownloaderOperation + { + internal PatchUnpackerOperation(List downloadList, int downloadingMaxNumber, int failedTryAgain) + : base(downloadList, downloadingMaxNumber, failedTryAgain) + { + } + } } \ No newline at end of file diff --git a/Assets/YooAsset/Runtime/PatchSystem/Operations/UpdateManifestOperation.cs b/Assets/YooAsset/Runtime/PatchSystem/Operations/UpdateManifestOperation.cs index fe300e2..a560849 100644 --- a/Assets/YooAsset/Runtime/PatchSystem/Operations/UpdateManifestOperation.cs +++ b/Assets/YooAsset/Runtime/PatchSystem/Operations/UpdateManifestOperation.cs @@ -53,24 +53,24 @@ namespace YooAsset CheckWebManifestHash, LoadWebManifest, CheckWebManifest, - InitPrepareCache, - UpdatePrepareCache, + InitVerifyingCache, + UpdateVerifyingCache, Done, } private static int RequestCount = 0; private readonly HostPlayModeImpl _impl; - private readonly int _updateResourceVersion; + private readonly int _resourceVersion; private readonly int _timeout; private ESteps _steps = ESteps.None; private UnityWebDataRequester _downloaderHash; private UnityWebDataRequester _downloaderManifest; private float _verifyTime; - public HostPlayModeUpdateManifestOperation(HostPlayModeImpl impl, int updateResourceVersion, int timeout) + internal HostPlayModeUpdateManifestOperation(HostPlayModeImpl impl, int resourceVersion, int timeout) { _impl = impl; - _updateResourceVersion = updateResourceVersion; + _resourceVersion = resourceVersion; _timeout = timeout; } internal override void Start() @@ -85,7 +85,7 @@ namespace YooAsset if (_steps == ESteps.LoadWebManifestHash) { - string webURL = GetPatchManifestRequestURL(YooAssetSettingsData.GetPatchManifestHashFileName(_updateResourceVersion)); + string webURL = GetPatchManifestRequestURL(YooAssetSettingsData.GetPatchManifestHashFileName(_resourceVersion)); YooLogger.Log($"Beginning to request patch manifest hash : {webURL}"); _downloaderHash = new UnityWebDataRequester(); _downloaderHash.SendRequest(webURL, _timeout); @@ -107,14 +107,14 @@ namespace YooAsset else { string webManifestHash = _downloaderHash.GetText(); - string cachedManifestHash = GetSandboxPatchManifestFileHash(_updateResourceVersion); + string cachedManifestHash = GetSandboxPatchManifestFileHash(_resourceVersion); // 如果补丁清单文件的哈希值相同 if (cachedManifestHash == webManifestHash) { YooLogger.Log($"Patch manifest file hash is not change : {webManifestHash}"); - LoadSandboxPatchManifest(_updateResourceVersion); - _steps = ESteps.InitPrepareCache; + LoadSandboxPatchManifest(_resourceVersion); + _steps = ESteps.InitVerifyingCache; } else { @@ -127,7 +127,7 @@ namespace YooAsset if (_steps == ESteps.LoadWebManifest) { - string webURL = GetPatchManifestRequestURL(YooAssetSettingsData.GetPatchManifestFileName(_updateResourceVersion)); + string webURL = GetPatchManifestRequestURL(YooAssetSettingsData.GetPatchManifestFileName(_resourceVersion)); YooLogger.Log($"Beginning to request patch manifest : {webURL}"); _downloaderManifest = new UnityWebDataRequester(); _downloaderManifest.SendRequest(webURL, _timeout); @@ -149,9 +149,9 @@ namespace YooAsset else { // 解析补丁清单 - if (ParseAndSaveRemotePatchManifest(_updateResourceVersion, _downloaderManifest.GetText())) + if (ParseAndSaveRemotePatchManifest(_resourceVersion, _downloaderManifest.GetText())) { - _steps = ESteps.InitPrepareCache; + _steps = ESteps.InitVerifyingCache; } else { @@ -163,16 +163,16 @@ namespace YooAsset _downloaderManifest.Dispose(); } - if (_steps == ESteps.InitPrepareCache) + if (_steps == ESteps.InitVerifyingCache) { - InitPrepareCache(); + InitVerifyingCache(); _verifyTime = UnityEngine.Time.realtimeSinceStartup; - _steps = ESteps.UpdatePrepareCache; + _steps = ESteps.UpdateVerifyingCache; } - if (_steps == ESteps.UpdatePrepareCache) + if (_steps == ESteps.UpdateVerifyingCache) { - if (UpdatePrepareCache()) + if (UpdateVerifyingCache()) { _steps = ESteps.Done; Status = EOperationStatus.Succeed; @@ -182,6 +182,9 @@ namespace YooAsset } } + /// + /// 获取补丁清单请求地址 + /// private string GetPatchManifestRequestURL(string fileName) { // 轮流返回请求地址 @@ -256,7 +259,7 @@ namespace YooAsset private int _verifySuccessCount = 0; private int _verifyFailCount = 0; - private void InitPrepareCache() + private void InitVerifyingCache() { // 遍历所有文件然后验证并缓存合法文件 foreach (var patchBundle in _impl.LocalPatchManifest.BundleList) @@ -286,7 +289,7 @@ namespace YooAsset YooLogger.Log($"Work threads : {workerThreads}, IO threads : {ioThreads}"); _verifyMaxNum = Math.Min(workerThreads, ioThreads); } - private bool UpdatePrepareCache() + private bool UpdateVerifyingCache() { _syncContext.Update(); diff --git a/Assets/YooAsset/Runtime/PatchSystem/Operations/UpdatePackageOperation.cs b/Assets/YooAsset/Runtime/PatchSystem/Operations/UpdatePackageOperation.cs new file mode 100644 index 0000000..8204565 --- /dev/null +++ b/Assets/YooAsset/Runtime/PatchSystem/Operations/UpdatePackageOperation.cs @@ -0,0 +1,231 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.IO; + +namespace YooAsset +{ + public abstract class UpdatePackageOperation : AsyncOperationBase + { + /// + /// 开始下载 + /// + /// 同时下载的最大文件数 + /// 下载失败的重试次数 + public abstract PackageDownloaderOperation BeginDownloadPackage(int downloadingMaxNumber, int failedTryAgain); + } + + /// + /// 编辑器下模拟运行的更新资源包裹操作 + /// + internal sealed class EditorPlayModeUpdatePackageOperation : UpdatePackageOperation + { + internal override void Start() + { + Status = EOperationStatus.Succeed; + } + internal override void Update() + { + } + + /// + /// 开始下载 + /// + public override PackageDownloaderOperation BeginDownloadPackage(int downloadingMaxNumber, int failedTryAgain) + { + List downloadList = new List(); + var operation = new PackageDownloaderOperation(downloadList, downloadingMaxNumber, failedTryAgain); + operation.BeginDownload(); + return operation; + } + } + + /// + /// 离线模式的更新资源包裹操作 + /// + internal sealed class OfflinePlayModeUpdatePackageOperation : UpdatePackageOperation + { + internal override void Start() + { + Status = EOperationStatus.Succeed; + } + internal override void Update() + { + } + + /// + /// 开始下载 + /// + public override PackageDownloaderOperation BeginDownloadPackage(int downloadingMaxNumber, int failedTryAgain) + { + List downloadList = new List(); + var operation = new PackageDownloaderOperation(downloadList, downloadingMaxNumber, failedTryAgain); + operation.BeginDownload(); + return operation; + } + } + + /// + /// 网络模式的更新资源包裹操作 + /// + internal sealed class HostPlayModeUpdatePackageOperation : UpdatePackageOperation + { + private enum ESteps + { + None, + LoadWebManifest, + CheckWebManifest, + Done, + } + + private static int RequestCount = 0; + private readonly HostPlayModeImpl _impl; + private readonly int _resourceVersion; + private readonly int _timeout; + private ESteps _steps = ESteps.None; + private UnityWebDataRequester _downloaderManifest; + private PatchManifest _remotePatchManifest; + + internal HostPlayModeUpdatePackageOperation(HostPlayModeImpl impl, int resourceVersion, int timeout) + { + _impl = impl; + _resourceVersion = resourceVersion; + _timeout = timeout; + } + internal override void Start() + { + RequestCount++; + _steps = ESteps.LoadWebManifest; + } + internal override void Update() + { + if (_steps == ESteps.None || _steps == ESteps.Done) + return; + + if (_steps == ESteps.LoadWebManifest) + { + string webURL = GetPatchManifestRequestURL(YooAssetSettingsData.GetPatchManifestFileName(_resourceVersion)); + YooLogger.Log($"Beginning to request patch manifest : {webURL}"); + _downloaderManifest = new UnityWebDataRequester(); + _downloaderManifest.SendRequest(webURL, _timeout); + _steps = ESteps.CheckWebManifest; + } + + if (_steps == ESteps.CheckWebManifest) + { + if (_downloaderManifest.IsDone() == false) + return; + + // Check error + if (_downloaderManifest.HasError()) + { + _steps = ESteps.Done; + Status = EOperationStatus.Failed; + Error = _downloaderManifest.GetError(); + } + else + { + // 解析补丁清单 + if (ParseRemotePatchManifest(_downloaderManifest.GetText())) + { + _steps = ESteps.Done; + Status = EOperationStatus.Succeed; + } + else + { + _steps = ESteps.Done; + Status = EOperationStatus.Failed; + Error = $"URL : {_downloaderManifest.URL} Error : remote patch manifest content is invalid"; + } + } + _downloaderManifest.Dispose(); + } + } + + /// + /// 开始下载 + /// + public override PackageDownloaderOperation BeginDownloadPackage(int downloadingMaxNumber, int failedTryAgain) + { + if (Status == EOperationStatus.Succeed) + { + List downloadList = GetDownloadList(); + var operation = new PackageDownloaderOperation(downloadList, downloadingMaxNumber, failedTryAgain); + operation.BeginDownload(); + return operation; + } + else + { + YooLogger.Error($"{nameof(UpdatePackageOperation)} status is failed !"); + var operation = new PackageDownloaderOperation(null, downloadingMaxNumber, failedTryAgain); + operation.BeginDownload(); + return operation; + } + } + + /// + /// 获取补丁清单请求地址 + /// + private string GetPatchManifestRequestURL(string fileName) + { + // 轮流返回请求地址 + if (RequestCount % 2 == 0) + return _impl.GetPatchDownloadFallbackURL(fileName); + else + return _impl.GetPatchDownloadMainURL(fileName); + } + + /// + /// 解析远端请求的补丁清单 + /// + private bool ParseRemotePatchManifest(string content) + { + try + { + _remotePatchManifest = PatchManifest.Deserialize(content); + return true; + } + catch (Exception e) + { + YooLogger.Warning(e.ToString()); + return false; + } + } + + /// + /// 获取下载列表 + /// + private List GetDownloadList() + { + List downloadList = new List(1000); + foreach (var patchBundle in _remotePatchManifest.BundleList) + { + // 忽略缓存文件 + if (DownloadSystem.ContainsVerifyFile(patchBundle.Hash)) + continue; + + // 忽略APP资源 + // 注意:如果是APP资源并且哈希值相同,则不需要下载 + if (_impl.AppPatchManifest.Bundles.TryGetValue(patchBundle.BundleName, out PatchBundle appPatchBundle)) + { + if (appPatchBundle.IsBuildin && appPatchBundle.Hash == patchBundle.Hash) + continue; + } + + // 注意:下载系统只会验证当前游戏版本的资源文件,对于其它游戏版本的差异文件不会在初始化的时候去做校验。 + // 注意:通过比对文件大小做实时的文件校验方式! + string filePath = SandboxHelper.MakeSandboxCacheFilePath(patchBundle.Hash); + if (File.Exists(filePath)) + { + long fileSize = FileUtility.GetFileSize(filePath); + if (fileSize == patchBundle.SizeBytes) + continue; + } + + downloadList.Add(patchBundle); + } + + return _impl.ConvertToDownloadList(downloadList); + } + } +} \ No newline at end of file diff --git a/Assets/YooAsset/Runtime/PatchSystem/Operations/UpdatePackageOperation.cs.meta b/Assets/YooAsset/Runtime/PatchSystem/Operations/UpdatePackageOperation.cs.meta new file mode 100644 index 0000000..6c362bd --- /dev/null +++ b/Assets/YooAsset/Runtime/PatchSystem/Operations/UpdatePackageOperation.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: c4b754a3b15abc44fa2727f57721e18b +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/YooAsset/Runtime/PatchSystem/PlayMode/HostPlayModeImpl.cs b/Assets/YooAsset/Runtime/PatchSystem/PlayMode/HostPlayModeImpl.cs index 660b50c..1d8b763 100644 --- a/Assets/YooAsset/Runtime/PatchSystem/PlayMode/HostPlayModeImpl.cs +++ b/Assets/YooAsset/Runtime/PatchSystem/PlayMode/HostPlayModeImpl.cs @@ -42,9 +42,19 @@ namespace YooAsset /// /// 异步更新补丁清单 /// - public UpdateManifestOperation UpdatePatchManifestAsync(int updateResourceVersion, int timeout) + public UpdateManifestOperation UpdatePatchManifestAsync(int resourceVersion, int timeout) { - var operation = new HostPlayModeUpdateManifestOperation(this, updateResourceVersion, timeout); + var operation = new HostPlayModeUpdateManifestOperation(this, resourceVersion, timeout); + OperationSystem.ProcessOperaiton(operation); + return operation; + } + + /// + /// 异步更新资源包裹 + /// + public UpdatePackageOperation UpdatePackageAsync(int resourceVersion, int timeout) + { + var operation = new HostPlayModeUpdatePackageOperation(this, resourceVersion, timeout); OperationSystem.ProcessOperaiton(operation); return operation; } @@ -62,10 +72,10 @@ namespace YooAsset /// /// 创建下载器 /// - public DownloaderOperation CreateDownloaderByAll(int fileLoadingMaxNumber, int failedTryAgain) + public PatchDownloaderOperation CreatePatchDownloaderByAll(int fileLoadingMaxNumber, int failedTryAgain) { List downloadList = GetDownloadListByAll(); - var operation = new DownloaderOperation(downloadList, fileLoadingMaxNumber, failedTryAgain); + var operation = new PatchDownloaderOperation(downloadList, fileLoadingMaxNumber, failedTryAgain); return operation; } private List GetDownloadListByAll() @@ -94,10 +104,10 @@ namespace YooAsset /// /// 创建下载器 /// - public DownloaderOperation CreateDownloaderByTags(string[] tags, int fileLoadingMaxNumber, int failedTryAgain) + public PatchDownloaderOperation CreatePatchDownloaderByTags(string[] tags, int fileLoadingMaxNumber, int failedTryAgain) { List downloadList = GetDownloadListByTags(tags); - var operation = new DownloaderOperation(downloadList, fileLoadingMaxNumber, failedTryAgain); + var operation = new PatchDownloaderOperation(downloadList, fileLoadingMaxNumber, failedTryAgain); return operation; } private List GetDownloadListByTags(string[] tags) @@ -140,10 +150,10 @@ namespace YooAsset /// /// 创建下载器 /// - public DownloaderOperation CreateDownloaderByPaths(List assetPaths, int fileLoadingMaxNumber, int failedTryAgain) + public PatchDownloaderOperation CreatePatchDownloaderByPaths(List assetPaths, int fileLoadingMaxNumber, int failedTryAgain) { List downloadList = GetDownloadListByPaths(assetPaths); - var operation = new DownloaderOperation(downloadList, fileLoadingMaxNumber, failedTryAgain); + var operation = new PatchDownloaderOperation(downloadList, fileLoadingMaxNumber, failedTryAgain); return operation; } private List GetDownloadListByPaths(List assetPaths) @@ -197,10 +207,10 @@ namespace YooAsset /// /// 创建解压器 /// - public DownloaderOperation CreateUnpackerByTags(string[] tags, int fileUpackingMaxNumber, int failedTryAgain) + public PatchUnpackerOperation CreatePatchUnpackerByTags(string[] tags, int fileUpackingMaxNumber, int failedTryAgain) { List unpcakList = PatchHelper.GetUnpackListByTags(AppPatchManifest, tags); - var operation = new DownloaderOperation(unpcakList, fileUpackingMaxNumber, failedTryAgain); + var operation = new PatchUnpackerOperation(unpcakList, fileUpackingMaxNumber, failedTryAgain); return operation; } @@ -215,7 +225,7 @@ namespace YooAsset } // 下载相关 - private List ConvertToDownloadList(List downloadList) + public List ConvertToDownloadList(List downloadList) { List result = new List(downloadList.Count); foreach (var patchBundle in downloadList) @@ -225,7 +235,7 @@ namespace YooAsset } return result; } - private BundleInfo ConvertToDownloadInfo(PatchBundle patchBundle) + public BundleInfo ConvertToDownloadInfo(PatchBundle patchBundle) { // 注意:资源版本号只用于确定下载路径 string remoteMainURL = GetPatchDownloadMainURL(patchBundle.Hash); diff --git a/Assets/YooAsset/Runtime/PatchSystem/PlayMode/OfflinePlayModeImpl.cs b/Assets/YooAsset/Runtime/PatchSystem/PlayMode/OfflinePlayModeImpl.cs index 467b676..73e1880 100644 --- a/Assets/YooAsset/Runtime/PatchSystem/PlayMode/OfflinePlayModeImpl.cs +++ b/Assets/YooAsset/Runtime/PatchSystem/PlayMode/OfflinePlayModeImpl.cs @@ -31,10 +31,10 @@ namespace YooAsset /// /// 创建解压器 /// - public DownloaderOperation CreateUnpackerByTags(string[] tags, int fileUpackingMaxNumber, int failedTryAgain) + public PatchUnpackerOperation CreatePatchUnpackerByTags(string[] tags, int fileUpackingMaxNumber, int failedTryAgain) { List unpcakList = PatchHelper.GetUnpackListByTags(AppPatchManifest, tags); - var operation = new DownloaderOperation(unpcakList, fileUpackingMaxNumber, failedTryAgain); + var operation = new PatchUnpackerOperation(unpcakList, fileUpackingMaxNumber, failedTryAgain); return operation; } diff --git a/Assets/YooAsset/Runtime/YooAssets.cs b/Assets/YooAsset/Runtime/YooAssets.cs index 106a4cf..251ae27 100644 --- a/Assets/YooAsset/Runtime/YooAssets.cs +++ b/Assets/YooAsset/Runtime/YooAssets.cs @@ -216,7 +216,7 @@ namespace YooAsset } /// - /// 向网络端请求静态资源版本号 + /// 向网络端请求静态资源版本 /// /// 超时时间(默认值:60秒) public static UpdateStaticVersionOperation UpdateStaticVersionAsync(int timeout = 60) @@ -248,9 +248,9 @@ namespace YooAsset /// /// 向网络端请求并更新补丁清单 /// - /// 更新的资源版本号 + /// 更新的资源版本 /// 超时时间(默认值:60秒) - public static UpdateManifestOperation UpdateManifestAsync(int updateResourceVersion, int timeout = 60) + public static UpdateManifestOperation UpdateManifestAsync(int resourceVersion, int timeout = 60) { if (_playMode == EPlayMode.EditorPlayMode) { @@ -268,7 +268,7 @@ namespace YooAsset { if (_hostPlayModeImpl == null) throw new Exception("YooAsset is not initialized."); - return _hostPlayModeImpl.UpdatePatchManifestAsync(updateResourceVersion, timeout); + return _hostPlayModeImpl.UpdatePatchManifestAsync(resourceVersion, timeout); } else { @@ -343,7 +343,7 @@ namespace YooAsset AssetSystem.GetDebugReport(report); } - #region 场景加载接口 + #region 场景加载 /// /// 异步加载场景 /// @@ -359,7 +359,7 @@ namespace YooAsset } #endregion - #region 资源加载接口 + #region 资源加载 /// /// 异步获取原生文件 /// @@ -498,37 +498,37 @@ namespace YooAsset } #endregion - #region 资源下载接口 + #region 资源下载 /// - /// 创建补丁下载器,用于更新下载资源标签指定的文件 + /// 创建补丁下载器,用于下载更新资源标签指定的资源包文件 /// /// 资源标签 /// 同时下载的最大文件数 /// 下载失败的重试次数 - public static DownloaderOperation CreatePatchDownloader(string tag, int downloadingMaxNumber, int failedTryAgain) + public static PatchDownloaderOperation CreatePatchDownloader(string tag, int downloadingMaxNumber, int failedTryAgain) { return CreatePatchDownloader(new string[] { tag }, downloadingMaxNumber, failedTryAgain); } /// - /// 创建补丁下载器,用于更新下载资源标签指定的文件 + /// 创建补丁下载器,用于下载更新资源标签指定的资源包文件 /// /// 资源标签列表 /// 同时下载的最大文件数 /// 下载失败的重试次数 - public static DownloaderOperation CreatePatchDownloader(string[] tags, int downloadingMaxNumber, int failedTryAgain) + public static PatchDownloaderOperation CreatePatchDownloader(string[] tags, int downloadingMaxNumber, int failedTryAgain) { if (_playMode == EPlayMode.EditorPlayMode || _playMode == EPlayMode.OfflinePlayMode) { List downloadList = new List(); - var operation = new DownloaderOperation(downloadList, downloadingMaxNumber, failedTryAgain); + var operation = new PatchDownloaderOperation(downloadList, downloadingMaxNumber, failedTryAgain); return operation; } else if (_playMode == EPlayMode.HostPlayMode) { if (_hostPlayModeImpl == null) throw new Exception("YooAsset is not initialized."); - return _hostPlayModeImpl.CreateDownloaderByTags(tags, downloadingMaxNumber, failedTryAgain); + return _hostPlayModeImpl.CreatePatchDownloaderByTags(tags, downloadingMaxNumber, failedTryAgain); } else { @@ -537,23 +537,23 @@ namespace YooAsset } /// - /// 创建补丁下载器,用于更新下载所有文件 + /// 创建补丁下载器,用于下载更新当前资源版本所有的资源包文件 /// /// 同时下载的最大文件数 /// 下载失败的重试次数 - public static DownloaderOperation CreatePatchDownloader(int downloadingMaxNumber, int failedTryAgain) + public static PatchDownloaderOperation CreatePatchDownloader(int downloadingMaxNumber, int failedTryAgain) { if (_playMode == EPlayMode.EditorPlayMode || _playMode == EPlayMode.OfflinePlayMode) { List downloadList = new List(); - var operation = new DownloaderOperation(downloadList, downloadingMaxNumber, failedTryAgain); + var operation = new PatchDownloaderOperation(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); + return _hostPlayModeImpl.CreatePatchDownloaderByAll(downloadingMaxNumber, failedTryAgain); } else { @@ -562,17 +562,17 @@ namespace YooAsset } /// - /// 创建资源包下载器,用于更新下载指定的资源列表 + /// 创建补丁下载器,用于下载更新指定的资源列表依赖的资源包文件 /// /// 资源列表 /// 同时下载的最大文件数 /// 下载失败的重试次数 - public static DownloaderOperation CreateBundleDownloader(string[] locations, int downloadingMaxNumber, int failedTryAgain) + public static PatchDownloaderOperation CreateBundleDownloader(string[] locations, int downloadingMaxNumber, int failedTryAgain) { if (_playMode == EPlayMode.EditorPlayMode || _playMode == EPlayMode.OfflinePlayMode) { List downloadList = new List(); - var operation = new DownloaderOperation(downloadList, downloadingMaxNumber, failedTryAgain); + var operation = new PatchDownloaderOperation(downloadList, downloadingMaxNumber, failedTryAgain); return operation; } else if (_playMode == EPlayMode.HostPlayMode) @@ -586,7 +586,7 @@ namespace YooAsset string assetPath = _locationServices.ConvertLocationToAssetPath(_playMode, location); assetPaths.Add(assetPath); } - return _hostPlayModeImpl.CreateDownloaderByPaths(assetPaths, downloadingMaxNumber, failedTryAgain); + return _hostPlayModeImpl.CreatePatchDownloaderByPaths(assetPaths, downloadingMaxNumber, failedTryAgain); } else { @@ -595,14 +595,14 @@ namespace YooAsset } #endregion - #region 资源解压接口 + #region 资源解压 /// /// 创建补丁解压器 /// /// 资源标签 /// 同时解压的最大文件数 /// 解压失败的重试次数 - public static DownloaderOperation CreatePatchUnpacker(string tag, int unpackingMaxNumber, int failedTryAgain) + public static PatchUnpackerOperation CreatePatchUnpacker(string tag, int unpackingMaxNumber, int failedTryAgain) { return CreatePatchUnpacker(new string[] { tag }, unpackingMaxNumber, failedTryAgain); } @@ -613,25 +613,58 @@ namespace YooAsset /// 资源标签列表 /// 同时解压的最大文件数 /// 解压失败的重试次数 - public static DownloaderOperation CreatePatchUnpacker(string[] tags, int unpackingMaxNumber, int failedTryAgain) + public static PatchUnpackerOperation CreatePatchUnpacker(string[] tags, int unpackingMaxNumber, int failedTryAgain) { if (_playMode == EPlayMode.EditorPlayMode) { List downloadList = new List(); - var operation = new DownloaderOperation(downloadList, unpackingMaxNumber, failedTryAgain); + var operation = new PatchUnpackerOperation(downloadList, unpackingMaxNumber, failedTryAgain); return operation; } else if (_playMode == EPlayMode.OfflinePlayMode) { if (_offlinePlayModeImpl == null) throw new Exception("YooAsset is not initialized."); - return _offlinePlayModeImpl.CreateUnpackerByTags(tags, unpackingMaxNumber, failedTryAgain); + return _offlinePlayModeImpl.CreatePatchUnpackerByTags(tags, unpackingMaxNumber, failedTryAgain); } else if (_playMode == EPlayMode.HostPlayMode) { if (_hostPlayModeImpl == null) throw new Exception("YooAsset is not initialized."); - return _hostPlayModeImpl.CreateUnpackerByTags(tags, unpackingMaxNumber, failedTryAgain); + return _hostPlayModeImpl.CreatePatchUnpackerByTags(tags, unpackingMaxNumber, failedTryAgain); + } + else + { + throw new NotImplementedException(); + } + } + #endregion + + #region 包裹更新 + /// + /// 创建资源包裹下载器,用于下载更新指定资源版本所有的资源包文件 + /// + /// 指定更新的资源版本 + /// 超时时间 + public static UpdatePackageOperation UpdatePackageAsync(int resourceVersion, int timeout = 60) + { + if (_playMode == EPlayMode.EditorPlayMode) + { + var operation = new EditorPlayModeUpdatePackageOperation(); + OperationSystem.ProcessOperaiton(operation); + return operation; + } + else if (_playMode == EPlayMode.OfflinePlayMode) + { + var operation = new OfflinePlayModeUpdatePackageOperation(); + OperationSystem.ProcessOperaiton(operation); + return operation; + } + else if (_playMode == EPlayMode.HostPlayMode) + { + if (_hostPlayModeImpl == null) + throw new Exception("YooAsset is not initialized."); + return _hostPlayModeImpl.UpdatePackageAsync(resourceVersion, timeout); } else {