From 45ecd8baff3846fde873442e6cabe5c94166f859 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BD=95=E5=86=A0=E5=B3=B0?= <33317070@qq.com> Date: Fri, 15 May 2026 10:56:24 +0800 Subject: [PATCH] feat: add EnsureBundleFileAsync operation --- .../BundleCache/Interfaces/IBundleCache.cs | 7 + .../BundleCache/Interfaces/ICacheEntry.cs | 2 +- .../Common/LoadLocalArchiveBundleOperation.cs | 2 +- .../Common/LoadLocalAssetBundleOperation.cs | 2 +- .../Common/LoadLocalRawBundleOperation.cs | 2 +- .../Common/LoadWebAssetBundleOperation.cs | 4 +- .../BuiltinBundleCache/BuiltinBundleCache.cs | 11 ++ .../EditorBundleCache/EditorBundleCache.cs | 12 +- .../EditorBundleCacheEntry.cs | 9 +- .../EBCLoadVirtualAssetBundleOperation.cs | 11 +- .../EBCLoadVirtualRawBundleOperation.cs | 2 +- .../Operations/EBCWriteCacheOperation.cs | 2 +- .../Operations/SBCLoadAssetBundleOperation.cs | 2 +- .../SandboxBundleCache/SandboxBundleCache.cs | 11 ++ .../LoadWebGameAssetBundleOperation.cs | 2 +- .../Internal/LoadWebGameAssetBundleOptions.cs | 8 +- .../WGBCLoadAssetBundleOperation.cs | 24 +-- .../WebGameBundleCache/WebGameBundleCache.cs | 31 +--- .../WebGameBundleCacheEntry.cs | 38 ----- .../WRBCLoadAssetBundleOperation.cs | 21 +-- .../WebRemoteBundleCache.cs | 32 +--- .../WebRemoteBundleCacheEntry.cs | 31 ---- .../WebServerBundleCache.cs | 8 +- .../BundleHandle/Interfaces/IBundleHandle.cs | 5 - .../ArchiveBundleHandle.cs | 11 +- .../AssetBundleHandle/AssetBundleHandle.cs | 11 +- .../RawBundleHandle/RawBundleHandle.cs | 11 +- .../VirtualAssetBundleHandle.cs | 11 +- .../VirtualRawBundleHandle.cs | 11 +- .../WebGameAssetBundleHandle.cs | 11 +- .../Compatibility/CompatibleHandles.cs | 21 ++- .../FileSystem/Interfaces/IFileSystem.cs | 7 + .../FSEnsurePackageBundleOperation.cs | 35 +++++ .../FSEnsurePackageBundleOperation.cs.meta} | 2 +- .../FSEnsurePackageBundleOptions.cs | 19 +++ .../FSEnsurePackageBundleOptions.cs.meta} | 2 +- .../BuiltinFileSystem/BuiltinFileSystem.cs | 6 + .../BFSEnsurePackageBundleOperation.cs | 105 +++++++++++++ .../BFSEnsurePackageBundleOperation.cs.meta | 11 ++ .../EditorFileSystem/EditorFileSystem.cs | 6 + .../EFSEnsurePackageBundleOperation.cs | 96 ++++++++++++ .../EFSEnsurePackageBundleOperation.cs.meta | 11 ++ .../SFSEnsurePackageBundleOperation.cs | 96 ++++++++++++ .../SFSEnsurePackageBundleOperation.cs.meta | 11 ++ .../SandboxFileSystem/SandboxFileSystem.cs | 6 + .../WebGameFileSystem/WebGameFileSystem.cs | 6 + .../WebRemoteFileSystem.cs | 6 + .../WebServerFileSystem.cs | 6 + .../Handles/BundleFileHandle.cs | 11 -- .../Runtime/ResourcePackage/BundleInfo.cs | 10 ++ .../Operations/EnsureBundleFileOperation.cs | 132 +++++++++++++++++ .../EnsureBundleFileOperation.cs.meta | 11 ++ .../Operations/EnsureBundleFileOptions.cs | 39 +++++ .../EnsureBundleFileOptions.cs.meta | 11 ++ .../ResourcePackage/ResourcePackage.cs | 138 ++++++++++-------- .../CommonTests/TestBundleFileRelease.cs | 3 +- .../CommonTests/TestEnsureBundleFile.cs | 75 ++++++++++ .../CommonTests/TestEnsureBundleFile.cs.meta | 11 ++ .../CommonTests/TestLoadArchiveBundle.cs | 20 +-- .../Runtime/CommonTests/TestLoadBundleFile.cs | 20 +-- .../T0_InitYooAssets/T0_InitYooAssets.cs | 2 +- .../T1_TestEditorFileSystem.cs | 23 ++- .../T2_TestBuiltinFileSystem.cs | 23 ++- .../Test Sample/TestRes/ArchiveFiles.meta | 8 + .../TestRes/ArchiveFiles/archive_file_a.txt | 1 + .../ArchiveFiles/archive_file_a.txt.meta | 7 + .../TestRes/ArchiveFiles/archive_file_b.txt | 1 + .../ArchiveFiles/archive_file_b.txt.meta | 7 + .../TestRes/ArchiveFiles/archive_file_c.txt | 1 + .../ArchiveFiles/archive_file_c.txt.meta | 7 + .../TestRes/ArchiveFiles/archive_file_d.txt | 1 + .../ArchiveFiles/archive_file_d.txt.meta | 7 + .../TestRes/ArchiveFiles/archive_file_e.txt | 1 + .../ArchiveFiles/archive_file_e.txt.meta | 7 + 74 files changed, 1000 insertions(+), 374 deletions(-) delete mode 100644 Assets/YooAsset/Runtime/BundleCache/Services/WebGameBundleCache/WebGameBundleCacheEntry.cs delete mode 100644 Assets/YooAsset/Runtime/BundleCache/Services/WebRemoteBundleCache/WebRemoteBundleCacheEntry.cs create mode 100644 Assets/YooAsset/Runtime/FileSystem/Operations/FSEnsurePackageBundleOperation.cs rename Assets/YooAsset/Runtime/{BundleCache/Services/WebGameBundleCache/WebGameBundleCacheEntry.cs.meta => FileSystem/Operations/FSEnsurePackageBundleOperation.cs.meta} (83%) create mode 100644 Assets/YooAsset/Runtime/FileSystem/Operations/FSEnsurePackageBundleOptions.cs rename Assets/YooAsset/Runtime/{BundleCache/Services/WebRemoteBundleCache/WebRemoteBundleCacheEntry.cs.meta => FileSystem/Operations/FSEnsurePackageBundleOptions.cs.meta} (83%) create mode 100644 Assets/YooAsset/Runtime/FileSystem/Services/BuiltinFileSystem/Operations/BFSEnsurePackageBundleOperation.cs create mode 100644 Assets/YooAsset/Runtime/FileSystem/Services/BuiltinFileSystem/Operations/BFSEnsurePackageBundleOperation.cs.meta create mode 100644 Assets/YooAsset/Runtime/FileSystem/Services/EditorFileSystem/Operations/EFSEnsurePackageBundleOperation.cs create mode 100644 Assets/YooAsset/Runtime/FileSystem/Services/EditorFileSystem/Operations/EFSEnsurePackageBundleOperation.cs.meta create mode 100644 Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/Operations/SFSEnsurePackageBundleOperation.cs create mode 100644 Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/Operations/SFSEnsurePackageBundleOperation.cs.meta create mode 100644 Assets/YooAsset/Runtime/ResourcePackage/Operations/EnsureBundleFileOperation.cs create mode 100644 Assets/YooAsset/Runtime/ResourcePackage/Operations/EnsureBundleFileOperation.cs.meta create mode 100644 Assets/YooAsset/Runtime/ResourcePackage/Operations/EnsureBundleFileOptions.cs create mode 100644 Assets/YooAsset/Runtime/ResourcePackage/Operations/EnsureBundleFileOptions.cs.meta create mode 100644 Assets/YooAsset/Samples~/Test Sample/Runtime/CommonTests/TestEnsureBundleFile.cs create mode 100644 Assets/YooAsset/Samples~/Test Sample/Runtime/CommonTests/TestEnsureBundleFile.cs.meta create mode 100644 Assets/YooAsset/Samples~/Test Sample/TestRes/ArchiveFiles.meta create mode 100644 Assets/YooAsset/Samples~/Test Sample/TestRes/ArchiveFiles/archive_file_a.txt create mode 100644 Assets/YooAsset/Samples~/Test Sample/TestRes/ArchiveFiles/archive_file_a.txt.meta create mode 100644 Assets/YooAsset/Samples~/Test Sample/TestRes/ArchiveFiles/archive_file_b.txt create mode 100644 Assets/YooAsset/Samples~/Test Sample/TestRes/ArchiveFiles/archive_file_b.txt.meta create mode 100644 Assets/YooAsset/Samples~/Test Sample/TestRes/ArchiveFiles/archive_file_c.txt create mode 100644 Assets/YooAsset/Samples~/Test Sample/TestRes/ArchiveFiles/archive_file_c.txt.meta create mode 100644 Assets/YooAsset/Samples~/Test Sample/TestRes/ArchiveFiles/archive_file_d.txt create mode 100644 Assets/YooAsset/Samples~/Test Sample/TestRes/ArchiveFiles/archive_file_d.txt.meta create mode 100644 Assets/YooAsset/Samples~/Test Sample/TestRes/ArchiveFiles/archive_file_e.txt create mode 100644 Assets/YooAsset/Samples~/Test Sample/TestRes/ArchiveFiles/archive_file_e.txt.meta diff --git a/Assets/YooAsset/Runtime/BundleCache/Interfaces/IBundleCache.cs b/Assets/YooAsset/Runtime/BundleCache/Interfaces/IBundleCache.cs index 97f6dbcd..4e1ebc2f 100644 --- a/Assets/YooAsset/Runtime/BundleCache/Interfaces/IBundleCache.cs +++ b/Assets/YooAsset/Runtime/BundleCache/Interfaces/IBundleCache.cs @@ -73,5 +73,12 @@ namespace YooAsset /// 资源包的唯一标识符 /// 如果缓存中存在该资源包则返回 true,否则返回 false。 bool IsCached(string bundleGuid); + + /// + /// 获取已缓存的资源包文件路径 + /// + /// 资源包的唯一标识符 + /// 返回已缓存的资源包文件路径,如果不存在则返回 null。 + string GetCacheFilePath(string bundleGuid); } } diff --git a/Assets/YooAsset/Runtime/BundleCache/Interfaces/ICacheEntry.cs b/Assets/YooAsset/Runtime/BundleCache/Interfaces/ICacheEntry.cs index d2f3060e..e377022b 100644 --- a/Assets/YooAsset/Runtime/BundleCache/Interfaces/ICacheEntry.cs +++ b/Assets/YooAsset/Runtime/BundleCache/Interfaces/ICacheEntry.cs @@ -7,7 +7,7 @@ namespace YooAsset internal interface ICacheEntry { /// - /// Bundle 唯一标识 + /// 资源包唯一标识 /// string BundleGuid { get; } } diff --git a/Assets/YooAsset/Runtime/BundleCache/Operations/Common/LoadLocalArchiveBundleOperation.cs b/Assets/YooAsset/Runtime/BundleCache/Operations/Common/LoadLocalArchiveBundleOperation.cs index 0505675c..a51b620b 100644 --- a/Assets/YooAsset/Runtime/BundleCache/Operations/Common/LoadLocalArchiveBundleOperation.cs +++ b/Assets/YooAsset/Runtime/BundleCache/Operations/Common/LoadLocalArchiveBundleOperation.cs @@ -74,7 +74,7 @@ namespace YooAsset { _steps = ESteps.Done; SetResult(); - BundleHandle = new ArchiveBundleHandle(_options.FilePath, _options.Bundle, _archiveBundle); + BundleHandle = new ArchiveBundleHandle(_options.Bundle, _archiveBundle); } } } diff --git a/Assets/YooAsset/Runtime/BundleCache/Operations/Common/LoadLocalAssetBundleOperation.cs b/Assets/YooAsset/Runtime/BundleCache/Operations/Common/LoadLocalAssetBundleOperation.cs index e8e2fc9e..8d2c8894 100644 --- a/Assets/YooAsset/Runtime/BundleCache/Operations/Common/LoadLocalAssetBundleOperation.cs +++ b/Assets/YooAsset/Runtime/BundleCache/Operations/Common/LoadLocalAssetBundleOperation.cs @@ -121,7 +121,7 @@ namespace YooAsset { _steps = ESteps.Done; SetResult(); - BundleHandle = new AssetBundleHandle(_options.FilePath, _options.Bundle, _assetBundle, _loadStream); + BundleHandle = new AssetBundleHandle(_options.Bundle, _assetBundle, _loadStream); } } } diff --git a/Assets/YooAsset/Runtime/BundleCache/Operations/Common/LoadLocalRawBundleOperation.cs b/Assets/YooAsset/Runtime/BundleCache/Operations/Common/LoadLocalRawBundleOperation.cs index dcd947f9..591535f7 100644 --- a/Assets/YooAsset/Runtime/BundleCache/Operations/Common/LoadLocalRawBundleOperation.cs +++ b/Assets/YooAsset/Runtime/BundleCache/Operations/Common/LoadLocalRawBundleOperation.cs @@ -100,7 +100,7 @@ namespace YooAsset { _steps = ESteps.Done; SetResult(); - BundleHandle = new RawBundleHandle(_options.FilePath, _options.Bundle, _rawBundle); + BundleHandle = new RawBundleHandle(_options.Bundle, _rawBundle); } } } diff --git a/Assets/YooAsset/Runtime/BundleCache/Operations/Common/LoadWebAssetBundleOperation.cs b/Assets/YooAsset/Runtime/BundleCache/Operations/Common/LoadWebAssetBundleOperation.cs index 0d70b1d7..ecbb7b85 100644 --- a/Assets/YooAsset/Runtime/BundleCache/Operations/Common/LoadWebAssetBundleOperation.cs +++ b/Assets/YooAsset/Runtime/BundleCache/Operations/Common/LoadWebAssetBundleOperation.cs @@ -75,7 +75,7 @@ namespace YooAsset { _steps = ESteps.Done; SetResult(); - BundleHandle = new AssetBundleHandle(_downloadAssetBundleRequest.Url, _options.Bundle, assetBundle, null); + BundleHandle = new AssetBundleHandle(_options.Bundle, assetBundle, null); } } else @@ -290,7 +290,7 @@ namespace YooAsset { _steps = ESteps.Done; SetResult(); - BundleHandle = new AssetBundleHandle(_downloadBytesRequest.Url, _options.Bundle, assetBundle, null); + BundleHandle = new AssetBundleHandle(_options.Bundle, assetBundle, null); } } diff --git a/Assets/YooAsset/Runtime/BundleCache/Services/BuiltinBundleCache/BuiltinBundleCache.cs b/Assets/YooAsset/Runtime/BundleCache/Services/BuiltinBundleCache/BuiltinBundleCache.cs index 896241fe..72ce7ba3 100644 --- a/Assets/YooAsset/Runtime/BundleCache/Services/BuiltinBundleCache/BuiltinBundleCache.cs +++ b/Assets/YooAsset/Runtime/BundleCache/Services/BuiltinBundleCache/BuiltinBundleCache.cs @@ -135,6 +135,17 @@ namespace YooAsset { return _cacheEntries.ContainsKey(bundleGuid); } + /// + public string GetCacheFilePath(string bundleGuid) + { + if (_cacheEntries.TryGetValue(bundleGuid, out BuiltinBundleCacheEntry entry)) + { + return entry.FilePath; + } + + YooLogger.LogWarning($"Cache file path not found. Bundle GUID: '{bundleGuid}'."); + return null; + } #region 内部方法 /// diff --git a/Assets/YooAsset/Runtime/BundleCache/Services/EditorBundleCache/EditorBundleCache.cs b/Assets/YooAsset/Runtime/BundleCache/Services/EditorBundleCache/EditorBundleCache.cs index 0105c29d..97696844 100644 --- a/Assets/YooAsset/Runtime/BundleCache/Services/EditorBundleCache/EditorBundleCache.cs +++ b/Assets/YooAsset/Runtime/BundleCache/Services/EditorBundleCache/EditorBundleCache.cs @@ -142,10 +142,16 @@ namespace YooAsset /// public bool IsCached(string bundleGuid) { - if (Config.VirtualDownloadMode) - return _cacheEntries.ContainsKey(bundleGuid); - else + if (Config.VirtualDownloadMode == false) return true; + + return _cacheEntries.ContainsKey(bundleGuid); + } + /// + public string GetCacheFilePath(string bundleGuid) + { + YooLogger.LogWarning($"{nameof(EditorBundleCache)} does not support local cache file path."); + return null; } /// diff --git a/Assets/YooAsset/Runtime/BundleCache/Services/EditorBundleCache/EditorBundleCacheEntry.cs b/Assets/YooAsset/Runtime/BundleCache/Services/EditorBundleCache/EditorBundleCacheEntry.cs index e5586b33..11ca1f2b 100644 --- a/Assets/YooAsset/Runtime/BundleCache/Services/EditorBundleCache/EditorBundleCacheEntry.cs +++ b/Assets/YooAsset/Runtime/BundleCache/Services/EditorBundleCache/EditorBundleCacheEntry.cs @@ -11,20 +11,13 @@ namespace YooAsset /// public string BundleGuid { get; private set; } - /// - /// 资源包文件路径 - /// - public string FilePath { get; private set; } - /// /// 创建编辑器文件缓存条目实例 /// /// 资源包唯一标识 - /// 资源包文件路径 - public EditorBundleCacheEntry(string bundleGuid, string filePath) + public EditorBundleCacheEntry(string bundleGuid) { BundleGuid = bundleGuid; - FilePath = filePath; } } } \ No newline at end of file diff --git a/Assets/YooAsset/Runtime/BundleCache/Services/EditorBundleCache/Operations/EBCLoadVirtualAssetBundleOperation.cs b/Assets/YooAsset/Runtime/BundleCache/Services/EditorBundleCache/Operations/EBCLoadVirtualAssetBundleOperation.cs index 7fc0ded1..118a8dbf 100644 --- a/Assets/YooAsset/Runtime/BundleCache/Services/EditorBundleCache/Operations/EBCLoadVirtualAssetBundleOperation.cs +++ b/Assets/YooAsset/Runtime/BundleCache/Services/EditorBundleCache/Operations/EBCLoadVirtualAssetBundleOperation.cs @@ -1,5 +1,3 @@ -using System; -using System.IO; namespace YooAsset { @@ -13,15 +11,8 @@ namespace YooAsset protected override void CreateBundleHandle() { - string editorFilePath = EditorFileSystemHelper.GetEditorFilePath(_bundle); - if (string.IsNullOrEmpty(editorFilePath)) - { - SetError($"Editor file path is null. Bundle: '{_bundle.BundleName}'."); - return; - } - SetResult(); - BundleHandle = new VirtualAssetBundleHandle(editorFilePath, _bundle); + BundleHandle = new VirtualAssetBundleHandle(_bundle); } } } diff --git a/Assets/YooAsset/Runtime/BundleCache/Services/EditorBundleCache/Operations/EBCLoadVirtualRawBundleOperation.cs b/Assets/YooAsset/Runtime/BundleCache/Services/EditorBundleCache/Operations/EBCLoadVirtualRawBundleOperation.cs index c932e802..3498093f 100644 --- a/Assets/YooAsset/Runtime/BundleCache/Services/EditorBundleCache/Operations/EBCLoadVirtualRawBundleOperation.cs +++ b/Assets/YooAsset/Runtime/BundleCache/Services/EditorBundleCache/Operations/EBCLoadVirtualRawBundleOperation.cs @@ -26,7 +26,7 @@ namespace YooAsset var rawBundle = new RawBundle(data); SetResult(); - BundleHandle = new VirtualRawBundleHandle(editorFilePath, _bundle, rawBundle); + BundleHandle = new VirtualRawBundleHandle(_bundle, rawBundle); } catch (Exception ex) { diff --git a/Assets/YooAsset/Runtime/BundleCache/Services/EditorBundleCache/Operations/EBCWriteCacheOperation.cs b/Assets/YooAsset/Runtime/BundleCache/Services/EditorBundleCache/Operations/EBCWriteCacheOperation.cs index 1a6e11a4..35889e97 100644 --- a/Assets/YooAsset/Runtime/BundleCache/Services/EditorBundleCache/Operations/EBCWriteCacheOperation.cs +++ b/Assets/YooAsset/Runtime/BundleCache/Services/EditorBundleCache/Operations/EBCWriteCacheOperation.cs @@ -52,7 +52,7 @@ namespace YooAsset if (_steps == ESteps.CacheFile) { - var cacheEntry = new EditorBundleCacheEntry(_options.Bundle.BundleGuid, _options.FilePath); + var cacheEntry = new EditorBundleCacheEntry(_options.Bundle.BundleGuid); _fileCache.AddEntry(_options.Bundle.BundleGuid, cacheEntry); _steps = ESteps.Done; SetResult(); diff --git a/Assets/YooAsset/Runtime/BundleCache/Services/SandboxBundleCache/Operations/SBCLoadAssetBundleOperation.cs b/Assets/YooAsset/Runtime/BundleCache/Services/SandboxBundleCache/Operations/SBCLoadAssetBundleOperation.cs index fb629146..d3edf50b 100644 --- a/Assets/YooAsset/Runtime/BundleCache/Services/SandboxBundleCache/Operations/SBCLoadAssetBundleOperation.cs +++ b/Assets/YooAsset/Runtime/BundleCache/Services/SandboxBundleCache/Operations/SBCLoadAssetBundleOperation.cs @@ -170,7 +170,7 @@ namespace YooAsset { _steps = ESteps.Done; SetResult(); - BundleHandle = new AssetBundleHandle(_cacheEntry.DataFilePath, _bundle, assetBundle, null); + BundleHandle = new AssetBundleHandle(_bundle, assetBundle, null); } } } diff --git a/Assets/YooAsset/Runtime/BundleCache/Services/SandboxBundleCache/SandboxBundleCache.cs b/Assets/YooAsset/Runtime/BundleCache/Services/SandboxBundleCache/SandboxBundleCache.cs index 624bb243..706e4a32 100644 --- a/Assets/YooAsset/Runtime/BundleCache/Services/SandboxBundleCache/SandboxBundleCache.cs +++ b/Assets/YooAsset/Runtime/BundleCache/Services/SandboxBundleCache/SandboxBundleCache.cs @@ -154,6 +154,17 @@ namespace YooAsset { return _cacheEntries.ContainsKey(bundleGuid); } + /// + public string GetCacheFilePath(string bundleGuid) + { + if (_cacheEntries.TryGetValue(bundleGuid, out SandboxBundleCacheEntry entry)) + { + return entry.DataFilePath; + } + + YooLogger.LogWarning($"Cache file path not found. Bundle GUID: '{bundleGuid}'."); + return null; + } /// /// 根据 ClearMethod 创建对应的淘汰策略实例 diff --git a/Assets/YooAsset/Runtime/BundleCache/Services/WebGameBundleCache/Operations/Internal/LoadWebGameAssetBundleOperation.cs b/Assets/YooAsset/Runtime/BundleCache/Services/WebGameBundleCache/Operations/Internal/LoadWebGameAssetBundleOperation.cs index 2b8e1c7f..c7d15448 100644 --- a/Assets/YooAsset/Runtime/BundleCache/Services/WebGameBundleCache/Operations/Internal/LoadWebGameAssetBundleOperation.cs +++ b/Assets/YooAsset/Runtime/BundleCache/Services/WebGameBundleCache/Operations/Internal/LoadWebGameAssetBundleOperation.cs @@ -69,7 +69,7 @@ namespace YooAsset { _steps = ESteps.Done; SetResult(); - BundleHandle = new WebGameAssetBundleHandle(_options.CacheFilePath, _options.Bundle, assetBundle, _options.GamePlatform); + BundleHandle = new WebGameAssetBundleHandle(_options.Bundle, assetBundle, _options.GamePlatform); } } else diff --git a/Assets/YooAsset/Runtime/BundleCache/Services/WebGameBundleCache/Operations/Internal/LoadWebGameAssetBundleOptions.cs b/Assets/YooAsset/Runtime/BundleCache/Services/WebGameBundleCache/Operations/Internal/LoadWebGameAssetBundleOptions.cs index 9413bcaa..eeb6424d 100644 --- a/Assets/YooAsset/Runtime/BundleCache/Services/WebGameBundleCache/Operations/Internal/LoadWebGameAssetBundleOptions.cs +++ b/Assets/YooAsset/Runtime/BundleCache/Services/WebGameBundleCache/Operations/Internal/LoadWebGameAssetBundleOptions.cs @@ -22,11 +22,6 @@ namespace YooAsset /// public IWebGamePlatform GamePlatform { get; } - /// - /// 平台侧缓存文件路径 - /// - public string CacheFilePath { get; } - /// /// 看门狗超时时间 /// @@ -43,13 +38,12 @@ namespace YooAsset public IDownloadUrlPolicy DownloadUrlPolicy { get; } public LoadWebGameAssetBundleOptions(PackageBundle bundle, IReadOnlyList candidateUrls, - IWebGamePlatform gamePlatform, string cacheFilePath, int watchdogTimeout, + IWebGamePlatform gamePlatform, int watchdogTimeout, IDownloadRetryPolicy downloadRetryPolicy, IDownloadUrlPolicy downloadUrlPolicy) { Bundle = bundle; CandidateUrls = candidateUrls; GamePlatform = gamePlatform; - CacheFilePath = cacheFilePath; WatchdogTimeout = watchdogTimeout; DownloadRetryPolicy = downloadRetryPolicy; DownloadUrlPolicy = downloadUrlPolicy; diff --git a/Assets/YooAsset/Runtime/BundleCache/Services/WebGameBundleCache/Operations/WGBCLoadAssetBundleOperation.cs b/Assets/YooAsset/Runtime/BundleCache/Services/WebGameBundleCache/Operations/WGBCLoadAssetBundleOperation.cs index 6c9e27c9..a26bc16d 100644 --- a/Assets/YooAsset/Runtime/BundleCache/Services/WebGameBundleCache/Operations/WGBCLoadAssetBundleOperation.cs +++ b/Assets/YooAsset/Runtime/BundleCache/Services/WebGameBundleCache/Operations/WGBCLoadAssetBundleOperation.cs @@ -8,7 +8,6 @@ namespace YooAsset private enum ESteps { None, - GetEntry, LoadBundle, Done, } @@ -16,7 +15,6 @@ namespace YooAsset private readonly WebGameBundleCache _fileCache; private readonly BCLoadBundleOptions _options; private BCLoadBundleOperation _loadBundleOp; - private WebGameBundleCacheEntry _cacheEntry; private ESteps _steps = ESteps.None; internal WGBCLoadAssetBundleOperation(WebGameBundleCache fileCache, BCLoadBundleOptions options) @@ -26,37 +24,24 @@ namespace YooAsset } protected override void InternalStart() { - _steps = ESteps.GetEntry; + _steps = ESteps.LoadBundle; } protected override void InternalUpdate() { if (_steps == ESteps.None || _steps == ESteps.Done) return; - if (_steps == ESteps.GetEntry) - { - _cacheEntry = _fileCache.GetEntry(_options.Bundle); - if (_cacheEntry == null) - { - _steps = ESteps.Done; - SetError($"File cache entry not found: '{_options.Bundle.BundleGuid}'."); - } - else - { - _steps = ESteps.LoadBundle; - } - } - if (_steps == ESteps.LoadBundle) { if (_loadBundleOp == null) { + var urls = _fileCache.Config.RemoteService.GetRemoteUrls(_options.Bundle.GetFileName()); if (_options.Bundle.IsEncrypted) { var options = new LoadWebAssetBundleOptions( cacheName: _fileCache.GetType().Name, bundle: _options.Bundle, - candidateUrls: _cacheEntry.Urls, + candidateUrls: urls, assetBundleDecryptor: _fileCache.Config.AssetBundleDecryptor, downloadBackend: _fileCache.Config.DownloadBackend, downloadVerifyLevel: _fileCache.Config.DownloadVerifyLevel, @@ -70,9 +55,8 @@ namespace YooAsset { var webGameOptions = new LoadWebGameAssetBundleOptions( bundle: _options.Bundle, - candidateUrls: _cacheEntry.Urls, + candidateUrls: urls, gamePlatform: _fileCache.Config.GamePlatform, - cacheFilePath: _cacheEntry.CacheFilePath, watchdogTimeout: _fileCache.Config.WatchdogTimeout, downloadRetryPolicy: _fileCache.Config.DownloadRetryPolicy, downloadUrlPolicy: _fileCache.Config.DownloadUrlPolicy); diff --git a/Assets/YooAsset/Runtime/BundleCache/Services/WebGameBundleCache/WebGameBundleCache.cs b/Assets/YooAsset/Runtime/BundleCache/Services/WebGameBundleCache/WebGameBundleCache.cs index 81a4fa38..a01f945e 100644 --- a/Assets/YooAsset/Runtime/BundleCache/Services/WebGameBundleCache/WebGameBundleCache.cs +++ b/Assets/YooAsset/Runtime/BundleCache/Services/WebGameBundleCache/WebGameBundleCache.cs @@ -71,8 +71,6 @@ namespace YooAsset } } - private readonly Dictionary _cacheEntries = new Dictionary(10000); - /// /// 缓存配置 /// @@ -89,10 +87,10 @@ namespace YooAsset public bool IsReadOnly { get; } /// - public int FileCount => _cacheEntries.Count; + public int FileCount { get; } /// - public long SpaceOccupied => 0; + public long SpaceOccupied { get; } #endregion /// @@ -155,28 +153,13 @@ namespace YooAsset /// public bool IsCached(string bundleGuid) { - if (_cacheEntries.TryGetValue(bundleGuid, out var entry)) - return Config.GamePlatform.IsCached(entry.CacheFilePath); - return false; + return true; } - - #region 内部方法 - /// - /// 获取或创建指定资源包的缓存条目 - /// - /// 资源包描述 - /// 已存在则返回对应条目;否则创建并登记后返回新条目。 - internal WebGameBundleCacheEntry GetEntry(PackageBundle bundle) + /// + public string GetCacheFilePath(string bundleGuid) { - if (_cacheEntries.TryGetValue(bundle.BundleGuid, out var entry)) - return entry; - - var urls = Config.RemoteService.GetRemoteUrls(bundle.GetFileName()); - var filePath = Config.GamePlatform.GetCacheFilePath(RootPath, bundle); - var newEntry = new WebGameBundleCacheEntry(bundle.BundleGuid, urls, filePath); - _cacheEntries.Add(bundle.BundleGuid, newEntry); - return newEntry; + YooLogger.LogWarning($"{nameof(WebGameBundleCache)} does not support local cache file path."); + return null; } - #endregion } } diff --git a/Assets/YooAsset/Runtime/BundleCache/Services/WebGameBundleCache/WebGameBundleCacheEntry.cs b/Assets/YooAsset/Runtime/BundleCache/Services/WebGameBundleCache/WebGameBundleCacheEntry.cs deleted file mode 100644 index 093c896b..00000000 --- a/Assets/YooAsset/Runtime/BundleCache/Services/WebGameBundleCache/WebGameBundleCacheEntry.cs +++ /dev/null @@ -1,38 +0,0 @@ -using System.Collections.Generic; - -namespace YooAsset -{ - /// - /// WebGL 游戏平台缓存条目 - /// - internal class WebGameBundleCacheEntry : ICacheEntry - { - /// - /// 资源包唯一标识 - /// - public string BundleGuid { get; } - - /// - /// 候选下载地址列表 - /// - public IReadOnlyList Urls { get; } - - /// - /// 平台侧缓存文件路径 - /// - public string CacheFilePath { get; } - - /// - /// 创建 WebGL 游戏平台缓存条目实例 - /// - /// 资源包唯一标识 - /// 候选下载地址列表 - /// 平台侧缓存文件路径 - public WebGameBundleCacheEntry(string bundleGuid, IReadOnlyList urls, string cacheFilePath) - { - BundleGuid = bundleGuid; - Urls = urls; - CacheFilePath = cacheFilePath; - } - } -} diff --git a/Assets/YooAsset/Runtime/BundleCache/Services/WebRemoteBundleCache/Operations/WRBCLoadAssetBundleOperation.cs b/Assets/YooAsset/Runtime/BundleCache/Services/WebRemoteBundleCache/Operations/WRBCLoadAssetBundleOperation.cs index a2f8f733..7586de32 100644 --- a/Assets/YooAsset/Runtime/BundleCache/Services/WebRemoteBundleCache/Operations/WRBCLoadAssetBundleOperation.cs +++ b/Assets/YooAsset/Runtime/BundleCache/Services/WebRemoteBundleCache/Operations/WRBCLoadAssetBundleOperation.cs @@ -9,7 +9,6 @@ namespace YooAsset private enum ESteps { None, - GetEntry, LoadBundle, Done, } @@ -17,7 +16,6 @@ namespace YooAsset private readonly WebRemoteBundleCache _fileCache; private readonly BCLoadBundleOptions _options; private BCLoadBundleOperation _loadBundleOp; - private WebRemoteBundleCacheEntry _cacheEntry; private ESteps _steps = ESteps.None; /// @@ -32,35 +30,22 @@ namespace YooAsset } protected override void InternalStart() { - _steps = ESteps.GetEntry; + _steps = ESteps.LoadBundle; } protected override void InternalUpdate() { if (_steps == ESteps.None || _steps == ESteps.Done) return; - if (_steps == ESteps.GetEntry) - { - _cacheEntry = _fileCache.GetEntry(_options.Bundle); - if (_cacheEntry == null) - { - _steps = ESteps.Done; - SetError($"File cache entry not found: '{_options.Bundle.BundleGuid}'."); - } - else - { - _steps = ESteps.LoadBundle; - } - } - if (_steps == ESteps.LoadBundle) { if (_loadBundleOp == null) { + var urls = _fileCache.Config.RemoteService.GetRemoteUrls(_options.Bundle.GetFileName()); var options = new LoadWebAssetBundleOptions( cacheName: _fileCache.GetType().Name, bundle: _options.Bundle, - candidateUrls: _cacheEntry.Urls, + candidateUrls: urls, assetBundleDecryptor: _fileCache.Config.AssetBundleDecryptor, downloadBackend: _fileCache.Config.DownloadBackend, downloadVerifyLevel: _fileCache.Config.DownloadVerifyLevel, diff --git a/Assets/YooAsset/Runtime/BundleCache/Services/WebRemoteBundleCache/WebRemoteBundleCache.cs b/Assets/YooAsset/Runtime/BundleCache/Services/WebRemoteBundleCache/WebRemoteBundleCache.cs index cf1f9c2d..0b3287f9 100644 --- a/Assets/YooAsset/Runtime/BundleCache/Services/WebRemoteBundleCache/WebRemoteBundleCache.cs +++ b/Assets/YooAsset/Runtime/BundleCache/Services/WebRemoteBundleCache/WebRemoteBundleCache.cs @@ -65,8 +65,6 @@ namespace YooAsset } } - private readonly Dictionary _cacheEntries = new Dictionary(10000); - /// /// 缓存配置 /// @@ -83,16 +81,10 @@ namespace YooAsset public bool IsReadOnly { get; } /// - public int FileCount - { - get - { - return _cacheEntries.Count; - } - } + public int FileCount { get; } /// - public long SpaceOccupied { get; private set; } + public long SpaceOccupied { get; } #endregion /// @@ -157,23 +149,11 @@ namespace YooAsset { return true; } - - #region 内部方法 - /// - /// 获取或创建指定资源包的缓存条目 - /// - /// 资源包描述 - /// 已存在则返回对应条目;否则创建并登记后返回新条目。 - internal WebRemoteBundleCacheEntry GetEntry(PackageBundle bundle) + /// + public string GetCacheFilePath(string bundleGuid) { - if (_cacheEntries.TryGetValue(bundle.BundleGuid, out WebRemoteBundleCacheEntry entry)) - return entry; - - var urls = Config.RemoteService.GetRemoteUrls(bundle.GetFileName()); - var newEntry = new WebRemoteBundleCacheEntry(bundle.BundleGuid, urls); - _cacheEntries.Add(bundle.BundleGuid, newEntry); - return newEntry; + YooLogger.LogWarning($"{nameof(WebRemoteBundleCache)} does not support local cache file path."); + return null; } - #endregion } } \ No newline at end of file diff --git a/Assets/YooAsset/Runtime/BundleCache/Services/WebRemoteBundleCache/WebRemoteBundleCacheEntry.cs b/Assets/YooAsset/Runtime/BundleCache/Services/WebRemoteBundleCache/WebRemoteBundleCacheEntry.cs deleted file mode 100644 index d4bd4047..00000000 --- a/Assets/YooAsset/Runtime/BundleCache/Services/WebRemoteBundleCache/WebRemoteBundleCacheEntry.cs +++ /dev/null @@ -1,31 +0,0 @@ -using System.Collections.Generic; - -namespace YooAsset -{ - /// - /// Web远端文件缓存条目 - /// - internal class WebRemoteBundleCacheEntry : ICacheEntry - { - /// - /// 资源包唯一标识 - /// - public string BundleGuid { get; } - - /// - /// 候选下载地址列表 - /// - public IReadOnlyList Urls { get; } - - /// - /// 创建 Web 远端文件缓存条目实例 - /// - /// 资源包唯一标识 - /// 候选下载地址列表 - public WebRemoteBundleCacheEntry(string bundleGuid, IReadOnlyList urls) - { - BundleGuid = bundleGuid; - Urls = urls; - } - } -} diff --git a/Assets/YooAsset/Runtime/BundleCache/Services/WebServerBundleCache/WebServerBundleCache.cs b/Assets/YooAsset/Runtime/BundleCache/Services/WebServerBundleCache/WebServerBundleCache.cs index fe3de2eb..a09f79ce 100644 --- a/Assets/YooAsset/Runtime/BundleCache/Services/WebServerBundleCache/WebServerBundleCache.cs +++ b/Assets/YooAsset/Runtime/BundleCache/Services/WebServerBundleCache/WebServerBundleCache.cs @@ -86,7 +86,7 @@ namespace YooAsset } /// - public long SpaceOccupied { get; private set; } + public long SpaceOccupied { get; } #endregion /// @@ -151,6 +151,12 @@ namespace YooAsset { return _cacheEntries.ContainsKey(bundleGuid); } + /// + public string GetCacheFilePath(string bundleGuid) + { + YooLogger.LogWarning($"{nameof(WebServerBundleCache)} does not support local cache file path."); + return null; + } #region 内部方法 /// diff --git a/Assets/YooAsset/Runtime/BundleHandle/Interfaces/IBundleHandle.cs b/Assets/YooAsset/Runtime/BundleHandle/Interfaces/IBundleHandle.cs index 03286a6a..4b39da56 100644 --- a/Assets/YooAsset/Runtime/BundleHandle/Interfaces/IBundleHandle.cs +++ b/Assets/YooAsset/Runtime/BundleHandle/Interfaces/IBundleHandle.cs @@ -7,11 +7,6 @@ namespace YooAsset /// internal interface IBundleHandle { - /// - /// 资源包文件的本地路径 - /// - string BundleFilePath { get; } - /// /// 卸载资源包 /// diff --git a/Assets/YooAsset/Runtime/BundleHandle/Services/ArchiveBundleHandle/ArchiveBundleHandle.cs b/Assets/YooAsset/Runtime/BundleHandle/Services/ArchiveBundleHandle/ArchiveBundleHandle.cs index 5f2e10ca..edd31387 100644 --- a/Assets/YooAsset/Runtime/BundleHandle/Services/ArchiveBundleHandle/ArchiveBundleHandle.cs +++ b/Assets/YooAsset/Runtime/BundleHandle/Services/ArchiveBundleHandle/ArchiveBundleHandle.cs @@ -7,25 +7,16 @@ namespace YooAsset /// internal sealed class ArchiveBundleHandle : IBundleHandle { - private readonly string _bundleFilePath; private readonly PackageBundle _packageBundle; private readonly ArchiveBundle _archiveBundle; - /// - public string BundleFilePath - { - get { return _bundleFilePath; } - } - /// /// 创建 ArchiveBundleHandle 实例 /// - /// 资源包文件的本地路径 /// 资源包描述 /// 已解析的归档资源包数据对象 - public ArchiveBundleHandle(string bundleFilePath, PackageBundle packageBundle, ArchiveBundle archiveBundle) + public ArchiveBundleHandle(PackageBundle packageBundle, ArchiveBundle archiveBundle) { - _bundleFilePath = bundleFilePath; _packageBundle = packageBundle; _archiveBundle = archiveBundle; } diff --git a/Assets/YooAsset/Runtime/BundleHandle/Services/AssetBundleHandle/AssetBundleHandle.cs b/Assets/YooAsset/Runtime/BundleHandle/Services/AssetBundleHandle/AssetBundleHandle.cs index b98f843b..05145cbc 100644 --- a/Assets/YooAsset/Runtime/BundleHandle/Services/AssetBundleHandle/AssetBundleHandle.cs +++ b/Assets/YooAsset/Runtime/BundleHandle/Services/AssetBundleHandle/AssetBundleHandle.cs @@ -9,27 +9,18 @@ namespace YooAsset /// internal sealed class AssetBundleHandle : IBundleHandle { - private readonly string _bundleFilePath; private readonly PackageBundle _packageBundle; private readonly AssetBundle _assetBundle; private readonly Stream _bundleStream; - /// - public string BundleFilePath - { - get { return _bundleFilePath; } - } - /// /// 创建 AssetBundleHandle 实例 /// - /// 资源包文件的本地路径 /// 资源包描述 /// 已加载的 AssetBundle 对象 /// 加载 AssetBundle 时使用的文件流 - public AssetBundleHandle(string bundleFilePath, PackageBundle packageBundle, AssetBundle assetBundle, Stream bundleStream) + public AssetBundleHandle(PackageBundle packageBundle, AssetBundle assetBundle, Stream bundleStream) { - _bundleFilePath = bundleFilePath; _packageBundle = packageBundle; _assetBundle = assetBundle; _bundleStream = bundleStream; diff --git a/Assets/YooAsset/Runtime/BundleHandle/Services/RawBundleHandle/RawBundleHandle.cs b/Assets/YooAsset/Runtime/BundleHandle/Services/RawBundleHandle/RawBundleHandle.cs index 7d89a35e..657f28f3 100644 --- a/Assets/YooAsset/Runtime/BundleHandle/Services/RawBundleHandle/RawBundleHandle.cs +++ b/Assets/YooAsset/Runtime/BundleHandle/Services/RawBundleHandle/RawBundleHandle.cs @@ -7,25 +7,16 @@ namespace YooAsset /// internal sealed class RawBundleHandle : IBundleHandle { - private readonly string _bundleFilePath; private readonly PackageBundle _packageBundle; private readonly RawBundle _rawBundle; - /// - public string BundleFilePath - { - get { return _bundleFilePath; } - } - /// /// 创建 RawBundleHandle 实例 /// - /// 资源包文件的本地路径 /// 资源包描述 /// 已加载的原生资源包数据对象 - public RawBundleHandle(string bundleFilePath, PackageBundle packageBundle, RawBundle rawBundle) + public RawBundleHandle(PackageBundle packageBundle, RawBundle rawBundle) { - _bundleFilePath = bundleFilePath; _packageBundle = packageBundle; _rawBundle = rawBundle; } diff --git a/Assets/YooAsset/Runtime/BundleHandle/Services/VirtualAssetBundleHandle/VirtualAssetBundleHandle.cs b/Assets/YooAsset/Runtime/BundleHandle/Services/VirtualAssetBundleHandle/VirtualAssetBundleHandle.cs index 38913695..34cc29be 100644 --- a/Assets/YooAsset/Runtime/BundleHandle/Services/VirtualAssetBundleHandle/VirtualAssetBundleHandle.cs +++ b/Assets/YooAsset/Runtime/BundleHandle/Services/VirtualAssetBundleHandle/VirtualAssetBundleHandle.cs @@ -4,23 +4,14 @@ namespace YooAsset { internal sealed class VirtualAssetBundleHandle : IBundleHandle { - private readonly string _bundleFilePath; private readonly PackageBundle _packageBundle; - /// - public string BundleFilePath - { - get { return _bundleFilePath; } - } - /// /// 创建 VirtualAssetBundleHandle 实例 /// - /// 资源包文件的本地路径 /// 资源包描述 - public VirtualAssetBundleHandle(string bundleFilePath, PackageBundle packageBundle) + public VirtualAssetBundleHandle(PackageBundle packageBundle) { - _bundleFilePath = bundleFilePath; _packageBundle = packageBundle; } diff --git a/Assets/YooAsset/Runtime/BundleHandle/Services/VirtualRawBundleHandle/VirtualRawBundleHandle.cs b/Assets/YooAsset/Runtime/BundleHandle/Services/VirtualRawBundleHandle/VirtualRawBundleHandle.cs index 3048fabf..92352832 100644 --- a/Assets/YooAsset/Runtime/BundleHandle/Services/VirtualRawBundleHandle/VirtualRawBundleHandle.cs +++ b/Assets/YooAsset/Runtime/BundleHandle/Services/VirtualRawBundleHandle/VirtualRawBundleHandle.cs @@ -4,25 +4,16 @@ namespace YooAsset { internal sealed class VirtualRawBundleHandle : IBundleHandle { - private readonly string _bundleFilePath; private readonly PackageBundle _packageBundle; private readonly RawBundle _rawBundle; - /// - public string BundleFilePath - { - get { return _bundleFilePath; } - } - /// /// 创建 VirtualRawBundleHandle 实例 /// - /// 资源包文件的本地路径 /// 资源包描述 /// 已加载的原生资源包数据对象 - public VirtualRawBundleHandle(string bundleFilePath, PackageBundle packageBundle, RawBundle rawBundle) + public VirtualRawBundleHandle(PackageBundle packageBundle, RawBundle rawBundle) { - _bundleFilePath = bundleFilePath; _packageBundle = packageBundle; _rawBundle = rawBundle; } diff --git a/Assets/YooAsset/Runtime/BundleHandle/Services/WebGameBundleHandle/WebGameAssetBundleHandle.cs b/Assets/YooAsset/Runtime/BundleHandle/Services/WebGameBundleHandle/WebGameAssetBundleHandle.cs index d51dcc01..fa177d25 100644 --- a/Assets/YooAsset/Runtime/BundleHandle/Services/WebGameBundleHandle/WebGameAssetBundleHandle.cs +++ b/Assets/YooAsset/Runtime/BundleHandle/Services/WebGameBundleHandle/WebGameAssetBundleHandle.cs @@ -8,27 +8,18 @@ namespace YooAsset /// internal sealed class WebGameAssetBundleHandle : IBundleHandle { - private readonly string _bundleFilePath; private readonly PackageBundle _packageBundle; private readonly AssetBundle _assetBundle; private readonly IWebGamePlatform _platform; - /// - public string BundleFilePath - { - get { return _bundleFilePath; } - } - /// /// 创建 WebGameAssetBundleHandle 实例 /// - /// 资源包文件的本地路径 /// 资源包描述 /// 已加载的 AssetBundle 对象 /// 平台实现 - public WebGameAssetBundleHandle(string bundleFilePath, PackageBundle packageBundle, AssetBundle assetBundle, IWebGamePlatform platform) + public WebGameAssetBundleHandle(PackageBundle packageBundle, AssetBundle assetBundle, IWebGamePlatform platform) { - _bundleFilePath = bundleFilePath; _packageBundle = packageBundle; _assetBundle = assetBundle; _platform = platform; diff --git a/Assets/YooAsset/Runtime/Compatibility/CompatibleHandles.cs b/Assets/YooAsset/Runtime/Compatibility/CompatibleHandles.cs index ac85c9d3..9c2d29fd 100644 --- a/Assets/YooAsset/Runtime/Compatibility/CompatibleHandles.cs +++ b/Assets/YooAsset/Runtime/Compatibility/CompatibleHandles.cs @@ -94,27 +94,34 @@ namespace YooAsset } #endregion - #region BundleFileHandle -- GetRawFileData / GetRawFileText + #region BundleFileHandle -- GetBundleFilePath / GetRawFileData / GetRawFileText public sealed partial class BundleFileHandle { + /// + /// v2.3: rawFileHandle.GetRawFilePath() + /// + [Obsolete("Use EnsureBundleFileAsync() to get bundle file path via EnsureBundleFileOperation.Detail.BundleFilePath.")] + public string GetBundleFilePath() + { + throw new NotSupportedException("GetBundleFilePath() is no longer available. Use EnsureBundleFileAsync() to get bundle file path via EnsureBundleFileOperation.Detail.BundleFilePath."); + } + /// /// v2.3: rawFileHandle.GetRawFileData() /// - [Obsolete("Read file manually via GetBundleFilePath().")] + [Obsolete("Use LoadAssetAsync() to read binary data via RawFileObject.GetBytes().")] public byte[] GetRawFileData() { - if (CheckValidWithWarning() == false) return null; - return System.IO.File.ReadAllBytes(GetBundleFilePath()); + throw new NotSupportedException("GetRawFileData() is no longer available. Use LoadAssetAsync() to read binary data via RawFileObject.GetBytes()."); } /// /// v2.3: rawFileHandle.GetRawFileText() /// - [Obsolete("Read file manually via GetBundleFilePath().")] + [Obsolete("Use LoadAssetAsync() to read text data via RawFileObject.GetText().")] public string GetRawFileText() { - if (CheckValidWithWarning() == false) return null; - return System.IO.File.ReadAllText(GetBundleFilePath()); + throw new NotSupportedException("GetRawFileText() is no longer available. Use LoadAssetAsync() to read text data via RawFileObject.GetText()."); } } #endregion diff --git a/Assets/YooAsset/Runtime/FileSystem/Interfaces/IFileSystem.cs b/Assets/YooAsset/Runtime/FileSystem/Interfaces/IFileSystem.cs index 5ecd83c0..23f93b66 100644 --- a/Assets/YooAsset/Runtime/FileSystem/Interfaces/IFileSystem.cs +++ b/Assets/YooAsset/Runtime/FileSystem/Interfaces/IFileSystem.cs @@ -38,6 +38,13 @@ namespace YooAsset /// 加载资源包操作句柄 FSLoadPackageBundleOperation LoadPackageBundleAsync(FSLoadPackageBundleOptions options); + /// + /// 确保资源包文件已就绪 + /// + /// 确保资源包已就绪的选项参数 + /// 确保资源包已就绪的操作句柄 + FSEnsurePackageBundleOperation EnsurePackageBundleAsync(FSEnsurePackageBundleOptions options); + /// /// 下载资源包 /// diff --git a/Assets/YooAsset/Runtime/FileSystem/Operations/FSEnsurePackageBundleOperation.cs b/Assets/YooAsset/Runtime/FileSystem/Operations/FSEnsurePackageBundleOperation.cs new file mode 100644 index 00000000..6c15a1bb --- /dev/null +++ b/Assets/YooAsset/Runtime/FileSystem/Operations/FSEnsurePackageBundleOperation.cs @@ -0,0 +1,35 @@ + +namespace YooAsset +{ + /// + /// 确保资源包已就绪的操作基类 + /// + internal abstract class FSEnsurePackageBundleOperation : AsyncOperationBase + { + /// + /// 资源包文件的本地路径 + /// + public string BundleFilePath { get; protected set; } + } + + /// + /// 确保资源包已就绪的失败实现 + /// + internal sealed class FSEnsurePackageBundleFailureOperation : FSEnsurePackageBundleOperation + { + private readonly string _error; + + internal FSEnsurePackageBundleFailureOperation(string error) + { + _error = error; + } + + protected override void InternalStart() + { + SetError(_error); + } + protected override void InternalUpdate() + { + } + } +} diff --git a/Assets/YooAsset/Runtime/BundleCache/Services/WebGameBundleCache/WebGameBundleCacheEntry.cs.meta b/Assets/YooAsset/Runtime/FileSystem/Operations/FSEnsurePackageBundleOperation.cs.meta similarity index 83% rename from Assets/YooAsset/Runtime/BundleCache/Services/WebGameBundleCache/WebGameBundleCacheEntry.cs.meta rename to Assets/YooAsset/Runtime/FileSystem/Operations/FSEnsurePackageBundleOperation.cs.meta index 91177cd7..4ef2de7d 100644 --- a/Assets/YooAsset/Runtime/BundleCache/Services/WebGameBundleCache/WebGameBundleCacheEntry.cs.meta +++ b/Assets/YooAsset/Runtime/FileSystem/Operations/FSEnsurePackageBundleOperation.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: f11e7e5e45702bb459771f57e1b84fdc +guid: 104d90c1b2424984d86d037cc4672f41 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Assets/YooAsset/Runtime/FileSystem/Operations/FSEnsurePackageBundleOptions.cs b/Assets/YooAsset/Runtime/FileSystem/Operations/FSEnsurePackageBundleOptions.cs new file mode 100644 index 00000000..a6d8df4e --- /dev/null +++ b/Assets/YooAsset/Runtime/FileSystem/Operations/FSEnsurePackageBundleOptions.cs @@ -0,0 +1,19 @@ + +namespace YooAsset +{ + /// + /// 确保资源包已就绪的操作选项 + /// + internal readonly struct FSEnsurePackageBundleOptions + { + /// + /// 资源包描述 + /// + public PackageBundle Bundle { get; } + + public FSEnsurePackageBundleOptions(PackageBundle bundle) + { + Bundle = bundle; + } + } +} diff --git a/Assets/YooAsset/Runtime/BundleCache/Services/WebRemoteBundleCache/WebRemoteBundleCacheEntry.cs.meta b/Assets/YooAsset/Runtime/FileSystem/Operations/FSEnsurePackageBundleOptions.cs.meta similarity index 83% rename from Assets/YooAsset/Runtime/BundleCache/Services/WebRemoteBundleCache/WebRemoteBundleCacheEntry.cs.meta rename to Assets/YooAsset/Runtime/FileSystem/Operations/FSEnsurePackageBundleOptions.cs.meta index 21233e0c..390a37ce 100644 --- a/Assets/YooAsset/Runtime/BundleCache/Services/WebRemoteBundleCache/WebRemoteBundleCacheEntry.cs.meta +++ b/Assets/YooAsset/Runtime/FileSystem/Operations/FSEnsurePackageBundleOptions.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 2c5756c583ed1474c9abb56419b488d6 +guid: 27f8e387050567642b3ee6da777f3189 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Assets/YooAsset/Runtime/FileSystem/Services/BuiltinFileSystem/BuiltinFileSystem.cs b/Assets/YooAsset/Runtime/FileSystem/Services/BuiltinFileSystem/BuiltinFileSystem.cs index 7db8f80e..1deb8eff 100644 --- a/Assets/YooAsset/Runtime/FileSystem/Services/BuiltinFileSystem/BuiltinFileSystem.cs +++ b/Assets/YooAsset/Runtime/FileSystem/Services/BuiltinFileSystem/BuiltinFileSystem.cs @@ -175,6 +175,12 @@ namespace YooAsset return operation; } /// + public FSEnsurePackageBundleOperation EnsurePackageBundleAsync(FSEnsurePackageBundleOptions options) + { + var operation = new BFSEnsurePackageBundleOperation(this, options); + return operation; + } + /// public FSDownloadBundleOperation DownloadBundleAsync(FSDownloadBundleOptions options) { var operation = new BFSDownloadBundleOperation(this, options); diff --git a/Assets/YooAsset/Runtime/FileSystem/Services/BuiltinFileSystem/Operations/BFSEnsurePackageBundleOperation.cs b/Assets/YooAsset/Runtime/FileSystem/Services/BuiltinFileSystem/Operations/BFSEnsurePackageBundleOperation.cs new file mode 100644 index 00000000..ef418ae5 --- /dev/null +++ b/Assets/YooAsset/Runtime/FileSystem/Services/BuiltinFileSystem/Operations/BFSEnsurePackageBundleOperation.cs @@ -0,0 +1,105 @@ + +namespace YooAsset +{ + internal sealed class BFSEnsurePackageBundleOperation : FSEnsurePackageBundleOperation + { + private enum ESteps + { + None, + CheckUnpack, + UnpackFile, + CheckFilePath, + Done, + } + + private readonly BuiltinFileSystem _fileSystem; + private readonly FSEnsurePackageBundleOptions _options; + private FSDownloadBundleOperation _unpackFileOp; + private ESteps _steps = ESteps.None; + + internal BFSEnsurePackageBundleOperation(BuiltinFileSystem fileSystem, FSEnsurePackageBundleOptions options) + { + _fileSystem = fileSystem; + _options = options; + } + protected override void InternalStart() + { + _steps = ESteps.CheckUnpack; + } + protected override void InternalUpdate() + { + if (_steps == ESteps.None || _steps == ESteps.Done) + return; + + if (_steps == ESteps.CheckUnpack) + { + if (_fileSystem.IsUnpackBundleFile(_options.Bundle)) + { + if (_fileSystem.UnpackBundleCache.IsCached(_options.Bundle.BundleGuid)) + { + _steps = ESteps.CheckFilePath; + } + else + { + _steps = ESteps.UnpackFile; + } + } + else + { + BundleFilePath = _fileSystem.GetBuiltinBundleFilePath(_options.Bundle); + _steps = ESteps.Done; + SetResult(); + } + } + + if (_steps == ESteps.UnpackFile) + { + if (_unpackFileOp == null) + { + var options = new FSDownloadBundleOptions(_options.Bundle, 0); + _unpackFileOp = _fileSystem.DownloadBundleAsync(options); + _unpackFileOp.StartOperation(); + AddChildOperation(_unpackFileOp); + } + + if (IsWaitForCompletion) + _unpackFileOp.WaitForCompletion(); + + _unpackFileOp.UpdateOperation(); + Progress = _unpackFileOp.Progress; + if (_unpackFileOp.IsDone == false) + return; + + if (_unpackFileOp.Status == EOperationStatus.Succeeded) + { + _steps = ESteps.CheckFilePath; + } + else + { + _steps = ESteps.Done; + SetError(_unpackFileOp.Error); + } + } + + if (_steps == ESteps.CheckFilePath) + { + string filePath = _fileSystem.UnpackBundleCache.GetCacheFilePath(_options.Bundle.BundleGuid); + if (string.IsNullOrEmpty(filePath)) + { + _steps = ESteps.Done; + SetError($"Bundle '{_options.Bundle.BundleName}' cache file path not found."); + } + else + { + _steps = ESteps.Done; + BundleFilePath = filePath; + SetResult(); + } + } + } + protected override void InternalWaitForCompletion() + { + ExecuteBatch(); + } + } +} diff --git a/Assets/YooAsset/Runtime/FileSystem/Services/BuiltinFileSystem/Operations/BFSEnsurePackageBundleOperation.cs.meta b/Assets/YooAsset/Runtime/FileSystem/Services/BuiltinFileSystem/Operations/BFSEnsurePackageBundleOperation.cs.meta new file mode 100644 index 00000000..63bd4ac2 --- /dev/null +++ b/Assets/YooAsset/Runtime/FileSystem/Services/BuiltinFileSystem/Operations/BFSEnsurePackageBundleOperation.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 6ea859176a8a53342a78b5dbb0909da0 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/YooAsset/Runtime/FileSystem/Services/EditorFileSystem/EditorFileSystem.cs b/Assets/YooAsset/Runtime/FileSystem/Services/EditorFileSystem/EditorFileSystem.cs index 4272a9bd..3cc109cc 100644 --- a/Assets/YooAsset/Runtime/FileSystem/Services/EditorFileSystem/EditorFileSystem.cs +++ b/Assets/YooAsset/Runtime/FileSystem/Services/EditorFileSystem/EditorFileSystem.cs @@ -121,6 +121,12 @@ namespace YooAsset return operation; } /// + public FSEnsurePackageBundleOperation EnsurePackageBundleAsync(FSEnsurePackageBundleOptions options) + { + var operation = new EFSEnsurePackageBundleOperation(this, options); + return operation; + } + /// public FSDownloadBundleOperation DownloadBundleAsync(FSDownloadBundleOptions options) { var downloader = new EFSDownloadBundleOperation(this, options); diff --git a/Assets/YooAsset/Runtime/FileSystem/Services/EditorFileSystem/Operations/EFSEnsurePackageBundleOperation.cs b/Assets/YooAsset/Runtime/FileSystem/Services/EditorFileSystem/Operations/EFSEnsurePackageBundleOperation.cs new file mode 100644 index 00000000..e85049c7 --- /dev/null +++ b/Assets/YooAsset/Runtime/FileSystem/Services/EditorFileSystem/Operations/EFSEnsurePackageBundleOperation.cs @@ -0,0 +1,96 @@ + +namespace YooAsset +{ + internal sealed class EFSEnsurePackageBundleOperation : FSEnsurePackageBundleOperation + { + private enum ESteps + { + None, + CheckCache, + DownloadFile, + CheckFilePath, + Done, + } + + private readonly EditorFileSystem _fileSystem; + private readonly FSEnsurePackageBundleOptions _options; + private FSDownloadBundleOperation _downloadFileOp; + private ESteps _steps = ESteps.None; + + internal EFSEnsurePackageBundleOperation(EditorFileSystem fileSystem, FSEnsurePackageBundleOptions options) + { + _fileSystem = fileSystem; + _options = options; + } + protected override void InternalStart() + { + _steps = ESteps.CheckCache; + } + protected override void InternalUpdate() + { + if (_steps == ESteps.None || _steps == ESteps.Done) + return; + + if (_steps == ESteps.CheckCache) + { + if (_fileSystem.BundleCache.IsCached(_options.Bundle.BundleGuid)) + { + _steps = ESteps.CheckFilePath; + } + else + { + _steps = ESteps.DownloadFile; + } + } + + if (_steps == ESteps.DownloadFile) + { + if (_downloadFileOp == null) + { + var options = new FSDownloadBundleOptions(_options.Bundle, 0); + _downloadFileOp = _fileSystem.DownloadBundleAsync(options); + _downloadFileOp.StartOperation(); + AddChildOperation(_downloadFileOp); + } + + if (IsWaitForCompletion) + _downloadFileOp.WaitForCompletion(); + + _downloadFileOp.UpdateOperation(); + Progress = _downloadFileOp.Progress; + if (_downloadFileOp.IsDone == false) + return; + + if (_downloadFileOp.Status == EOperationStatus.Succeeded) + { + _steps = ESteps.CheckFilePath; + } + else + { + _steps = ESteps.Done; + SetError(_downloadFileOp.Error); + } + } + + if (_steps == ESteps.CheckFilePath) + { + string filePath = EditorFileSystemHelper.GetEditorFilePath(_options.Bundle); + if (string.IsNullOrEmpty(filePath)) + { + _steps = ESteps.Done; + SetError($"Editor file path is empty for bundle '{_options.Bundle.BundleName}'."); + } + else + { + _steps = ESteps.Done; + BundleFilePath = filePath; + SetResult(); + } + } + } + protected override void InternalWaitForCompletion() + { + ExecuteBatch(); + } + } +} diff --git a/Assets/YooAsset/Runtime/FileSystem/Services/EditorFileSystem/Operations/EFSEnsurePackageBundleOperation.cs.meta b/Assets/YooAsset/Runtime/FileSystem/Services/EditorFileSystem/Operations/EFSEnsurePackageBundleOperation.cs.meta new file mode 100644 index 00000000..13d8d608 --- /dev/null +++ b/Assets/YooAsset/Runtime/FileSystem/Services/EditorFileSystem/Operations/EFSEnsurePackageBundleOperation.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 44426c6bae3a47e43be1a57e455bf520 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/Operations/SFSEnsurePackageBundleOperation.cs b/Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/Operations/SFSEnsurePackageBundleOperation.cs new file mode 100644 index 00000000..cad667ad --- /dev/null +++ b/Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/Operations/SFSEnsurePackageBundleOperation.cs @@ -0,0 +1,96 @@ + +namespace YooAsset +{ + internal sealed class SFSEnsurePackageBundleOperation : FSEnsurePackageBundleOperation + { + private enum ESteps + { + None, + CheckCache, + DownloadFile, + CheckFilePath, + Done, + } + + private readonly SandboxFileSystem _fileSystem; + private readonly FSEnsurePackageBundleOptions _options; + private FSDownloadBundleOperation _downloadFileOp; + private ESteps _steps = ESteps.None; + + internal SFSEnsurePackageBundleOperation(SandboxFileSystem fileSystem, FSEnsurePackageBundleOptions options) + { + _fileSystem = fileSystem; + _options = options; + } + protected override void InternalStart() + { + _steps = ESteps.CheckCache; + } + protected override void InternalUpdate() + { + if (_steps == ESteps.None || _steps == ESteps.Done) + return; + + if (_steps == ESteps.CheckCache) + { + if (_fileSystem.BundleCache.IsCached(_options.Bundle.BundleGuid)) + { + _steps = ESteps.CheckFilePath; + } + else + { + _steps = ESteps.DownloadFile; + } + } + + if (_steps == ESteps.DownloadFile) + { + if (_downloadFileOp == null) + { + var options = new FSDownloadBundleOptions(_options.Bundle, int.MaxValue); + _downloadFileOp = _fileSystem.DownloadBundleAsync(options); + _downloadFileOp.StartOperation(); + AddChildOperation(_downloadFileOp); + } + + if (IsWaitForCompletion) + _downloadFileOp.WaitForCompletion(); + + _downloadFileOp.UpdateOperation(); + Progress = _downloadFileOp.Progress; + if (_downloadFileOp.IsDone == false) + return; + + if (_downloadFileOp.Status == EOperationStatus.Succeeded) + { + _steps = ESteps.CheckFilePath; + } + else + { + _steps = ESteps.Done; + SetError(_downloadFileOp.Error); + } + } + + if (_steps == ESteps.CheckFilePath) + { + string filePath = _fileSystem.BundleCache.GetCacheFilePath(_options.Bundle.BundleGuid); + if (string.IsNullOrEmpty(filePath)) + { + _steps = ESteps.Done; + SetError($"Bundle '{_options.Bundle.BundleName}' cache file path not found."); + } + else + { + _steps = ESteps.Done; + BundleFilePath = filePath; + SetResult(); + } + } + } + protected override void InternalWaitForCompletion() + { + ExecuteBatch(); + } + } +} diff --git a/Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/Operations/SFSEnsurePackageBundleOperation.cs.meta b/Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/Operations/SFSEnsurePackageBundleOperation.cs.meta new file mode 100644 index 00000000..f965f56c --- /dev/null +++ b/Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/Operations/SFSEnsurePackageBundleOperation.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 3df0f518860ad9042aefab0cc18bc630 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/SandboxFileSystem.cs b/Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/SandboxFileSystem.cs index 7fc1a9b4..554bbba8 100644 --- a/Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/SandboxFileSystem.cs +++ b/Assets/YooAsset/Runtime/FileSystem/Services/SandboxFileSystem/SandboxFileSystem.cs @@ -177,6 +177,12 @@ namespace YooAsset return operation; } /// + public FSEnsurePackageBundleOperation EnsurePackageBundleAsync(FSEnsurePackageBundleOptions options) + { + var operation = new SFSEnsurePackageBundleOperation(this, options); + return operation; + } + /// public FSDownloadBundleOperation DownloadBundleAsync(FSDownloadBundleOptions options) { var downloader = new SFSDownloadBundleOperation(this, options); diff --git a/Assets/YooAsset/Runtime/FileSystem/Services/WebGameFileSystem/WebGameFileSystem.cs b/Assets/YooAsset/Runtime/FileSystem/Services/WebGameFileSystem/WebGameFileSystem.cs index 0002f891..381b87b7 100644 --- a/Assets/YooAsset/Runtime/FileSystem/Services/WebGameFileSystem/WebGameFileSystem.cs +++ b/Assets/YooAsset/Runtime/FileSystem/Services/WebGameFileSystem/WebGameFileSystem.cs @@ -96,6 +96,12 @@ namespace YooAsset return operation; } /// + public virtual FSEnsurePackageBundleOperation EnsurePackageBundleAsync(FSEnsurePackageBundleOptions options) + { + var operation = new FSEnsurePackageBundleFailureOperation($"{nameof(WebGameFileSystem)} does not support ensure bundle file operation."); + return operation; + } + /// public virtual FSDownloadBundleOperation DownloadBundleAsync(FSDownloadBundleOptions options) { var operation = new FSDownloadBundleCompleteOperation($"{nameof(WebGameFileSystem)} does not support download operation."); diff --git a/Assets/YooAsset/Runtime/FileSystem/Services/WebRemoteFileSystem/WebRemoteFileSystem.cs b/Assets/YooAsset/Runtime/FileSystem/Services/WebRemoteFileSystem/WebRemoteFileSystem.cs index 706fe6ab..1193c77b 100644 --- a/Assets/YooAsset/Runtime/FileSystem/Services/WebRemoteFileSystem/WebRemoteFileSystem.cs +++ b/Assets/YooAsset/Runtime/FileSystem/Services/WebRemoteFileSystem/WebRemoteFileSystem.cs @@ -102,6 +102,12 @@ namespace YooAsset return operation; } /// + public FSEnsurePackageBundleOperation EnsurePackageBundleAsync(FSEnsurePackageBundleOptions options) + { + var operation = new FSEnsurePackageBundleFailureOperation($"{nameof(WebRemoteFileSystem)} does not support ensure bundle file operation."); + return operation; + } + /// public FSDownloadBundleOperation DownloadBundleAsync(FSDownloadBundleOptions options) { var operation = new FSDownloadBundleCompleteOperation($"{nameof(WebRemoteFileSystem)} does not support download operation."); diff --git a/Assets/YooAsset/Runtime/FileSystem/Services/WebServerFileSystem/WebServerFileSystem.cs b/Assets/YooAsset/Runtime/FileSystem/Services/WebServerFileSystem/WebServerFileSystem.cs index 88237fb7..8367e408 100644 --- a/Assets/YooAsset/Runtime/FileSystem/Services/WebServerFileSystem/WebServerFileSystem.cs +++ b/Assets/YooAsset/Runtime/FileSystem/Services/WebServerFileSystem/WebServerFileSystem.cs @@ -108,6 +108,12 @@ namespace YooAsset return operation; } /// + public FSEnsurePackageBundleOperation EnsurePackageBundleAsync(FSEnsurePackageBundleOptions options) + { + var operation = new FSEnsurePackageBundleFailureOperation($"{nameof(WebServerFileSystem)} does not support ensure bundle file operation."); + return operation; + } + /// public FSDownloadBundleOperation DownloadBundleAsync(FSDownloadBundleOptions options) { var operation = new FSDownloadBundleCompleteOperation($"{nameof(WebServerFileSystem)} does not support download operation."); diff --git a/Assets/YooAsset/Runtime/ResourceManager/Handles/BundleFileHandle.cs b/Assets/YooAsset/Runtime/ResourceManager/Handles/BundleFileHandle.cs index 00e759f8..6a820dee 100644 --- a/Assets/YooAsset/Runtime/ResourceManager/Handles/BundleFileHandle.cs +++ b/Assets/YooAsset/Runtime/ResourceManager/Handles/BundleFileHandle.cs @@ -47,16 +47,5 @@ namespace YooAsset return; Provider.WaitForCompletion(); } - - /// - /// 获取资源包文件的路径 - /// - /// 资源包文件的磁盘路径 - public string GetBundleFilePath() - { - if (CheckValidWithWarning() == false) - return string.Empty; - return Provider.LoadedBundleHandle.BundleFilePath; - } } } \ No newline at end of file diff --git a/Assets/YooAsset/Runtime/ResourcePackage/BundleInfo.cs b/Assets/YooAsset/Runtime/ResourcePackage/BundleInfo.cs index 79179ea0..5a12fbd8 100644 --- a/Assets/YooAsset/Runtime/ResourcePackage/BundleInfo.cs +++ b/Assets/YooAsset/Runtime/ResourcePackage/BundleInfo.cs @@ -50,6 +50,16 @@ namespace YooAsset return _fileSystem.LoadPackageBundleAsync(options); } + /// + /// 创建资源包文件确保器 + /// + /// 返回确保资源包文件就绪的操作对象 + public FSEnsurePackageBundleOperation CreateBundleEnsurer() + { + var options = new FSEnsurePackageBundleOptions(Bundle); + return _fileSystem.EnsurePackageBundleAsync(options); + } + /// /// 创建资源包下载器 /// diff --git a/Assets/YooAsset/Runtime/ResourcePackage/Operations/EnsureBundleFileOperation.cs b/Assets/YooAsset/Runtime/ResourcePackage/Operations/EnsureBundleFileOperation.cs new file mode 100644 index 00000000..3ac7646d --- /dev/null +++ b/Assets/YooAsset/Runtime/ResourcePackage/Operations/EnsureBundleFileOperation.cs @@ -0,0 +1,132 @@ + +namespace YooAsset +{ + /// + /// 确保资源包已就绪的异步操作 + /// + public sealed class EnsureBundleFileOperation : AsyncOperationBase + { + /// + /// 资源包文件详情 + /// + public readonly struct BundleDetail + { + /// + /// 资源包名称 + /// + public readonly string BundleName; + + /// + /// 资源包文件的本地路径 + /// + public readonly string BundleFilePath; + + /// + /// 资源包类型 + /// + public readonly int BundleType; + + /// + /// 文件是否加密 + /// + public readonly bool IsEncrypted; + + internal BundleDetail(string bundleName, string bundleFilePath, int bundleType, bool isEncrypted) + { + BundleName = bundleName; + BundleFilePath = bundleFilePath; + BundleType = bundleType; + IsEncrypted = isEncrypted; + } + } + + private enum ESteps + { + None, + Validate, + EnsureFile, + Done, + } + + private readonly FileSystemHost _host; + private readonly EnsureBundleFileOptions _options; + private FSEnsurePackageBundleOperation _ensurePackageBundleOp; + private BundleInfo _bundleInfo; + private ESteps _steps = ESteps.None; + + /// + /// 资源包文件详情 + /// + public BundleDetail Detail { get; private set; } + + + internal EnsureBundleFileOperation(FileSystemHost host, EnsureBundleFileOptions options) + { + _host = host; + _options = options; + } + protected override void InternalStart() + { + _steps = ESteps.Validate; + } + protected override void InternalUpdate() + { + if (_steps == ESteps.None || _steps == ESteps.Done) + return; + + if (_steps == ESteps.Validate) + { + AssetInfo assetInfo = _options.AssetInfo; + if (assetInfo == null) + { + _steps = ESteps.Done; + SetError("Failed to ensure bundle file. Error: AssetInfo is null."); + return; + } + + if (assetInfo.IsValid == false) + { + _steps = ESteps.Done; + SetError($"Failed to ensure bundle file. Error: {assetInfo.Error}"); + return; + } + + _steps = ESteps.EnsureFile; + } + + if (_steps == ESteps.EnsureFile) + { + if (_ensurePackageBundleOp == null) + { + _bundleInfo = _host.GetMainBundleInfo(_options.AssetInfo); + _ensurePackageBundleOp = _bundleInfo.CreateBundleEnsurer(); + _ensurePackageBundleOp.StartOperation(); + AddChildOperation(_ensurePackageBundleOp); + } + + _ensurePackageBundleOp.UpdateOperation(); + Progress = _ensurePackageBundleOp.Progress; + if (_ensurePackageBundleOp.IsDone == false) + return; + + if (_ensurePackageBundleOp.Status == EOperationStatus.Succeeded) + { + var bundle = _bundleInfo.Bundle; + Detail = new BundleDetail( + bundleName: bundle.BundleName, + bundleFilePath: _ensurePackageBundleOp.BundleFilePath, + bundleType: bundle.GetBundleType(), + isEncrypted: bundle.IsEncrypted); + + _steps = ESteps.Done; + SetResult(); + } + else + { + _steps = ESteps.Done; + SetError(_ensurePackageBundleOp.Error); + } + } + } + } +} diff --git a/Assets/YooAsset/Runtime/ResourcePackage/Operations/EnsureBundleFileOperation.cs.meta b/Assets/YooAsset/Runtime/ResourcePackage/Operations/EnsureBundleFileOperation.cs.meta new file mode 100644 index 00000000..5e520b3c --- /dev/null +++ b/Assets/YooAsset/Runtime/ResourcePackage/Operations/EnsureBundleFileOperation.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: f96dcb07877ab7d4eaff7d2f9f171ecd +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/YooAsset/Runtime/ResourcePackage/Operations/EnsureBundleFileOptions.cs b/Assets/YooAsset/Runtime/ResourcePackage/Operations/EnsureBundleFileOptions.cs new file mode 100644 index 00000000..a578094a --- /dev/null +++ b/Assets/YooAsset/Runtime/ResourcePackage/Operations/EnsureBundleFileOptions.cs @@ -0,0 +1,39 @@ + +namespace YooAsset +{ + /// + /// 确保资源包文件已就绪的选项 + /// + public readonly struct EnsureBundleFileOptions + { + /// + /// 资源定位地址 + /// + public string Location { get; } + + /// + /// 资源信息 + /// + public AssetInfo AssetInfo { get; } + + /// + /// 创建确保资源包文件已就绪的选项实例 + /// + /// 资源定位地址 + public EnsureBundleFileOptions(string location) + { + Location = location; + AssetInfo = null; + } + + /// + /// 创建确保资源包文件已就绪的选项实例 + /// + /// 资源信息 + public EnsureBundleFileOptions(AssetInfo assetInfo) + { + Location = null; + AssetInfo = assetInfo; + } + } +} diff --git a/Assets/YooAsset/Runtime/ResourcePackage/Operations/EnsureBundleFileOptions.cs.meta b/Assets/YooAsset/Runtime/ResourcePackage/Operations/EnsureBundleFileOptions.cs.meta new file mode 100644 index 00000000..64eab19e --- /dev/null +++ b/Assets/YooAsset/Runtime/ResourcePackage/Operations/EnsureBundleFileOptions.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 8a62e7d7a33c4d34a9c3b4d59a3b0a2f +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/YooAsset/Runtime/ResourcePackage/ResourcePackage.cs b/Assets/YooAsset/Runtime/ResourcePackage/ResourcePackage.cs index 48a5e637..192d3c25 100644 --- a/Assets/YooAsset/Runtime/ResourcePackage/ResourcePackage.cs +++ b/Assets/YooAsset/Runtime/ResourcePackage/ResourcePackage.cs @@ -419,66 +419,6 @@ namespace YooAsset } #endregion - #region 资源包文件 - /// - /// 同步加载资源包文件 - /// - /// 资源信息 - /// 返回资源包文件操作句柄 - public BundleFileHandle LoadBundleFileSync(AssetInfo assetInfo) - { - CheckInitialized(); - return LoadBundleFileInternal(assetInfo, true, 0); - } - - /// - /// 同步加载资源包文件 - /// - /// 资源的定位地址 - /// 返回资源包文件操作句柄 - public BundleFileHandle LoadBundleFileSync(string location) - { - CheckInitialized(); - AssetInfo assetInfo = ConvertLocationToAssetInfo(location, null); - return LoadBundleFileInternal(assetInfo, true, 0); - } - - /// - /// 异步加载资源包文件 - /// - /// 资源信息 - /// 加载的优先级 - /// 返回资源包文件操作句柄 - public BundleFileHandle LoadBundleFileAsync(AssetInfo assetInfo, uint priority = 0) - { - CheckInitialized(); - return LoadBundleFileInternal(assetInfo, false, priority); - } - - /// - /// 异步加载资源包文件 - /// - /// 资源的定位地址 - /// 加载的优先级 - /// 返回资源包文件操作句柄 - public BundleFileHandle LoadBundleFileAsync(string location, uint priority = 0) - { - CheckInitialized(); - AssetInfo assetInfo = ConvertLocationToAssetInfo(location, null); - return LoadBundleFileInternal(assetInfo, false, priority); - } - - - private BundleFileHandle LoadBundleFileInternal(AssetInfo assetInfo, bool waitForAsyncComplete, uint priority) - { - assetInfo.LoadMethod = ELoadMethod.LoadBundleFile; - var handle = _resourceManager.LoadBundleFileAsync(assetInfo, priority); - if (waitForAsyncComplete) - handle.WaitForAsyncComplete(); - return handle; - } - #endregion - #region 场景加载 /// /// 同步加载场景 @@ -898,6 +838,84 @@ namespace YooAsset } #endregion + #region 资源包文件 + /// + /// 确保资源包文件已就绪 + /// + /// 确保资源包文件已就绪的选项 + /// 返回确保资源包文件就绪的操作对象 + public EnsureBundleFileOperation EnsureBundleFileAsync(EnsureBundleFileOptions options) + { + CheckInitialized(); + if (options.AssetInfo == null) + { + AssetInfo assetInfo = ConvertLocationToAssetInfo(options.Location, null); + options = new EnsureBundleFileOptions(assetInfo); + } + + var operation = new EnsureBundleFileOperation(_fileSystemHost, options); + AsyncOperationSystem.StartOperation(PackageName, operation); + return operation; + } + + /// + /// 同步加载资源包文件 + /// + /// 资源信息 + /// 返回资源包文件操作句柄 + public BundleFileHandle LoadBundleFileSync(AssetInfo assetInfo) + { + CheckInitialized(); + return LoadBundleFileInternal(assetInfo, true, 0); + } + + /// + /// 同步加载资源包文件 + /// + /// 资源的定位地址 + /// 返回资源包文件操作句柄 + public BundleFileHandle LoadBundleFileSync(string location) + { + CheckInitialized(); + AssetInfo assetInfo = ConvertLocationToAssetInfo(location, null); + return LoadBundleFileInternal(assetInfo, true, 0); + } + + /// + /// 异步加载资源包文件 + /// + /// 资源信息 + /// 加载的优先级 + /// 返回资源包文件操作句柄 + public BundleFileHandle LoadBundleFileAsync(AssetInfo assetInfo, uint priority = 0) + { + CheckInitialized(); + return LoadBundleFileInternal(assetInfo, false, priority); + } + + /// + /// 异步加载资源包文件 + /// + /// 资源的定位地址 + /// 加载的优先级 + /// 返回资源包文件操作句柄 + public BundleFileHandle LoadBundleFileAsync(string location, uint priority = 0) + { + CheckInitialized(); + AssetInfo assetInfo = ConvertLocationToAssetInfo(location, null); + return LoadBundleFileInternal(assetInfo, false, priority); + } + + private BundleFileHandle LoadBundleFileInternal(AssetInfo assetInfo, bool waitForAsyncComplete, uint priority) + { + assetInfo.LoadMethod = ELoadMethod.LoadBundleFile; + var handle = _resourceManager.LoadBundleFileAsync(assetInfo, priority); + if (waitForAsyncComplete) + handle.WaitForAsyncComplete(); + return handle; + } + #endregion + #region 资源下载 /// /// 创建资源下载器,用于下载指定的资源标签关联的资源包文件。 diff --git a/Assets/YooAsset/Samples~/Test Sample/Runtime/CommonTests/TestBundleFileRelease.cs b/Assets/YooAsset/Samples~/Test Sample/Runtime/CommonTests/TestBundleFileRelease.cs index a836e388..575bb983 100644 --- a/Assets/YooAsset/Samples~/Test Sample/Runtime/CommonTests/TestBundleFileRelease.cs +++ b/Assets/YooAsset/Samples~/Test Sample/Runtime/CommonTests/TestBundleFileRelease.cs @@ -14,7 +14,7 @@ using YooAsset; /// 1. 异步加载 Bundle 文件,验证加载成功 /// 2. 释放 BundleFileHandle 引用,等待一帧 /// 3. 调用 UnloadUnusedAssetsAsync 清理未使用资源 -/// 4. 再次加载同一 Bundle 文件,验证加载成功且文件路径有效 +/// 4. 再次加载同一 Bundle 文件,验证加载成功 /// public class TestBundleFileRelease { @@ -39,7 +39,6 @@ public class TestBundleFileRelease var reloadHandle = package.LoadBundleFileAsync("raw_file_e"); yield return reloadHandle; Assert.AreEqual(EOperationStatus.Succeeded, reloadHandle.Status); - Assert.IsTrue(File.Exists(reloadHandle.GetBundleFilePath())); reloadHandle.Release(); } } diff --git a/Assets/YooAsset/Samples~/Test Sample/Runtime/CommonTests/TestEnsureBundleFile.cs b/Assets/YooAsset/Samples~/Test Sample/Runtime/CommonTests/TestEnsureBundleFile.cs new file mode 100644 index 00000000..1facb514 --- /dev/null +++ b/Assets/YooAsset/Samples~/Test Sample/Runtime/CommonTests/TestEnsureBundleFile.cs @@ -0,0 +1,75 @@ +using System.IO; +using System.Collections; +using UnityEngine.TestTools; +using NUnit.Framework; +using YooAsset; + +/// +/// 测试确保资源包已就绪 +/// +/// +/// 覆盖 API: EnsureBundleFileAsync +/// 测试内容: +/// 1. RawBundle 包裹:异步确保资源包已就绪,验证文件路径有效(raw_file_a) +/// 2. AssetBundle 包裹:异步确保资源包已就绪,验证文件路径有效(prefab_a) +/// 3. ArchiveBundle 包裹:异步确保资源包已就绪,验证文件路径有效(archive_file_a) +/// +public class TestEnsureBundleFile +{ + public IEnumerator RuntimeTester_RawBundle() + { + ResourcePackage package = YooAssets.GetPackage(TestConsts.RawBundlePackageName); + Assert.IsNotNull(package); + + { + var ensureOp = package.EnsureBundleFileAsync(new EnsureBundleFileOptions("raw_file_a")); + yield return ensureOp; + Assert.AreEqual(EOperationStatus.Succeeded, ensureOp.Status); + + var detail = ensureOp.Detail; + Assert.IsNotNull(detail.BundleFilePath); + Assert.IsNotEmpty(detail.BundleFilePath); + Assert.IsTrue(File.Exists(detail.BundleFilePath), $"Bundle file does not exist: {detail.BundleFilePath}"); + Assert.IsNotNull(detail.BundleName); + Assert.IsNotEmpty(detail.BundleName); + } + } + + public IEnumerator RuntimeTester_AssetBundle() + { + ResourcePackage package = YooAssets.GetPackage(TestConsts.AssetBundlePackageName); + Assert.IsNotNull(package); + + { + var ensureOp = package.EnsureBundleFileAsync(new EnsureBundleFileOptions("prefab_a")); + yield return ensureOp; + Assert.AreEqual(EOperationStatus.Succeeded, ensureOp.Status); + + var detail = ensureOp.Detail; + Assert.IsNotNull(detail.BundleFilePath); + Assert.IsNotEmpty(detail.BundleFilePath); + Assert.IsTrue(File.Exists(detail.BundleFilePath), $"Bundle file does not exist: {detail.BundleFilePath}"); + Assert.IsNotNull(detail.BundleName); + Assert.IsNotEmpty(detail.BundleName); + } + } + + public IEnumerator RuntimeTester_ArchiveBundle() + { + ResourcePackage package = YooAssets.GetPackage(TestConsts.ArchiveBundlePackageName); + Assert.IsNotNull(package); + + { + var ensureOp = package.EnsureBundleFileAsync(new EnsureBundleFileOptions("archive_file_a")); + yield return ensureOp; + Assert.AreEqual(EOperationStatus.Succeeded, ensureOp.Status); + + var detail = ensureOp.Detail; + Assert.IsNotNull(detail.BundleFilePath); + Assert.IsNotEmpty(detail.BundleFilePath); + Assert.IsTrue(File.Exists(detail.BundleFilePath), $"Bundle file does not exist: {detail.BundleFilePath}"); + Assert.IsNotNull(detail.BundleName); + Assert.IsNotEmpty(detail.BundleName); + } + } +} diff --git a/Assets/YooAsset/Samples~/Test Sample/Runtime/CommonTests/TestEnsureBundleFile.cs.meta b/Assets/YooAsset/Samples~/Test Sample/Runtime/CommonTests/TestEnsureBundleFile.cs.meta new file mode 100644 index 00000000..2f6d77ef --- /dev/null +++ b/Assets/YooAsset/Samples~/Test Sample/Runtime/CommonTests/TestEnsureBundleFile.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 7c4cd191337037a4da1cc228d1d871fc +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/YooAsset/Samples~/Test Sample/Runtime/CommonTests/TestLoadArchiveBundle.cs b/Assets/YooAsset/Samples~/Test Sample/Runtime/CommonTests/TestLoadArchiveBundle.cs index 1d4de9e1..cabe9317 100644 --- a/Assets/YooAsset/Samples~/Test Sample/Runtime/CommonTests/TestLoadArchiveBundle.cs +++ b/Assets/YooAsset/Samples~/Test Sample/Runtime/CommonTests/TestLoadArchiveBundle.cs @@ -10,10 +10,10 @@ using YooAsset; /// /// 覆盖 API: LoadAssetAsync(RawFileObject) / LoadAssetSync(RawFileObject) / UnloadUnusedAssetsAsync /// 测试内容: -/// 1. 异步加载归档子文件,验证 GetBytes() 和 GetText() 均返回有效数据(raw_file_a) -/// 2. 同步加载归档子文件,验证 GetBytes() 和 GetText() 均返回有效数据(raw_file_b) -/// 3. 重复加载同一归档子文件,验证缓存命中不会失败(raw_file_c) -/// 4. 释放句柄并卸载后重新加载,验证卸载保护和重载链路正常(raw_file_e) +/// 1. 异步加载归档子文件,验证 GetBytes() 和 GetText() 均返回有效数据(archive_file_a) +/// 2. 同步加载归档子文件,验证 GetBytes() 和 GetText() 均返回有效数据(archive_file_b) +/// 3. 重复加载同一归档子文件,验证缓存命中不会失败(archive_file_c) +/// 4. 释放句柄并卸载后重新加载,验证卸载保护和重载链路正常(archive_file_e) /// public class TestLoadArchiveBundle { @@ -24,7 +24,7 @@ public class TestLoadArchiveBundle // 异步加载归档子文件 { - var assetHandle = package.LoadAssetAsync("raw_file_a"); + var assetHandle = package.LoadAssetAsync("archive_file_a"); yield return assetHandle; Assert.AreEqual(EOperationStatus.Succeeded, assetHandle.Status); @@ -43,7 +43,7 @@ public class TestLoadArchiveBundle // 同步加载归档子文件 { - var assetHandle = package.LoadAssetSync("raw_file_b"); + var assetHandle = package.LoadAssetSync("archive_file_b"); Assert.AreEqual(EOperationStatus.Succeeded, assetHandle.Status); var rawFileObject = assetHandle.GetAssetObject(); @@ -61,11 +61,11 @@ public class TestLoadArchiveBundle // 重复加载同一归档子文件,验证缓存命中 { - var handle1 = package.LoadAssetAsync("raw_file_c"); + var handle1 = package.LoadAssetAsync("archive_file_c"); yield return handle1; Assert.AreEqual(EOperationStatus.Succeeded, handle1.Status); - var handle2 = package.LoadAssetAsync("raw_file_c"); + var handle2 = package.LoadAssetAsync("archive_file_c"); yield return handle2; Assert.AreEqual(EOperationStatus.Succeeded, handle2.Status); @@ -80,7 +80,7 @@ public class TestLoadArchiveBundle // 释放后卸载再重新加载,验证新旧对象不是同一实例 { - var assetHandle = package.LoadAssetAsync("raw_file_e"); + var assetHandle = package.LoadAssetAsync("archive_file_e"); yield return assetHandle; Assert.AreEqual(EOperationStatus.Succeeded, assetHandle.Status); @@ -93,7 +93,7 @@ public class TestLoadArchiveBundle yield return unloadOp; Assert.AreEqual(EOperationStatus.Succeeded, unloadOp.Status); - var reloadHandle = package.LoadAssetAsync("raw_file_e"); + var reloadHandle = package.LoadAssetAsync("archive_file_e"); yield return reloadHandle; Assert.AreEqual(EOperationStatus.Succeeded, reloadHandle.Status); diff --git a/Assets/YooAsset/Samples~/Test Sample/Runtime/CommonTests/TestLoadBundleFile.cs b/Assets/YooAsset/Samples~/Test Sample/Runtime/CommonTests/TestLoadBundleFile.cs index bb779daf..6db485fd 100644 --- a/Assets/YooAsset/Samples~/Test Sample/Runtime/CommonTests/TestLoadBundleFile.cs +++ b/Assets/YooAsset/Samples~/Test Sample/Runtime/CommonTests/TestLoadBundleFile.cs @@ -12,8 +12,8 @@ using YooAsset; /// /// 覆盖 API: LoadBundleFileAsync / LoadBundleFileSync / LoadAssetAsync(RawFileObject) / LoadAssetSync(RawFileObject) /// 测试内容: -/// 1. 异步加载 Bundle 文件,获取文件路径,验证文件存在且二进制数据非空(raw_file_a) -/// 2. 同步加载 Bundle 文件,获取文件路径,验证文件存在且二进制数据非空(raw_file_b) +/// 1. 异步加载 Bundle 文件(raw_file_a) +/// 2. 同步加载 Bundle 文件(raw_file_b) /// 3. 异步通过 RawFileObject 加载,验证 GetBytes() 和 GetText() 均返回有效数据(raw_file_c) /// 4. 同步通过 RawFileObject 加载,验证 GetBytes() 和 GetText() 均返回有效数据(raw_file_d) /// @@ -29,14 +29,6 @@ public class TestLoadBundleFile var bundleFileHandle = package.LoadBundleFileAsync("raw_file_a"); yield return bundleFileHandle; Assert.AreEqual(EOperationStatus.Succeeded, bundleFileHandle.Status); - - var filePath = bundleFileHandle.GetBundleFilePath(); - Assert.IsNotNull(filePath); - Assert.IsTrue(File.Exists(filePath)); - - byte[] fileBytes = File.ReadAllBytes(filePath); - Assert.IsNotNull(fileBytes); - Assert.Greater(fileBytes.Length, 0); bundleFileHandle.Release(); } @@ -44,14 +36,6 @@ public class TestLoadBundleFile { var bundleFileHandle = package.LoadBundleFileSync("raw_file_b"); Assert.AreEqual(EOperationStatus.Succeeded, bundleFileHandle.Status); - - var filePath = bundleFileHandle.GetBundleFilePath(); - Assert.IsNotNull(filePath); - Assert.IsTrue(File.Exists(filePath)); - - byte[] fileBytes = File.ReadAllBytes(filePath); - Assert.IsNotNull(fileBytes); - Assert.Greater(fileBytes.Length, 0); bundleFileHandle.Release(); } diff --git a/Assets/YooAsset/Samples~/Test Sample/Runtime/T0_InitYooAssets/T0_InitYooAssets.cs b/Assets/YooAsset/Samples~/Test Sample/Runtime/T0_InitYooAssets/T0_InitYooAssets.cs index a7b64149..543a2cb0 100644 --- a/Assets/YooAsset/Samples~/Test Sample/Runtime/T0_InitYooAssets/T0_InitYooAssets.cs +++ b/Assets/YooAsset/Samples~/Test Sample/Runtime/T0_InitYooAssets/T0_InitYooAssets.cs @@ -247,7 +247,7 @@ public class T0_InitYooAssets : IPrebuildSetup, IPostBuildCleanup { var collector1 = new YooAsset.Editor.BundleCollector(); collector1.CollectPath = ""; - collector1.CollectorGUID = "fddaaf9430e24344196cc82ac3d006b4"; //TestRes/RawFiles目录 + collector1.CollectorGUID = "c0444018376a7cd4ead6a671035617d6"; //TestRes/ArchiveFiles目录 collector1.CollectorType = YooAsset.Editor.ECollectorType.MainAssetCollector; collector1.PackRuleName = nameof(YooAsset.Editor.PackCollector); YooAsset.Editor.BundleCollectorSettingData.CreateCollector(archiveFileGroup, collector1); diff --git a/Assets/YooAsset/Samples~/Test Sample/Runtime/T1_TestEditorFileSystem/T1_TestEditorFileSystem.cs b/Assets/YooAsset/Samples~/Test Sample/Runtime/T1_TestEditorFileSystem/T1_TestEditorFileSystem.cs index b1bc4257..f1dbbcb9 100644 --- a/Assets/YooAsset/Samples~/Test Sample/Runtime/T1_TestEditorFileSystem/T1_TestEditorFileSystem.cs +++ b/Assets/YooAsset/Samples~/Test Sample/Runtime/T1_TestEditorFileSystem/T1_TestEditorFileSystem.cs @@ -255,7 +255,28 @@ public class T1_TestEditorFileSystem : IPrebuildSetup, IPostBuildCleanup } [UnityTest] - public IEnumerator B12_TestUniTask() + public IEnumerator B12_TestEnsureBundleFile_RawBundle() + { + var tester = new TestEnsureBundleFile(); + yield return tester.RuntimeTester_RawBundle(); + } + + [UnityTest] + public IEnumerator B13_TestEnsureBundleFile_AssetBundle() + { + var tester = new TestEnsureBundleFile(); + yield return tester.RuntimeTester_AssetBundle(); + } + + [UnityTest] + public IEnumerator B14_TestEnsureBundleFile_ArchiveBundle() + { + var tester = new TestEnsureBundleFile(); + yield return tester.RuntimeTester_ArchiveBundle(); + } + + [UnityTest] + public IEnumerator B15_TestUniTask() { var tester = new TestUniTask(); yield return tester.RuntimeTester(); diff --git a/Assets/YooAsset/Samples~/Test Sample/Runtime/T2_TestBuiltinFileSystem/T2_TestBuiltinFileSystem.cs b/Assets/YooAsset/Samples~/Test Sample/Runtime/T2_TestBuiltinFileSystem/T2_TestBuiltinFileSystem.cs index e9f6c1f9..4f2c2beb 100644 --- a/Assets/YooAsset/Samples~/Test Sample/Runtime/T2_TestBuiltinFileSystem/T2_TestBuiltinFileSystem.cs +++ b/Assets/YooAsset/Samples~/Test Sample/Runtime/T2_TestBuiltinFileSystem/T2_TestBuiltinFileSystem.cs @@ -255,7 +255,28 @@ public class T2_TestBuiltinFileSystem : IPrebuildSetup, IPostBuildCleanup } [UnityTest] - public IEnumerator B12_TestUniTask() + public IEnumerator B12_TestEnsureBundleFile_RawBundle() + { + var tester = new TestEnsureBundleFile(); + yield return tester.RuntimeTester_RawBundle(); + } + + [UnityTest] + public IEnumerator B13_TestEnsureBundleFile_AssetBundle() + { + var tester = new TestEnsureBundleFile(); + yield return tester.RuntimeTester_AssetBundle(); + } + + [UnityTest] + public IEnumerator B14_TestEnsureBundleFile_ArchiveBundle() + { + var tester = new TestEnsureBundleFile(); + yield return tester.RuntimeTester_ArchiveBundle(); + } + + [UnityTest] + public IEnumerator B15_TestUniTask() { var tester = new TestUniTask(); yield return tester.RuntimeTester(); diff --git a/Assets/YooAsset/Samples~/Test Sample/TestRes/ArchiveFiles.meta b/Assets/YooAsset/Samples~/Test Sample/TestRes/ArchiveFiles.meta new file mode 100644 index 00000000..9be293bc --- /dev/null +++ b/Assets/YooAsset/Samples~/Test Sample/TestRes/ArchiveFiles.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: c0444018376a7cd4ead6a671035617d6 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/YooAsset/Samples~/Test Sample/TestRes/ArchiveFiles/archive_file_a.txt b/Assets/YooAsset/Samples~/Test Sample/TestRes/ArchiveFiles/archive_file_a.txt new file mode 100644 index 00000000..4f26cd6e --- /dev/null +++ b/Assets/YooAsset/Samples~/Test Sample/TestRes/ArchiveFiles/archive_file_a.txt @@ -0,0 +1 @@ +this is archive file a ! \ No newline at end of file diff --git a/Assets/YooAsset/Samples~/Test Sample/TestRes/ArchiveFiles/archive_file_a.txt.meta b/Assets/YooAsset/Samples~/Test Sample/TestRes/ArchiveFiles/archive_file_a.txt.meta new file mode 100644 index 00000000..8337f335 --- /dev/null +++ b/Assets/YooAsset/Samples~/Test Sample/TestRes/ArchiveFiles/archive_file_a.txt.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: a84d58cf1f5f6d24aa165fe859227a5a +TextScriptImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/YooAsset/Samples~/Test Sample/TestRes/ArchiveFiles/archive_file_b.txt b/Assets/YooAsset/Samples~/Test Sample/TestRes/ArchiveFiles/archive_file_b.txt new file mode 100644 index 00000000..2de97441 --- /dev/null +++ b/Assets/YooAsset/Samples~/Test Sample/TestRes/ArchiveFiles/archive_file_b.txt @@ -0,0 +1 @@ +this is archive file b ! \ No newline at end of file diff --git a/Assets/YooAsset/Samples~/Test Sample/TestRes/ArchiveFiles/archive_file_b.txt.meta b/Assets/YooAsset/Samples~/Test Sample/TestRes/ArchiveFiles/archive_file_b.txt.meta new file mode 100644 index 00000000..7e1eb8f7 --- /dev/null +++ b/Assets/YooAsset/Samples~/Test Sample/TestRes/ArchiveFiles/archive_file_b.txt.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: cbf8014e6b7abb942a31ff5b316c5344 +TextScriptImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/YooAsset/Samples~/Test Sample/TestRes/ArchiveFiles/archive_file_c.txt b/Assets/YooAsset/Samples~/Test Sample/TestRes/ArchiveFiles/archive_file_c.txt new file mode 100644 index 00000000..3e899613 --- /dev/null +++ b/Assets/YooAsset/Samples~/Test Sample/TestRes/ArchiveFiles/archive_file_c.txt @@ -0,0 +1 @@ +this is archive file c ! \ No newline at end of file diff --git a/Assets/YooAsset/Samples~/Test Sample/TestRes/ArchiveFiles/archive_file_c.txt.meta b/Assets/YooAsset/Samples~/Test Sample/TestRes/ArchiveFiles/archive_file_c.txt.meta new file mode 100644 index 00000000..85cb6485 --- /dev/null +++ b/Assets/YooAsset/Samples~/Test Sample/TestRes/ArchiveFiles/archive_file_c.txt.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: ed5f41165a49cbe469594ab8f558bcfa +TextScriptImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/YooAsset/Samples~/Test Sample/TestRes/ArchiveFiles/archive_file_d.txt b/Assets/YooAsset/Samples~/Test Sample/TestRes/ArchiveFiles/archive_file_d.txt new file mode 100644 index 00000000..1bc2801d --- /dev/null +++ b/Assets/YooAsset/Samples~/Test Sample/TestRes/ArchiveFiles/archive_file_d.txt @@ -0,0 +1 @@ +this is archive file d ! \ No newline at end of file diff --git a/Assets/YooAsset/Samples~/Test Sample/TestRes/ArchiveFiles/archive_file_d.txt.meta b/Assets/YooAsset/Samples~/Test Sample/TestRes/ArchiveFiles/archive_file_d.txt.meta new file mode 100644 index 00000000..38943c70 --- /dev/null +++ b/Assets/YooAsset/Samples~/Test Sample/TestRes/ArchiveFiles/archive_file_d.txt.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 9a66a58916a41684cb44606d5479caf1 +TextScriptImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/YooAsset/Samples~/Test Sample/TestRes/ArchiveFiles/archive_file_e.txt b/Assets/YooAsset/Samples~/Test Sample/TestRes/ArchiveFiles/archive_file_e.txt new file mode 100644 index 00000000..73cee8d8 --- /dev/null +++ b/Assets/YooAsset/Samples~/Test Sample/TestRes/ArchiveFiles/archive_file_e.txt @@ -0,0 +1 @@ +this is archive file e ! \ No newline at end of file diff --git a/Assets/YooAsset/Samples~/Test Sample/TestRes/ArchiveFiles/archive_file_e.txt.meta b/Assets/YooAsset/Samples~/Test Sample/TestRes/ArchiveFiles/archive_file_e.txt.meta new file mode 100644 index 00000000..5781a81f --- /dev/null +++ b/Assets/YooAsset/Samples~/Test Sample/TestRes/ArchiveFiles/archive_file_e.txt.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 0c597b9bdd6ddd84eabd8fd3538947e9 +TextScriptImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: