From 589c0d3ce54a26dfe6fb9433e12c86ce33a2b349 Mon Sep 17 00:00:00 2001 From: hevinci Date: Sun, 8 Oct 2023 17:41:07 +0800 Subject: [PATCH] update resource package MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 下载器增加合并方法 --- .../Operation/DownloaderOperation.cs | 60 ++++++++++++++++--- 1 file changed, 52 insertions(+), 8 deletions(-) diff --git a/Assets/YooAsset/Runtime/ResourcePackage/Operation/DownloaderOperation.cs b/Assets/YooAsset/Runtime/ResourcePackage/Operation/DownloaderOperation.cs index 9a9c389..34bcbdf 100644 --- a/Assets/YooAsset/Runtime/ResourcePackage/Operation/DownloaderOperation.cs +++ b/Assets/YooAsset/Runtime/ResourcePackage/Operation/DownloaderOperation.cs @@ -95,14 +95,8 @@ namespace YooAsset _failedTryAgain = failedTryAgain; _timeout = timeout; - if (downloadList != null) - { - TotalDownloadCount = downloadList.Count; - foreach (var packageBundle in downloadList) - { - TotalDownloadBytes += packageBundle.Bundle.FileSize; - } - } + // 统计下载信息 + CalculatDownloaderInfo(); } internal override void Start() { @@ -210,7 +204,57 @@ namespace YooAsset } } } + private void CalculatDownloaderInfo() + { + if (_bundleInfoList != null) + { + TotalDownloadCount = _bundleInfoList.Count; + foreach (var packageBundle in _bundleInfoList) + { + TotalDownloadBytes += packageBundle.Bundle.FileSize; + } + } + } + /// + /// 合并其它下载器 + /// + /// 合并的下载器 + public void Combine(DownloaderOperation downloader) + if (_packageName != downloader._packageName) + { + YooLogger.Error("The downloaders have different resource packages !"); + return; + } + + if (Status != EOperationStatus.None) + { + YooLogger.Error("The downloader is running, can not combine with other downloader !"); + return; + } + + HashSet temper = new HashSet(); + foreach (var bundleInfo in _bundleInfoList) + { + if (temper.Contains(bundleInfo.CachedDataFilePath) == false) + { + temper.Add(bundleInfo.CachedDataFilePath); + } + } + + // 合并下载列表 + foreach (var bundleInfo in downloader._bundleInfoList) + { + if (temper.Contains(bundleInfo.CachedDataFilePath) == false) + { + _bundleInfoList.Add(bundleInfo); + } + } + + // 重新统计下载信息 + CalculatDownloaderInfo(); + } + /// /// 开始下载 ///