From 0ceeeb8c5bfab9f4e6181cb8d91edea55f7d23ed Mon Sep 17 00:00:00 2001 From: hevinci Date: Sat, 7 Oct 2023 16:02:11 +0800 Subject: [PATCH] update download system support to cancel download operation --- .../Runtime/DownloadSystem/DownloadManager.cs | 42 +++++++++---- .../Downloader/DownloaderBase.cs | 35 ++++++++--- .../Operation/DownloaderOperation.cs | 59 +++++++++++-------- .../Operation/PreDownloadContentOperation.cs | 50 ++++++++-------- .../PlayMode/EditorSimulateModeImpl.cs | 17 +++--- .../PlayMode/HostPlayModeImpl.cs | 16 +++-- .../PlayMode/OfflinePlayModeImpl.cs | 18 +++--- .../PlayMode/WebPlayModeImpl.cs | 16 +++-- 8 files changed, 160 insertions(+), 93 deletions(-) diff --git a/Assets/YooAsset/Runtime/DownloadSystem/DownloadManager.cs b/Assets/YooAsset/Runtime/DownloadSystem/DownloadManager.cs index c3b0431..34c81a9 100644 --- a/Assets/YooAsset/Runtime/DownloadSystem/DownloadManager.cs +++ b/Assets/YooAsset/Runtime/DownloadSystem/DownloadManager.cs @@ -49,7 +49,9 @@ namespace YooAsset var downloader = valuePair.Value; downloader.Update(); if (downloader.IsDone()) + { _removeList.Add(valuePair.Key); + } } // 移除下载器 @@ -82,7 +84,10 @@ namespace YooAsset { // 查询存在的下载器 if (_downloaders.TryGetValue(bundleInfo.CachedDataFilePath, out var downloader)) + { + downloader.Reference(); return downloader; + } // 如果资源已经缓存 if (bundleInfo.IsCached()) @@ -92,22 +97,19 @@ namespace YooAsset } // 创建新的下载器 + DownloaderBase newDownloader = null; YooLogger.Log($"Beginning to download bundle : {bundleInfo.Bundle.BundleName} URL : {bundleInfo.RemoteMainURL}"); #if UNITY_WEBGL if (bundleInfo.Bundle.Buildpipeline == DefaultBuildPipeline.RawFileBuildPipelineName) { FileUtility.CreateFileDirectory(bundleInfo.CachedDataFilePath); System.Type requesterType = typeof(FileGeneralRequest); - DownloaderBase newDownloader = new FileDownloader(bundleInfo, requesterType, failedTryAgain, timeout); - _downloaders.Add(bundleInfo.CachedDataFilePath, newDownloader); - return newDownloader; + newDownloader = new FileDownloader(bundleInfo, requesterType, failedTryAgain, timeout); } else { System.Type requesterType = typeof(AssetBundleWebRequest); - WebDownloader newDownloader = new WebDownloader(bundleInfo, requesterType, failedTryAgain, timeout); - _downloaders.Add(bundleInfo.CachedDataFilePath, newDownloader); - return newDownloader; + newDownloader = new WebDownloader(bundleInfo, requesterType, failedTryAgain, timeout); } #else FileUtility.CreateFileDirectory(bundleInfo.CachedDataFilePath); @@ -115,18 +117,34 @@ namespace YooAsset if (resumeDownload) { System.Type requesterType = typeof(FileResumeRequest); - DownloaderBase newDownloader = new FileDownloader(bundleInfo, requesterType, failedTryAgain, timeout); - _downloaders.Add(bundleInfo.CachedDataFilePath, newDownloader); - return newDownloader; + newDownloader = new FileDownloader(bundleInfo, requesterType, failedTryAgain, timeout); } else { System.Type requesterType = typeof(FileGeneralRequest); - DownloaderBase newDownloader = new FileDownloader(bundleInfo, requesterType, failedTryAgain, timeout); - _downloaders.Add(bundleInfo.CachedDataFilePath, newDownloader); - return newDownloader; + newDownloader = new FileDownloader(bundleInfo, requesterType, failedTryAgain, timeout); } #endif + + // 返回新创建的下载器 + _downloaders.Add(bundleInfo.CachedDataFilePath, newDownloader); + newDownloader.Reference(); + return newDownloader; + } + + /// + /// 停止不再使用的下载器 + /// + public void AbortUnusedDownloader() + { + foreach (var valuePair in _downloaders) + { + var downloader = valuePair.Value; + if (downloader.RefCount <= 0) + { + downloader.Abort(); + } + } } } } \ No newline at end of file diff --git a/Assets/YooAsset/Runtime/DownloadSystem/Downloader/DownloaderBase.cs b/Assets/YooAsset/Runtime/DownloadSystem/Downloader/DownloaderBase.cs index 7fb1dda..e64f954 100644 --- a/Assets/YooAsset/Runtime/DownloadSystem/Downloader/DownloaderBase.cs +++ b/Assets/YooAsset/Runtime/DownloadSystem/Downloader/DownloaderBase.cs @@ -49,6 +49,11 @@ namespace YooAsset /// public ulong DownloadedBytes { protected set; get; } + /// + /// 引用计数 + /// + public int RefCount { private set; get; } + public DownloaderBase(BundleInfo bundleInfo, System.Type requesterType, int failedTryAgain, int timeout) { @@ -63,20 +68,19 @@ namespace YooAsset public abstract AssetBundle GetAssetBundle(); /// - /// 获取下载文件的大小 + /// 引用(引用计数递加) /// - /// - public long GetDownloadFileSize() + public void Reference() { - return _bundleInfo.Bundle.FileSize; + RefCount++; } /// - /// 获取下载文件的资源包名 + /// 释放(引用计数递减) /// - public string GetDownloadBundleName() + public void Release() { - return _bundleInfo.Bundle.BundleName; + RefCount--; } /// @@ -119,6 +123,23 @@ namespace YooAsset return $"Failed to download : {_requestURL} Error : {_lastestNetError} Code : {_lastestHttpCode}"; } + /// + /// 获取下载文件的大小 + /// + /// + public long GetDownloadFileSize() + { + return _bundleInfo.Bundle.FileSize; + } + + /// + /// 获取下载的资源包名称 + /// + public string GetDownloadBundleName() + { + return _bundleInfo.Bundle.BundleName; + } + /// /// 获取网络请求地址 diff --git a/Assets/YooAsset/Runtime/ResourcePackage/Operation/DownloaderOperation.cs b/Assets/YooAsset/Runtime/ResourcePackage/Operation/DownloaderOperation.cs index bc3abb2..9a9c389 100644 --- a/Assets/YooAsset/Runtime/ResourcePackage/Operation/DownloaderOperation.cs +++ b/Assets/YooAsset/Runtime/ResourcePackage/Operation/DownloaderOperation.cs @@ -20,11 +20,12 @@ namespace YooAsset public delegate void OnDownloadError(string fileName, string error); public delegate void OnStartDownloadFile(string fileName, long sizeBytes); + private readonly DownloadManager _downloadMgr; private readonly string _packageName; private readonly int _downloadingMaxNumber; private readonly int _failedTryAgain; private readonly int _timeout; - private readonly List _downloadList; + private readonly List _bundleInfoList; private readonly List _downloaders = new List(MAX_LOADER_COUNT); private readonly List _removeList = new List(MAX_LOADER_COUNT); private readonly List _failedList = new List(MAX_LOADER_COUNT); @@ -85,10 +86,11 @@ namespace YooAsset public OnStartDownloadFile OnStartDownloadFileCallback { set; get; } - internal DownloaderOperation(string packageName, List downloadList, int downloadingMaxNumber, int failedTryAgain, int timeout) + internal DownloaderOperation(DownloadManager downloadMgr, string packageName, List downloadList, int downloadingMaxNumber, int failedTryAgain, int timeout) { + _downloadMgr = downloadMgr; _packageName = packageName; - _downloadList = downloadList; + _bundleInfoList = downloadList; _downloadingMaxNumber = UnityEngine.Mathf.Clamp(downloadingMaxNumber, 1, MAX_LOADER_COUNT); ; _failedTryAgain = failedTryAgain; _timeout = timeout; @@ -114,7 +116,7 @@ namespace YooAsset if (_steps == ESteps.Check) { - if (_downloadList == null) + if (_bundleInfoList == null) { _steps = ESteps.Done; Status = EOperationStatus.Failed; @@ -168,19 +170,19 @@ namespace YooAsset // 动态创建新的下载器到最大数量限制 // 注意:如果期间有下载失败的文件,暂停动态创建下载器 - if (_downloadList.Count > 0 && _failedList.Count == 0) + if (_bundleInfoList.Count > 0 && _failedList.Count == 0) { if (_isPause) return; if (_downloaders.Count < _downloadingMaxNumber) { - int index = _downloadList.Count - 1; - var bundleInfo = _downloadList[index]; + int index = _bundleInfoList.Count - 1; + var bundleInfo = _bundleInfoList[index]; var downloader = bundleInfo.CreateDownloader(_failedTryAgain, _timeout); downloader.SendRequest(); _downloaders.Add(downloader); - _downloadList.RemoveAt(index); + _bundleInfoList.RemoveAt(index); OnStartDownloadFileCallback?.Invoke(bundleInfo.Bundle.BundleName, bundleInfo.Bundle.FileSize); } } @@ -191,11 +193,11 @@ namespace YooAsset if (_failedList.Count > 0) { var failedDownloader = _failedList[0]; - string fileName = failedDownloader.GetDownloadBundleName(); + string bundleName = failedDownloader.GetDownloadBundleName(); _steps = ESteps.Done; Status = EOperationStatus.Failed; - Error = $"Failed to download file : {fileName}"; - OnDownloadErrorCallback?.Invoke(fileName, failedDownloader.GetLastError()); + Error = $"Failed to download file : {bundleName}"; + OnDownloadErrorCallback?.Invoke(bundleName, failedDownloader.GetLastError()); OnDownloadOverCallback?.Invoke(false); } else @@ -246,58 +248,69 @@ namespace YooAsset _steps = ESteps.Done; Status = EOperationStatus.Failed; Error = "User cancel."; + ReleaseAllDownloader(); } } + private void ReleaseAllDownloader() + { + foreach (var downloader in _downloaders) + { + downloader.Release(); + } + + // 注意:停止不再使用的下载器 + _downloadMgr.AbortUnusedDownloader(); + } } public sealed class ResourceDownloaderOperation : DownloaderOperation { - internal ResourceDownloaderOperation(string packageName, List downloadList, int downloadingMaxNumber, int failedTryAgain, int timeout) - : base(packageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout) + internal ResourceDownloaderOperation(DownloadManager downloadMgr, string packageName, List downloadList, int downloadingMaxNumber, int failedTryAgain, int timeout) + : base(downloadMgr, packageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout) { } /// /// 创建空的下载器 /// - internal static ResourceDownloaderOperation CreateEmptyDownloader(string packageName, int downloadingMaxNumber, int failedTryAgain, int timeout) + internal static ResourceDownloaderOperation CreateEmptyDownloader(DownloadManager downloadMgr, string packageName, int downloadingMaxNumber, int failedTryAgain, int timeout) { List downloadList = new List(); - var operation = new ResourceDownloaderOperation(packageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout); + var operation = new ResourceDownloaderOperation(downloadMgr, packageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout); return operation; } } public sealed class ResourceUnpackerOperation : DownloaderOperation { - internal ResourceUnpackerOperation(string packageName, List downloadList, int downloadingMaxNumber, int failedTryAgain, int timeout) - : base(packageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout) + internal ResourceUnpackerOperation(DownloadManager downloadMgr, string packageName, List downloadList, int downloadingMaxNumber, int failedTryAgain, int timeout) + : base(downloadMgr, packageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout) { } /// /// 创建空的解压器 /// - internal static ResourceUnpackerOperation CreateEmptyUnpacker(string packageName, int upackingMaxNumber, int failedTryAgain, int timeout) + internal static ResourceUnpackerOperation CreateEmptyUnpacker(DownloadManager downloadMgr, string packageName, int upackingMaxNumber, int failedTryAgain, int timeout) { List downloadList = new List(); - var operation = new ResourceUnpackerOperation(packageName, downloadList, upackingMaxNumber, failedTryAgain, int.MaxValue); + var operation = new ResourceUnpackerOperation(downloadMgr, packageName, downloadList, upackingMaxNumber, failedTryAgain, int.MaxValue); return operation; } } public sealed class ResourceImporterOperation : DownloaderOperation { - internal ResourceImporterOperation(string packageName, List downloadList, int downloadingMaxNumber, int failedTryAgain, int timeout) - : base(packageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout) + internal ResourceImporterOperation(DownloadManager downloadMgr, string packageName, List downloadList, int downloadingMaxNumber, int failedTryAgain, int timeout) + : base(downloadMgr, packageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout) { } /// /// 创建空的导入器 /// - internal static ResourceImporterOperation CreateEmptyImporter(string packageName, int upackingMaxNumber, int failedTryAgain, int timeout) + internal static ResourceImporterOperation CreateEmptyImporter(DownloadManager downloadMgr, string packageName, int upackingMaxNumber, int failedTryAgain, int timeout) { List downloadList = new List(); - var operation = new ResourceImporterOperation(packageName, downloadList, upackingMaxNumber, failedTryAgain, int.MaxValue); + var operation = new ResourceImporterOperation(downloadMgr, packageName, downloadList, upackingMaxNumber, failedTryAgain, int.MaxValue); return operation; } } diff --git a/Assets/YooAsset/Runtime/ResourcePackage/Operation/PreDownloadContentOperation.cs b/Assets/YooAsset/Runtime/ResourcePackage/Operation/PreDownloadContentOperation.cs index d44ce17..790ddb6 100644 --- a/Assets/YooAsset/Runtime/ResourcePackage/Operation/PreDownloadContentOperation.cs +++ b/Assets/YooAsset/Runtime/ResourcePackage/Operation/PreDownloadContentOperation.cs @@ -69,23 +69,23 @@ namespace YooAsset public override ResourceDownloaderOperation CreateResourceDownloader(int downloadingMaxNumber, int failedTryAgain, int timeout = 60) { - return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout); + return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.Download, _impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout); } public override ResourceDownloaderOperation CreateResourceDownloader(string tag, int downloadingMaxNumber, int failedTryAgain, int timeout = 60) { - return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout); + return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.Download, _impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout); } public override ResourceDownloaderOperation CreateResourceDownloader(string[] tags, int downloadingMaxNumber, int failedTryAgain, int timeout = 60) { - return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout); + return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.Download, _impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout); } public override ResourceDownloaderOperation CreateBundleDownloader(string location, int downloadingMaxNumber, int failedTryAgain, int timeout = 60) { - return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout); + return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.Download, _impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout); } public override ResourceDownloaderOperation CreateBundleDownloader(string[] locations, int downloadingMaxNumber, int failedTryAgain, int timeout = 60) { - return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout); + return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.Download, _impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout); } } internal class OfflinePlayModePreDownloadContentOperation : PreDownloadContentOperation @@ -106,23 +106,23 @@ namespace YooAsset public override ResourceDownloaderOperation CreateResourceDownloader(int downloadingMaxNumber, int failedTryAgain, int timeout = 60) { - return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout); + return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.Download, _impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout); } public override ResourceDownloaderOperation CreateResourceDownloader(string tag, int downloadingMaxNumber, int failedTryAgain, int timeout = 60) { - return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout); + return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.Download, _impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout); } public override ResourceDownloaderOperation CreateResourceDownloader(string[] tags, int downloadingMaxNumber, int failedTryAgain, int timeout = 60) { - return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout); + return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.Download, _impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout); } public override ResourceDownloaderOperation CreateBundleDownloader(string location, int downloadingMaxNumber, int failedTryAgain, int timeout = 60) { - return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout); + return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.Download, _impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout); } public override ResourceDownloaderOperation CreateBundleDownloader(string[] locations, int downloadingMaxNumber, int failedTryAgain, int timeout = 60) { - return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout); + return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.Download, _impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout); } } internal class HostPlayModePreDownloadContentOperation : PreDownloadContentOperation @@ -256,11 +256,11 @@ namespace YooAsset if (Status != EOperationStatus.Succeed) { YooLogger.Warning($"{nameof(PreDownloadContentOperation)} status is not succeed !"); - return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout); + return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.Download, _impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout); } List downloadList = _impl.GetDownloadListByAll(_manifest); - var operation = new ResourceDownloaderOperation(_impl.PackageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout); + var operation = new ResourceDownloaderOperation(_impl.Download, _impl.PackageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout); return operation; } public override ResourceDownloaderOperation CreateResourceDownloader(string tag, int downloadingMaxNumber, int failedTryAgain, int timeout = 60) @@ -268,11 +268,11 @@ namespace YooAsset if (Status != EOperationStatus.Succeed) { YooLogger.Warning($"{nameof(PreDownloadContentOperation)} status is not succeed !"); - return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout); + return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.Download, _impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout); } List downloadList = _impl.GetDownloadListByTags(_manifest, new string[] { tag }); - var operation = new ResourceDownloaderOperation(_impl.PackageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout); + var operation = new ResourceDownloaderOperation(_impl.Download, _impl.PackageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout); return operation; } public override ResourceDownloaderOperation CreateResourceDownloader(string[] tags, int downloadingMaxNumber, int failedTryAgain, int timeout = 60) @@ -280,11 +280,11 @@ namespace YooAsset if (Status != EOperationStatus.Succeed) { YooLogger.Warning($"{nameof(PreDownloadContentOperation)} status is not succeed !"); - return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout); + return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.Download, _impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout); } List downloadList = _impl.GetDownloadListByTags(_manifest, tags); - var operation = new ResourceDownloaderOperation(_impl.PackageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout); + var operation = new ResourceDownloaderOperation(_impl.Download, _impl.PackageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout); return operation; } public override ResourceDownloaderOperation CreateBundleDownloader(string location, int downloadingMaxNumber, int failedTryAgain, int timeout = 60) @@ -292,7 +292,7 @@ namespace YooAsset if (Status != EOperationStatus.Succeed) { YooLogger.Warning($"{nameof(PreDownloadContentOperation)} status is not succeed !"); - return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout); + return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.Download, _impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout); } List assetInfos = new List(); @@ -300,7 +300,7 @@ namespace YooAsset assetInfos.Add(assetInfo); List downloadList = _impl.GetDownloadListByPaths(_manifest, assetInfos.ToArray()); - var operation = new ResourceDownloaderOperation(_impl.PackageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout); + var operation = new ResourceDownloaderOperation(_impl.Download, _impl.PackageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout); return operation; } public override ResourceDownloaderOperation CreateBundleDownloader(string[] locations, int downloadingMaxNumber, int failedTryAgain, int timeout = 60) @@ -308,7 +308,7 @@ namespace YooAsset if (Status != EOperationStatus.Succeed) { YooLogger.Warning($"{nameof(PreDownloadContentOperation)} status is not succeed !"); - return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout); + return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.Download, _impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout); } List assetInfos = new List(locations.Length); @@ -319,7 +319,7 @@ namespace YooAsset } List downloadList = _impl.GetDownloadListByPaths(_manifest, assetInfos.ToArray()); - var operation = new ResourceDownloaderOperation(_impl.PackageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout); + var operation = new ResourceDownloaderOperation(_impl.Download, _impl.PackageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout); return operation; } } @@ -341,23 +341,23 @@ namespace YooAsset public override ResourceDownloaderOperation CreateResourceDownloader(int downloadingMaxNumber, int failedTryAgain, int timeout = 60) { - return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout); + return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.Download, _impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout); } public override ResourceDownloaderOperation CreateResourceDownloader(string tag, int downloadingMaxNumber, int failedTryAgain, int timeout = 60) { - return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout); + return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.Download, _impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout); } public override ResourceDownloaderOperation CreateResourceDownloader(string[] tags, int downloadingMaxNumber, int failedTryAgain, int timeout = 60) { - return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout); + return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.Download, _impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout); } public override ResourceDownloaderOperation CreateBundleDownloader(string location, int downloadingMaxNumber, int failedTryAgain, int timeout = 60) { - return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout); + return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.Download, _impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout); } public override ResourceDownloaderOperation CreateBundleDownloader(string[] locations, int downloadingMaxNumber, int failedTryAgain, int timeout = 60) { - return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout); + return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.Download, _impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout); } } } \ No newline at end of file diff --git a/Assets/YooAsset/Runtime/ResourcePackage/PlayMode/EditorSimulateModeImpl.cs b/Assets/YooAsset/Runtime/ResourcePackage/PlayMode/EditorSimulateModeImpl.cs index f266053..3c68027 100644 --- a/Assets/YooAsset/Runtime/ResourcePackage/PlayMode/EditorSimulateModeImpl.cs +++ b/Assets/YooAsset/Runtime/ResourcePackage/PlayMode/EditorSimulateModeImpl.cs @@ -10,7 +10,10 @@ namespace YooAsset private ResourceAssist _assist; public readonly string PackageName; - + public DownloadManager Download + { + get { return _assist.Download; } + } public EditorSimulateModeImpl(string packageName) { @@ -66,29 +69,29 @@ namespace YooAsset ResourceDownloaderOperation IPlayMode.CreateResourceDownloaderByAll(int downloadingMaxNumber, int failedTryAgain, int timeout) { - return ResourceDownloaderOperation.CreateEmptyDownloader(PackageName, downloadingMaxNumber, failedTryAgain, timeout); + return ResourceDownloaderOperation.CreateEmptyDownloader(Download, PackageName, downloadingMaxNumber, failedTryAgain, timeout); } ResourceDownloaderOperation IPlayMode.CreateResourceDownloaderByTags(string[] tags, int downloadingMaxNumber, int failedTryAgain, int timeout) { - return ResourceDownloaderOperation.CreateEmptyDownloader(PackageName, downloadingMaxNumber, failedTryAgain, timeout); + return ResourceDownloaderOperation.CreateEmptyDownloader(Download, PackageName, downloadingMaxNumber, failedTryAgain, timeout); } ResourceDownloaderOperation IPlayMode.CreateResourceDownloaderByPaths(AssetInfo[] assetInfos, int downloadingMaxNumber, int failedTryAgain, int timeout) { - return ResourceDownloaderOperation.CreateEmptyDownloader(PackageName, downloadingMaxNumber, failedTryAgain, timeout); + return ResourceDownloaderOperation.CreateEmptyDownloader(Download, PackageName, downloadingMaxNumber, failedTryAgain, timeout); } ResourceUnpackerOperation IPlayMode.CreateResourceUnpackerByAll(int upackingMaxNumber, int failedTryAgain, int timeout) { - return ResourceUnpackerOperation.CreateEmptyUnpacker(PackageName, upackingMaxNumber, failedTryAgain, timeout); + return ResourceUnpackerOperation.CreateEmptyUnpacker(Download, PackageName, upackingMaxNumber, failedTryAgain, timeout); } ResourceUnpackerOperation IPlayMode.CreateResourceUnpackerByTags(string[] tags, int upackingMaxNumber, int failedTryAgain, int timeout) { - return ResourceUnpackerOperation.CreateEmptyUnpacker(PackageName, upackingMaxNumber, failedTryAgain, timeout); + return ResourceUnpackerOperation.CreateEmptyUnpacker(Download, PackageName, upackingMaxNumber, failedTryAgain, timeout); } ResourceImporterOperation IPlayMode.CreateResourceImporterByFilePaths(string[] filePaths, int importerMaxNumber, int failedTryAgain, int timeout) { - return ResourceImporterOperation.CreateEmptyImporter(PackageName, importerMaxNumber, failedTryAgain, timeout); + return ResourceImporterOperation.CreateEmptyImporter(Download, PackageName, importerMaxNumber, failedTryAgain, timeout); } #endregion diff --git a/Assets/YooAsset/Runtime/ResourcePackage/PlayMode/HostPlayModeImpl.cs b/Assets/YooAsset/Runtime/ResourcePackage/PlayMode/HostPlayModeImpl.cs index d1862e1..eb152b3 100644 --- a/Assets/YooAsset/Runtime/ResourcePackage/PlayMode/HostPlayModeImpl.cs +++ b/Assets/YooAsset/Runtime/ResourcePackage/PlayMode/HostPlayModeImpl.cs @@ -13,6 +13,10 @@ namespace YooAsset private IRemoteServices _remoteServices; public readonly string PackageName; + public DownloadManager Download + { + get { return _assist.Download; } + } public PersistentManager Persistent { get { return _assist.Persistent; } @@ -124,7 +128,7 @@ namespace YooAsset ResourceDownloaderOperation IPlayMode.CreateResourceDownloaderByAll(int downloadingMaxNumber, int failedTryAgain, int timeout) { List downloadList = GetDownloadListByAll(_activeManifest); - var operation = new ResourceDownloaderOperation(PackageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout); + var operation = new ResourceDownloaderOperation(Download, PackageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout); return operation; } public List GetDownloadListByAll(PackageManifest manifest) @@ -153,7 +157,7 @@ namespace YooAsset ResourceDownloaderOperation IPlayMode.CreateResourceDownloaderByTags(string[] tags, int downloadingMaxNumber, int failedTryAgain, int timeout) { List downloadList = GetDownloadListByTags(_activeManifest, tags); - var operation = new ResourceDownloaderOperation(PackageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout); + var operation = new ResourceDownloaderOperation(Download, PackageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout); return operation; } public List GetDownloadListByTags(PackageManifest manifest, string[] tags) @@ -194,7 +198,7 @@ namespace YooAsset ResourceDownloaderOperation IPlayMode.CreateResourceDownloaderByPaths(AssetInfo[] assetInfos, int downloadingMaxNumber, int failedTryAgain, int timeout) { List downloadList = GetDownloadListByPaths(_activeManifest, assetInfos); - var operation = new ResourceDownloaderOperation(PackageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout); + var operation = new ResourceDownloaderOperation(Download, PackageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout); return operation; } public List GetDownloadListByPaths(PackageManifest manifest, AssetInfo[] assetInfos) @@ -247,7 +251,7 @@ namespace YooAsset ResourceUnpackerOperation IPlayMode.CreateResourceUnpackerByAll(int upackingMaxNumber, int failedTryAgain, int timeout) { List unpcakList = GetUnpackListByAll(_activeManifest); - var operation = new ResourceUnpackerOperation(PackageName, unpcakList, upackingMaxNumber, failedTryAgain, timeout); + var operation = new ResourceUnpackerOperation(Download, PackageName, unpcakList, upackingMaxNumber, failedTryAgain, timeout); return operation; } private List GetUnpackListByAll(PackageManifest manifest) @@ -271,7 +275,7 @@ namespace YooAsset ResourceUnpackerOperation IPlayMode.CreateResourceUnpackerByTags(string[] tags, int upackingMaxNumber, int failedTryAgain, int timeout) { List unpcakList = GetUnpackListByTags(_activeManifest, tags); - var operation = new ResourceUnpackerOperation(PackageName, unpcakList, upackingMaxNumber, failedTryAgain, timeout); + var operation = new ResourceUnpackerOperation(Download, PackageName, unpcakList, upackingMaxNumber, failedTryAgain, timeout); return operation; } private List GetUnpackListByTags(PackageManifest manifest, string[] tags) @@ -299,7 +303,7 @@ namespace YooAsset ResourceImporterOperation IPlayMode.CreateResourceImporterByFilePaths(string[] filePaths, int importerMaxNumber, int failedTryAgain, int timeout) { List importerList = GetImporterListByFilePaths(_activeManifest, filePaths); - var operation = new ResourceImporterOperation(PackageName, importerList, importerMaxNumber, failedTryAgain, timeout); + var operation = new ResourceImporterOperation(Download, PackageName, importerList, importerMaxNumber, failedTryAgain, timeout); return operation; } private List GetImporterListByFilePaths(PackageManifest manifest, string[] filePaths) diff --git a/Assets/YooAsset/Runtime/ResourcePackage/PlayMode/OfflinePlayModeImpl.cs b/Assets/YooAsset/Runtime/ResourcePackage/PlayMode/OfflinePlayModeImpl.cs index 0b9732d..96b3a2e 100644 --- a/Assets/YooAsset/Runtime/ResourcePackage/PlayMode/OfflinePlayModeImpl.cs +++ b/Assets/YooAsset/Runtime/ResourcePackage/PlayMode/OfflinePlayModeImpl.cs @@ -8,8 +8,12 @@ namespace YooAsset { private PackageManifest _activeManifest; private ResourceAssist _assist; - + public readonly string PackageName; + public DownloadManager Download + { + get { return _assist.Download; } + } public PersistentManager Persistent { get { return _assist.Persistent; } @@ -80,21 +84,21 @@ namespace YooAsset ResourceDownloaderOperation IPlayMode.CreateResourceDownloaderByAll(int downloadingMaxNumber, int failedTryAgain, int timeout) { - return ResourceDownloaderOperation.CreateEmptyDownloader(PackageName, downloadingMaxNumber, failedTryAgain, timeout); + return ResourceDownloaderOperation.CreateEmptyDownloader(Download, PackageName, downloadingMaxNumber, failedTryAgain, timeout); } ResourceDownloaderOperation IPlayMode.CreateResourceDownloaderByTags(string[] tags, int downloadingMaxNumber, int failedTryAgain, int timeout) { - return ResourceDownloaderOperation.CreateEmptyDownloader(PackageName, downloadingMaxNumber, failedTryAgain, timeout); + return ResourceDownloaderOperation.CreateEmptyDownloader(Download, PackageName, downloadingMaxNumber, failedTryAgain, timeout); } ResourceDownloaderOperation IPlayMode.CreateResourceDownloaderByPaths(AssetInfo[] assetInfos, int downloadingMaxNumber, int failedTryAgain, int timeout) { - return ResourceDownloaderOperation.CreateEmptyDownloader(PackageName, downloadingMaxNumber, failedTryAgain, timeout); + return ResourceDownloaderOperation.CreateEmptyDownloader(Download, PackageName, downloadingMaxNumber, failedTryAgain, timeout); } ResourceUnpackerOperation IPlayMode.CreateResourceUnpackerByAll(int upackingMaxNumber, int failedTryAgain, int timeout) { List unpcakList = GetUnpackListByAll(_activeManifest); - var operation = new ResourceUnpackerOperation(PackageName, unpcakList, upackingMaxNumber, failedTryAgain, timeout); + var operation = new ResourceUnpackerOperation(Download, PackageName, unpcakList, upackingMaxNumber, failedTryAgain, timeout); return operation; } private List GetUnpackListByAll(PackageManifest manifest) @@ -115,7 +119,7 @@ namespace YooAsset ResourceUnpackerOperation IPlayMode.CreateResourceUnpackerByTags(string[] tags, int upackingMaxNumber, int failedTryAgain, int timeout) { List unpcakList = GetUnpackListByTags(_activeManifest, tags); - var operation = new ResourceUnpackerOperation(PackageName, unpcakList, upackingMaxNumber, failedTryAgain, timeout); + var operation = new ResourceUnpackerOperation(Download, PackageName, unpcakList, upackingMaxNumber, failedTryAgain, timeout); return operation; } private List GetUnpackListByTags(PackageManifest manifest, string[] tags) @@ -140,7 +144,7 @@ namespace YooAsset ResourceImporterOperation IPlayMode.CreateResourceImporterByFilePaths(string[] filePaths, int importerMaxNumber, int failedTryAgain, int timeout) { List importerList = GetImporterListByFilePaths(_activeManifest, filePaths); - var operation = new ResourceImporterOperation(PackageName, importerList, importerMaxNumber, failedTryAgain, timeout); + var operation = new ResourceImporterOperation(Download, PackageName, importerList, importerMaxNumber, failedTryAgain, timeout); return operation; } private List GetImporterListByFilePaths(PackageManifest manifest, string[] filePaths) diff --git a/Assets/YooAsset/Runtime/ResourcePackage/PlayMode/WebPlayModeImpl.cs b/Assets/YooAsset/Runtime/ResourcePackage/PlayMode/WebPlayModeImpl.cs index 7fbaae9..95d987d 100644 --- a/Assets/YooAsset/Runtime/ResourcePackage/PlayMode/WebPlayModeImpl.cs +++ b/Assets/YooAsset/Runtime/ResourcePackage/PlayMode/WebPlayModeImpl.cs @@ -12,6 +12,10 @@ namespace YooAsset private IRemoteServices _remoteServices; public readonly string PackageName; + public DownloadManager Download + { + get { return _assist.Download; } + } public PersistentManager Persistent { get { return _assist.Persistent; } @@ -104,7 +108,7 @@ namespace YooAsset ResourceDownloaderOperation IPlayMode.CreateResourceDownloaderByAll(int downloadingMaxNumber, int failedTryAgain, int timeout) { List downloadList = GetDownloadListByAll(_activeManifest); - var operation = new ResourceDownloaderOperation(PackageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout); + var operation = new ResourceDownloaderOperation(Download, PackageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout); return operation; } public List GetDownloadListByAll(PackageManifest manifest) @@ -125,7 +129,7 @@ namespace YooAsset ResourceDownloaderOperation IPlayMode.CreateResourceDownloaderByTags(string[] tags, int downloadingMaxNumber, int failedTryAgain, int timeout) { List downloadList = GetDownloadListByTags(_activeManifest, tags); - var operation = new ResourceDownloaderOperation(PackageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout); + var operation = new ResourceDownloaderOperation(Download, PackageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout); return operation; } public List GetDownloadListByTags(PackageManifest manifest, string[] tags) @@ -158,7 +162,7 @@ namespace YooAsset ResourceDownloaderOperation IPlayMode.CreateResourceDownloaderByPaths(AssetInfo[] assetInfos, int downloadingMaxNumber, int failedTryAgain, int timeout) { List downloadList = GetDownloadListByPaths(_activeManifest, assetInfos); - var operation = new ResourceDownloaderOperation(PackageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout); + var operation = new ResourceDownloaderOperation(Download, PackageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout); return operation; } public List GetDownloadListByPaths(PackageManifest manifest, AssetInfo[] assetInfos) @@ -202,16 +206,16 @@ namespace YooAsset ResourceUnpackerOperation IPlayMode.CreateResourceUnpackerByAll(int upackingMaxNumber, int failedTryAgain, int timeout) { - return ResourceUnpackerOperation.CreateEmptyUnpacker(PackageName, upackingMaxNumber, failedTryAgain, timeout); + return ResourceUnpackerOperation.CreateEmptyUnpacker(Download, PackageName, upackingMaxNumber, failedTryAgain, timeout); } ResourceUnpackerOperation IPlayMode.CreateResourceUnpackerByTags(string[] tags, int upackingMaxNumber, int failedTryAgain, int timeout) { - return ResourceUnpackerOperation.CreateEmptyUnpacker(PackageName, upackingMaxNumber, failedTryAgain, timeout); + return ResourceUnpackerOperation.CreateEmptyUnpacker(Download, PackageName, upackingMaxNumber, failedTryAgain, timeout); } ResourceImporterOperation IPlayMode.CreateResourceImporterByFilePaths(string[] filePaths, int importerMaxNumber, int failedTryAgain, int timeout) { - return ResourceImporterOperation.CreateEmptyImporter(PackageName, importerMaxNumber, failedTryAgain, timeout); + return ResourceImporterOperation.CreateEmptyImporter(Download, PackageName, importerMaxNumber, failedTryAgain, timeout); } #endregion