From bd11f2e7b8877f0ef755cad2f066b6a2b844d740 Mon Sep 17 00:00:00 2001 From: hevinci Date: Mon, 17 Oct 2022 14:43:13 +0800 Subject: [PATCH] Update patch system MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 下载器增加超时参数 --- Assets/YooAsset/Runtime/AssetsPackage.cs | 45 ++++++++++--------- .../YooAsset/Runtime/InitializeParameters.cs | 3 +- .../Operations/DownloaderOperation.cs | 18 ++++---- .../Operations/UpdatePackageOperation.cs | 17 +++---- .../PatchSystem/PlayMode/HostPlayModeImpl.cs | 20 ++++----- 5 files changed, 55 insertions(+), 48 deletions(-) diff --git a/Assets/YooAsset/Runtime/AssetsPackage.cs b/Assets/YooAsset/Runtime/AssetsPackage.cs index ee96788..53d6658 100644 --- a/Assets/YooAsset/Runtime/AssetsPackage.cs +++ b/Assets/YooAsset/Runtime/AssetsPackage.cs @@ -690,10 +690,11 @@ namespace YooAsset /// 资源标签 /// 同时下载的最大文件数 /// 下载失败的重试次数 - public PatchDownloaderOperation CreatePatchDownloader(string tag, int downloadingMaxNumber, int failedTryAgain) + /// 超时时间 + public PatchDownloaderOperation CreatePatchDownloader(string tag, int downloadingMaxNumber, int failedTryAgain, int timeout = 60) { DebugCheckInitialize(); - return CreatePatchDownloader(new string[] { tag }, downloadingMaxNumber, failedTryAgain); + return CreatePatchDownloader(new string[] { tag }, downloadingMaxNumber, failedTryAgain, timeout); } /// @@ -702,18 +703,19 @@ namespace YooAsset /// 资源标签列表 /// 同时下载的最大文件数 /// 下载失败的重试次数 - public PatchDownloaderOperation CreatePatchDownloader(string[] tags, int downloadingMaxNumber, int failedTryAgain) + /// 超时时间 + public PatchDownloaderOperation CreatePatchDownloader(string[] tags, int downloadingMaxNumber, int failedTryAgain, int timeout = 60) { DebugCheckInitialize(); if (_playMode == EPlayMode.EditorSimulateMode || _playMode == EPlayMode.OfflinePlayMode) { List downloadList = new List(); - var operation = new PatchDownloaderOperation(downloadList, downloadingMaxNumber, failedTryAgain); + var operation = new PatchDownloaderOperation(downloadList, downloadingMaxNumber, failedTryAgain, timeout); return operation; } else if (_playMode == EPlayMode.HostPlayMode) { - return _hostPlayModeImpl.CreatePatchDownloaderByTags(tags, downloadingMaxNumber, failedTryAgain); + return _hostPlayModeImpl.CreatePatchDownloaderByTags(tags, downloadingMaxNumber, failedTryAgain, timeout); } else { @@ -726,18 +728,19 @@ namespace YooAsset /// /// 同时下载的最大文件数 /// 下载失败的重试次数 - public PatchDownloaderOperation CreatePatchDownloader(int downloadingMaxNumber, int failedTryAgain) + /// 超时时间 + public PatchDownloaderOperation CreatePatchDownloader(int downloadingMaxNumber, int failedTryAgain, int timeout = 60) { DebugCheckInitialize(); if (_playMode == EPlayMode.EditorSimulateMode || _playMode == EPlayMode.OfflinePlayMode) { List downloadList = new List(); - var operation = new PatchDownloaderOperation(downloadList, downloadingMaxNumber, failedTryAgain); + var operation = new PatchDownloaderOperation(downloadList, downloadingMaxNumber, failedTryAgain, timeout); return operation; } else if (_playMode == EPlayMode.HostPlayMode) { - return _hostPlayModeImpl.CreatePatchDownloaderByAll(downloadingMaxNumber, failedTryAgain); + return _hostPlayModeImpl.CreatePatchDownloaderByAll(downloadingMaxNumber, failedTryAgain, timeout); } else { @@ -752,13 +755,14 @@ namespace YooAsset /// 资源定位列表 /// 同时下载的最大文件数 /// 下载失败的重试次数 - public PatchDownloaderOperation CreateBundleDownloader(string[] locations, int downloadingMaxNumber, int failedTryAgain) + /// 超时时间 + public PatchDownloaderOperation CreateBundleDownloader(string[] locations, int downloadingMaxNumber, int failedTryAgain, int timeout = 60) { DebugCheckInitialize(); if (_playMode == EPlayMode.EditorSimulateMode || _playMode == EPlayMode.OfflinePlayMode) { List downloadList = new List(); - var operation = new PatchDownloaderOperation(downloadList, downloadingMaxNumber, failedTryAgain); + var operation = new PatchDownloaderOperation(downloadList, downloadingMaxNumber, failedTryAgain, timeout); return operation; } else if (_playMode == EPlayMode.HostPlayMode) @@ -769,7 +773,7 @@ namespace YooAsset AssetInfo assetInfo = ConvertLocationToAssetInfo(location, null); assetInfos.Add(assetInfo); } - return _hostPlayModeImpl.CreatePatchDownloaderByPaths(assetInfos.ToArray(), downloadingMaxNumber, failedTryAgain); + return _hostPlayModeImpl.CreatePatchDownloaderByPaths(assetInfos.ToArray(), downloadingMaxNumber, failedTryAgain, timeout); } else { @@ -783,18 +787,19 @@ namespace YooAsset /// 资源信息列表 /// 同时下载的最大文件数 /// 下载失败的重试次数 - public PatchDownloaderOperation CreateBundleDownloader(AssetInfo[] assetInfos, int downloadingMaxNumber, int failedTryAgain) + /// 超时时间 + public PatchDownloaderOperation CreateBundleDownloader(AssetInfo[] assetInfos, int downloadingMaxNumber, int failedTryAgain, int timeout = 60) { DebugCheckInitialize(); if (_playMode == EPlayMode.EditorSimulateMode || _playMode == EPlayMode.OfflinePlayMode) { List downloadList = new List(); - var operation = new PatchDownloaderOperation(downloadList, downloadingMaxNumber, failedTryAgain); + var operation = new PatchDownloaderOperation(downloadList, downloadingMaxNumber, failedTryAgain, timeout); return operation; } else if (_playMode == EPlayMode.HostPlayMode) { - return _hostPlayModeImpl.CreatePatchDownloaderByPaths(assetInfos, downloadingMaxNumber, failedTryAgain); + return _hostPlayModeImpl.CreatePatchDownloaderByPaths(assetInfos, downloadingMaxNumber, failedTryAgain, timeout); } else { @@ -828,18 +833,18 @@ namespace YooAsset if (_playMode == EPlayMode.EditorSimulateMode) { List downloadList = new List(); - var operation = new PatchUnpackerOperation(downloadList, unpackingMaxNumber, failedTryAgain); + var operation = new PatchUnpackerOperation(downloadList, unpackingMaxNumber, failedTryAgain, int.MaxValue); return operation; } else if (_playMode == EPlayMode.OfflinePlayMode) { List downloadList = new List(); - var operation = new PatchUnpackerOperation(downloadList, unpackingMaxNumber, failedTryAgain); + var operation = new PatchUnpackerOperation(downloadList, unpackingMaxNumber, failedTryAgain, int.MaxValue); return operation; } else if (_playMode == EPlayMode.HostPlayMode) { - return _hostPlayModeImpl.CreatePatchUnpackerByTags(tags, unpackingMaxNumber, failedTryAgain); + return _hostPlayModeImpl.CreatePatchUnpackerByTags(tags, unpackingMaxNumber, failedTryAgain, int.MaxValue); } else { @@ -858,18 +863,18 @@ namespace YooAsset if (_playMode == EPlayMode.EditorSimulateMode) { List downloadList = new List(); - var operation = new PatchUnpackerOperation(downloadList, unpackingMaxNumber, failedTryAgain); + var operation = new PatchUnpackerOperation(downloadList, unpackingMaxNumber, failedTryAgain, int.MaxValue); return operation; } else if (_playMode == EPlayMode.OfflinePlayMode) { List downloadList = new List(); - var operation = new PatchUnpackerOperation(downloadList, unpackingMaxNumber, failedTryAgain); + var operation = new PatchUnpackerOperation(downloadList, unpackingMaxNumber, failedTryAgain, int.MaxValue); return operation; } else if (_playMode == EPlayMode.HostPlayMode) { - return _hostPlayModeImpl.CreatePatchUnpackerByAll(unpackingMaxNumber, failedTryAgain); + return _hostPlayModeImpl.CreatePatchUnpackerByAll(unpackingMaxNumber, failedTryAgain, int.MaxValue); } else { diff --git a/Assets/YooAsset/Runtime/InitializeParameters.cs b/Assets/YooAsset/Runtime/InitializeParameters.cs index 4810e96..a8664e3 100644 --- a/Assets/YooAsset/Runtime/InitializeParameters.cs +++ b/Assets/YooAsset/Runtime/InitializeParameters.cs @@ -1,5 +1,4 @@ -using UnityEngine; - + namespace YooAsset { /// diff --git a/Assets/YooAsset/Runtime/PatchSystem/Operations/DownloaderOperation.cs b/Assets/YooAsset/Runtime/PatchSystem/Operations/DownloaderOperation.cs index 2d1a52f..0f4d772 100644 --- a/Assets/YooAsset/Runtime/PatchSystem/Operations/DownloaderOperation.cs +++ b/Assets/YooAsset/Runtime/PatchSystem/Operations/DownloaderOperation.cs @@ -22,6 +22,7 @@ namespace YooAsset private readonly int _downloadingMaxNumber; private readonly int _failedTryAgain; + private readonly int _timeout; private readonly List _downloadList; private readonly List _downloaders = new List(MAX_LOADER_COUNT); private readonly List _removeList = new List(MAX_LOADER_COUNT); @@ -75,11 +76,12 @@ namespace YooAsset public OnStartDownloadFile OnStartDownloadFileCallback { set; get; } - internal DownloaderOperation(List downloadList, int downloadingMaxNumber, int failedTryAgain) + internal DownloaderOperation(List downloadList, int downloadingMaxNumber, int failedTryAgain, int timeout) { _downloadList = downloadList; _downloadingMaxNumber = UnityEngine.Mathf.Clamp(downloadingMaxNumber, 1, MAX_LOADER_COUNT); ; _failedTryAgain = failedTryAgain; + _timeout = timeout; if (downloadList != null) { @@ -167,7 +169,7 @@ namespace YooAsset { int index = _downloadList.Count - 1; var bundleInfo = _downloadList[index]; - var operation = DownloadSystem.BeginDownload(bundleInfo, _failedTryAgain); + var operation = DownloadSystem.BeginDownload(bundleInfo, _failedTryAgain, _timeout); _downloaders.Add(operation); _downloadList.RemoveAt(index); OnStartDownloadFileCallback?.Invoke(bundleInfo.Bundle.BundleName, bundleInfo.Bundle.FileSize); @@ -228,22 +230,22 @@ namespace YooAsset public sealed class PackageDownloaderOperation : DownloaderOperation { - internal PackageDownloaderOperation(List downloadList, int downloadingMaxNumber, int failedTryAgain) - : base(downloadList, downloadingMaxNumber, failedTryAgain) + internal PackageDownloaderOperation(List downloadList, int downloadingMaxNumber, int failedTryAgain, int timeout) + : base(downloadList, downloadingMaxNumber, failedTryAgain, timeout) { } } public sealed class PatchDownloaderOperation : DownloaderOperation { - internal PatchDownloaderOperation(List downloadList, int downloadingMaxNumber, int failedTryAgain) - : base(downloadList, downloadingMaxNumber, failedTryAgain) + internal PatchDownloaderOperation(List downloadList, int downloadingMaxNumber, int failedTryAgain, int timeout) + : base(downloadList, downloadingMaxNumber, failedTryAgain, timeout) { } } public sealed class PatchUnpackerOperation : DownloaderOperation { - internal PatchUnpackerOperation(List downloadList, int downloadingMaxNumber, int failedTryAgain) - : base(downloadList, downloadingMaxNumber, failedTryAgain) + internal PatchUnpackerOperation(List downloadList, int downloadingMaxNumber, int failedTryAgain, int timeout) + : base(downloadList, downloadingMaxNumber, failedTryAgain, timeout) { } } diff --git a/Assets/YooAsset/Runtime/PatchSystem/Operations/UpdatePackageOperation.cs b/Assets/YooAsset/Runtime/PatchSystem/Operations/UpdatePackageOperation.cs index b054ede..53f061e 100644 --- a/Assets/YooAsset/Runtime/PatchSystem/Operations/UpdatePackageOperation.cs +++ b/Assets/YooAsset/Runtime/PatchSystem/Operations/UpdatePackageOperation.cs @@ -12,7 +12,8 @@ namespace YooAsset /// /// 同时下载的最大文件数 /// 下载失败的重试次数 - public abstract PackageDownloaderOperation CreatePackageDownloader(int downloadingMaxNumber, int failedTryAgain); + /// 超时时间(单位:秒) + public abstract PackageDownloaderOperation CreatePackageDownloader(int downloadingMaxNumber, int failedTryAgain, int timeout); } /// @@ -31,10 +32,10 @@ namespace YooAsset /// /// 创建包裹下载器 /// - public override PackageDownloaderOperation CreatePackageDownloader(int downloadingMaxNumber, int failedTryAgain) + public override PackageDownloaderOperation CreatePackageDownloader(int downloadingMaxNumber, int failedTryAgain, int timeout) { List downloadList = new List(); - var operation = new PackageDownloaderOperation(downloadList, downloadingMaxNumber, failedTryAgain); + var operation = new PackageDownloaderOperation(downloadList, downloadingMaxNumber, failedTryAgain, timeout); return operation; } } @@ -55,10 +56,10 @@ namespace YooAsset /// /// 创建包裹下载器 /// - public override PackageDownloaderOperation CreatePackageDownloader(int downloadingMaxNumber, int failedTryAgain) + public override PackageDownloaderOperation CreatePackageDownloader(int downloadingMaxNumber, int failedTryAgain, int timeout) { List downloadList = new List(); - var operation = new PackageDownloaderOperation(downloadList, downloadingMaxNumber, failedTryAgain); + var operation = new PackageDownloaderOperation(downloadList, downloadingMaxNumber, failedTryAgain, timeout); return operation; } } @@ -147,18 +148,18 @@ namespace YooAsset /// /// 创建包裹下载器 /// - public override PackageDownloaderOperation CreatePackageDownloader(int downloadingMaxNumber, int failedTryAgain) + public override PackageDownloaderOperation CreatePackageDownloader(int downloadingMaxNumber, int failedTryAgain, int timeout) { if (Status == EOperationStatus.Succeed) { List downloadList = GetDownloadList(); - var operation = new PackageDownloaderOperation(downloadList, downloadingMaxNumber, failedTryAgain); + var operation = new PackageDownloaderOperation(downloadList, downloadingMaxNumber, failedTryAgain, timeout); return operation; } else { YooLogger.Error($"{nameof(UpdatePackageOperation)} status is failed !"); - var operation = new PackageDownloaderOperation(null, downloadingMaxNumber, failedTryAgain); + var operation = new PackageDownloaderOperation(null, downloadingMaxNumber, failedTryAgain, timeout); return operation; } } diff --git a/Assets/YooAsset/Runtime/PatchSystem/PlayMode/HostPlayModeImpl.cs b/Assets/YooAsset/Runtime/PatchSystem/PlayMode/HostPlayModeImpl.cs index 936eafa..a9a0008 100644 --- a/Assets/YooAsset/Runtime/PatchSystem/PlayMode/HostPlayModeImpl.cs +++ b/Assets/YooAsset/Runtime/PatchSystem/PlayMode/HostPlayModeImpl.cs @@ -74,10 +74,10 @@ namespace YooAsset /// /// 创建下载器 /// - public PatchDownloaderOperation CreatePatchDownloaderByAll(int fileLoadingMaxNumber, int failedTryAgain) + public PatchDownloaderOperation CreatePatchDownloaderByAll(int fileLoadingMaxNumber, int failedTryAgain, int timeout) { List downloadList = GetDownloadListByAll(); - var operation = new PatchDownloaderOperation(downloadList, fileLoadingMaxNumber, failedTryAgain); + var operation = new PatchDownloaderOperation(downloadList, fileLoadingMaxNumber, failedTryAgain, timeout); return operation; } private List GetDownloadListByAll() @@ -102,10 +102,10 @@ namespace YooAsset /// /// 创建下载器 /// - public PatchDownloaderOperation CreatePatchDownloaderByTags(string[] tags, int fileLoadingMaxNumber, int failedTryAgain) + public PatchDownloaderOperation CreatePatchDownloaderByTags(string[] tags, int fileLoadingMaxNumber, int failedTryAgain, int timeout) { List downloadList = GetDownloadListByTags(tags); - var operation = new PatchDownloaderOperation(downloadList, fileLoadingMaxNumber, failedTryAgain); + var operation = new PatchDownloaderOperation(downloadList, fileLoadingMaxNumber, failedTryAgain, timeout); return operation; } private List GetDownloadListByTags(string[] tags) @@ -142,10 +142,10 @@ namespace YooAsset /// /// 创建下载器 /// - public PatchDownloaderOperation CreatePatchDownloaderByPaths(AssetInfo[] assetInfos, int fileLoadingMaxNumber, int failedTryAgain) + public PatchDownloaderOperation CreatePatchDownloaderByPaths(AssetInfo[] assetInfos, int fileLoadingMaxNumber, int failedTryAgain, int timeout) { List downloadList = GetDownloadListByPaths(assetInfos); - var operation = new PatchDownloaderOperation(downloadList, fileLoadingMaxNumber, failedTryAgain); + var operation = new PatchDownloaderOperation(downloadList, fileLoadingMaxNumber, failedTryAgain, timeout); return operation; } private List GetDownloadListByPaths(AssetInfo[] assetInfos) @@ -194,10 +194,10 @@ namespace YooAsset /// /// 创建解压器 /// - public PatchUnpackerOperation CreatePatchUnpackerByTags(string[] tags, int fileUpackingMaxNumber, int failedTryAgain) + public PatchUnpackerOperation CreatePatchUnpackerByTags(string[] tags, int fileUpackingMaxNumber, int failedTryAgain, int timeout) { List unpcakList = GetUnpackListByTags(tags); - var operation = new PatchUnpackerOperation(unpcakList, fileUpackingMaxNumber, failedTryAgain); + var operation = new PatchUnpackerOperation(unpcakList, fileUpackingMaxNumber, failedTryAgain, timeout); return operation; } private List GetUnpackListByTags(string[] tags) @@ -225,10 +225,10 @@ namespace YooAsset /// /// 创建解压器 /// - public PatchUnpackerOperation CreatePatchUnpackerByAll(int fileUpackingMaxNumber, int failedTryAgain) + public PatchUnpackerOperation CreatePatchUnpackerByAll(int fileUpackingMaxNumber, int failedTryAgain, int timeout) { List unpcakList = GetUnpackListByAll(); - var operation = new PatchUnpackerOperation(unpcakList, fileUpackingMaxNumber, failedTryAgain); + var operation = new PatchUnpackerOperation(unpcakList, fileUpackingMaxNumber, failedTryAgain, timeout); return operation; } private List GetUnpackListByAll()