mirror of
https://github.com/tuyoogame/YooAsset.git
synced 2026-05-20 23:30:08 +00:00
feat: add EnsureBundleFileAsync operation
This commit is contained in:
@@ -73,5 +73,12 @@ namespace YooAsset
|
||||
/// <param name="bundleGuid">资源包的唯一标识符</param>
|
||||
/// <returns>如果缓存中存在该资源包则返回 true,否则返回 false。</returns>
|
||||
bool IsCached(string bundleGuid);
|
||||
|
||||
/// <summary>
|
||||
/// 获取已缓存的资源包文件路径
|
||||
/// </summary>
|
||||
/// <param name="bundleGuid">资源包的唯一标识符</param>
|
||||
/// <returns>返回已缓存的资源包文件路径,如果不存在则返回 null。</returns>
|
||||
string GetCacheFilePath(string bundleGuid);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ namespace YooAsset
|
||||
internal interface ICacheEntry
|
||||
{
|
||||
/// <summary>
|
||||
/// Bundle 唯一标识
|
||||
/// 资源包唯一标识
|
||||
/// </summary>
|
||||
string BundleGuid { get; }
|
||||
}
|
||||
|
||||
@@ -74,7 +74,7 @@ namespace YooAsset
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
SetResult();
|
||||
BundleHandle = new ArchiveBundleHandle(_options.FilePath, _options.Bundle, _archiveBundle);
|
||||
BundleHandle = new ArchiveBundleHandle(_options.Bundle, _archiveBundle);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -100,7 +100,7 @@ namespace YooAsset
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
SetResult();
|
||||
BundleHandle = new RawBundleHandle(_options.FilePath, _options.Bundle, _rawBundle);
|
||||
BundleHandle = new RawBundleHandle(_options.Bundle, _rawBundle);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -135,6 +135,17 @@ namespace YooAsset
|
||||
{
|
||||
return _cacheEntries.ContainsKey(bundleGuid);
|
||||
}
|
||||
/// <inheritdoc />
|
||||
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 内部方法
|
||||
/// <summary>
|
||||
|
||||
@@ -142,10 +142,16 @@ namespace YooAsset
|
||||
/// <inheritdoc />
|
||||
public bool IsCached(string bundleGuid)
|
||||
{
|
||||
if (Config.VirtualDownloadMode)
|
||||
return _cacheEntries.ContainsKey(bundleGuid);
|
||||
else
|
||||
if (Config.VirtualDownloadMode == false)
|
||||
return true;
|
||||
|
||||
return _cacheEntries.ContainsKey(bundleGuid);
|
||||
}
|
||||
/// <inheritdoc />
|
||||
public string GetCacheFilePath(string bundleGuid)
|
||||
{
|
||||
YooLogger.LogWarning($"{nameof(EditorBundleCache)} does not support local cache file path.");
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -11,20 +11,13 @@ namespace YooAsset
|
||||
/// </summary>
|
||||
public string BundleGuid { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// 资源包文件路径
|
||||
/// </summary>
|
||||
public string FilePath { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// 创建编辑器文件缓存条目实例
|
||||
/// </summary>
|
||||
/// <param name="bundleGuid">资源包唯一标识</param>
|
||||
/// <param name="filePath">资源包文件路径</param>
|
||||
public EditorBundleCacheEntry(string bundleGuid, string filePath)
|
||||
public EditorBundleCacheEntry(string bundleGuid)
|
||||
{
|
||||
BundleGuid = bundleGuid;
|
||||
FilePath = filePath;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -170,7 +170,7 @@ namespace YooAsset
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
SetResult();
|
||||
BundleHandle = new AssetBundleHandle(_cacheEntry.DataFilePath, _bundle, assetBundle, null);
|
||||
BundleHandle = new AssetBundleHandle(_bundle, assetBundle, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -154,6 +154,17 @@ namespace YooAsset
|
||||
{
|
||||
return _cacheEntries.ContainsKey(bundleGuid);
|
||||
}
|
||||
/// <inheritdoc />
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据 ClearMethod 创建对应的淘汰策略实例
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -22,11 +22,6 @@ namespace YooAsset
|
||||
/// </summary>
|
||||
public IWebGamePlatform GamePlatform { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 平台侧缓存文件路径
|
||||
/// </summary>
|
||||
public string CacheFilePath { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 看门狗超时时间
|
||||
/// </summary>
|
||||
@@ -43,13 +38,12 @@ namespace YooAsset
|
||||
public IDownloadUrlPolicy DownloadUrlPolicy { get; }
|
||||
|
||||
public LoadWebGameAssetBundleOptions(PackageBundle bundle, IReadOnlyList<string> 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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -71,8 +71,6 @@ namespace YooAsset
|
||||
}
|
||||
}
|
||||
|
||||
private readonly Dictionary<string, WebGameBundleCacheEntry> _cacheEntries = new Dictionary<string, WebGameBundleCacheEntry>(10000);
|
||||
|
||||
/// <summary>
|
||||
/// 缓存配置
|
||||
/// </summary>
|
||||
@@ -89,10 +87,10 @@ namespace YooAsset
|
||||
public bool IsReadOnly { get; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public int FileCount => _cacheEntries.Count;
|
||||
public int FileCount { get; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public long SpaceOccupied => 0;
|
||||
public long SpaceOccupied { get; }
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
@@ -155,28 +153,13 @@ namespace YooAsset
|
||||
/// <inheritdoc/>
|
||||
public bool IsCached(string bundleGuid)
|
||||
{
|
||||
if (_cacheEntries.TryGetValue(bundleGuid, out var entry))
|
||||
return Config.GamePlatform.IsCached(entry.CacheFilePath);
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
#region 内部方法
|
||||
/// <summary>
|
||||
/// 获取或创建指定资源包的缓存条目
|
||||
/// </summary>
|
||||
/// <param name="bundle">资源包描述</param>
|
||||
/// <returns>已存在则返回对应条目;否则创建并登记后返回新条目。</returns>
|
||||
internal WebGameBundleCacheEntry GetEntry(PackageBundle bundle)
|
||||
/// <inheritdoc/>
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,38 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
/// <summary>
|
||||
/// WebGL 游戏平台缓存条目
|
||||
/// </summary>
|
||||
internal class WebGameBundleCacheEntry : ICacheEntry
|
||||
{
|
||||
/// <summary>
|
||||
/// 资源包唯一标识
|
||||
/// </summary>
|
||||
public string BundleGuid { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 候选下载地址列表
|
||||
/// </summary>
|
||||
public IReadOnlyList<string> Urls { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 平台侧缓存文件路径
|
||||
/// </summary>
|
||||
public string CacheFilePath { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 创建 WebGL 游戏平台缓存条目实例
|
||||
/// </summary>
|
||||
/// <param name="bundleGuid">资源包唯一标识</param>
|
||||
/// <param name="urls">候选下载地址列表</param>
|
||||
/// <param name="cacheFilePath">平台侧缓存文件路径</param>
|
||||
public WebGameBundleCacheEntry(string bundleGuid, IReadOnlyList<string> urls, string cacheFilePath)
|
||||
{
|
||||
BundleGuid = bundleGuid;
|
||||
Urls = urls;
|
||||
CacheFilePath = cacheFilePath;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
/// <summary>
|
||||
@@ -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,
|
||||
|
||||
@@ -65,8 +65,6 @@ namespace YooAsset
|
||||
}
|
||||
}
|
||||
|
||||
private readonly Dictionary<string, WebRemoteBundleCacheEntry> _cacheEntries = new Dictionary<string, WebRemoteBundleCacheEntry>(10000);
|
||||
|
||||
/// <summary>
|
||||
/// 缓存配置
|
||||
/// </summary>
|
||||
@@ -83,16 +81,10 @@ namespace YooAsset
|
||||
public bool IsReadOnly { get; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public int FileCount
|
||||
{
|
||||
get
|
||||
{
|
||||
return _cacheEntries.Count;
|
||||
}
|
||||
}
|
||||
public int FileCount { get; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public long SpaceOccupied { get; private set; }
|
||||
public long SpaceOccupied { get; }
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
@@ -157,23 +149,11 @@ namespace YooAsset
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
#region 内部方法
|
||||
/// <summary>
|
||||
/// 获取或创建指定资源包的缓存条目
|
||||
/// </summary>
|
||||
/// <param name="bundle">资源包描述</param>
|
||||
/// <returns>已存在则返回对应条目;否则创建并登记后返回新条目。</returns>
|
||||
internal WebRemoteBundleCacheEntry GetEntry(PackageBundle bundle)
|
||||
/// <inheritdoc />
|
||||
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
|
||||
}
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
/// <summary>
|
||||
/// Web远端文件缓存条目
|
||||
/// </summary>
|
||||
internal class WebRemoteBundleCacheEntry : ICacheEntry
|
||||
{
|
||||
/// <summary>
|
||||
/// 资源包唯一标识
|
||||
/// </summary>
|
||||
public string BundleGuid { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 候选下载地址列表
|
||||
/// </summary>
|
||||
public IReadOnlyList<string> Urls { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 创建 Web 远端文件缓存条目实例
|
||||
/// </summary>
|
||||
/// <param name="bundleGuid">资源包唯一标识</param>
|
||||
/// <param name="urls">候选下载地址列表</param>
|
||||
public WebRemoteBundleCacheEntry(string bundleGuid, IReadOnlyList<string> urls)
|
||||
{
|
||||
BundleGuid = bundleGuid;
|
||||
Urls = urls;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -86,7 +86,7 @@ namespace YooAsset
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public long SpaceOccupied { get; private set; }
|
||||
public long SpaceOccupied { get; }
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
@@ -151,6 +151,12 @@ namespace YooAsset
|
||||
{
|
||||
return _cacheEntries.ContainsKey(bundleGuid);
|
||||
}
|
||||
/// <inheritdoc />
|
||||
public string GetCacheFilePath(string bundleGuid)
|
||||
{
|
||||
YooLogger.LogWarning($"{nameof(WebServerBundleCache)} does not support local cache file path.");
|
||||
return null;
|
||||
}
|
||||
|
||||
#region 内部方法
|
||||
/// <summary>
|
||||
|
||||
@@ -7,11 +7,6 @@ namespace YooAsset
|
||||
/// </summary>
|
||||
internal interface IBundleHandle
|
||||
{
|
||||
/// <summary>
|
||||
/// 资源包文件的本地路径
|
||||
/// </summary>
|
||||
string BundleFilePath { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 卸载资源包
|
||||
/// </summary>
|
||||
|
||||
@@ -7,25 +7,16 @@ namespace YooAsset
|
||||
/// </summary>
|
||||
internal sealed class ArchiveBundleHandle : IBundleHandle
|
||||
{
|
||||
private readonly string _bundleFilePath;
|
||||
private readonly PackageBundle _packageBundle;
|
||||
private readonly ArchiveBundle _archiveBundle;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public string BundleFilePath
|
||||
{
|
||||
get { return _bundleFilePath; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建 ArchiveBundleHandle 实例
|
||||
/// </summary>
|
||||
/// <param name="bundleFilePath">资源包文件的本地路径</param>
|
||||
/// <param name="packageBundle">资源包描述</param>
|
||||
/// <param name="archiveBundle">已解析的归档资源包数据对象</param>
|
||||
public ArchiveBundleHandle(string bundleFilePath, PackageBundle packageBundle, ArchiveBundle archiveBundle)
|
||||
public ArchiveBundleHandle(PackageBundle packageBundle, ArchiveBundle archiveBundle)
|
||||
{
|
||||
_bundleFilePath = bundleFilePath;
|
||||
_packageBundle = packageBundle;
|
||||
_archiveBundle = archiveBundle;
|
||||
}
|
||||
|
||||
@@ -9,27 +9,18 @@ namespace YooAsset
|
||||
/// </summary>
|
||||
internal sealed class AssetBundleHandle : IBundleHandle
|
||||
{
|
||||
private readonly string _bundleFilePath;
|
||||
private readonly PackageBundle _packageBundle;
|
||||
private readonly AssetBundle _assetBundle;
|
||||
private readonly Stream _bundleStream;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public string BundleFilePath
|
||||
{
|
||||
get { return _bundleFilePath; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建 AssetBundleHandle 实例
|
||||
/// </summary>
|
||||
/// <param name="bundleFilePath">资源包文件的本地路径</param>
|
||||
/// <param name="packageBundle">资源包描述</param>
|
||||
/// <param name="assetBundle">已加载的 AssetBundle 对象</param>
|
||||
/// <param name="bundleStream">加载 AssetBundle 时使用的文件流</param>
|
||||
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;
|
||||
|
||||
@@ -7,25 +7,16 @@ namespace YooAsset
|
||||
/// </summary>
|
||||
internal sealed class RawBundleHandle : IBundleHandle
|
||||
{
|
||||
private readonly string _bundleFilePath;
|
||||
private readonly PackageBundle _packageBundle;
|
||||
private readonly RawBundle _rawBundle;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public string BundleFilePath
|
||||
{
|
||||
get { return _bundleFilePath; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建 RawBundleHandle 实例
|
||||
/// </summary>
|
||||
/// <param name="bundleFilePath">资源包文件的本地路径</param>
|
||||
/// <param name="packageBundle">资源包描述</param>
|
||||
/// <param name="rawBundle">已加载的原生资源包数据对象</param>
|
||||
public RawBundleHandle(string bundleFilePath, PackageBundle packageBundle, RawBundle rawBundle)
|
||||
public RawBundleHandle(PackageBundle packageBundle, RawBundle rawBundle)
|
||||
{
|
||||
_bundleFilePath = bundleFilePath;
|
||||
_packageBundle = packageBundle;
|
||||
_rawBundle = rawBundle;
|
||||
}
|
||||
|
||||
@@ -4,23 +4,14 @@ namespace YooAsset
|
||||
{
|
||||
internal sealed class VirtualAssetBundleHandle : IBundleHandle
|
||||
{
|
||||
private readonly string _bundleFilePath;
|
||||
private readonly PackageBundle _packageBundle;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public string BundleFilePath
|
||||
{
|
||||
get { return _bundleFilePath; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建 VirtualAssetBundleHandle 实例
|
||||
/// </summary>
|
||||
/// <param name="bundleFilePath">资源包文件的本地路径</param>
|
||||
/// <param name="packageBundle">资源包描述</param>
|
||||
public VirtualAssetBundleHandle(string bundleFilePath, PackageBundle packageBundle)
|
||||
public VirtualAssetBundleHandle(PackageBundle packageBundle)
|
||||
{
|
||||
_bundleFilePath = bundleFilePath;
|
||||
_packageBundle = packageBundle;
|
||||
}
|
||||
|
||||
|
||||
@@ -4,25 +4,16 @@ namespace YooAsset
|
||||
{
|
||||
internal sealed class VirtualRawBundleHandle : IBundleHandle
|
||||
{
|
||||
private readonly string _bundleFilePath;
|
||||
private readonly PackageBundle _packageBundle;
|
||||
private readonly RawBundle _rawBundle;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public string BundleFilePath
|
||||
{
|
||||
get { return _bundleFilePath; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建 VirtualRawBundleHandle 实例
|
||||
/// </summary>
|
||||
/// <param name="bundleFilePath">资源包文件的本地路径</param>
|
||||
/// <param name="packageBundle">资源包描述</param>
|
||||
/// <param name="rawBundle">已加载的原生资源包数据对象</param>
|
||||
public VirtualRawBundleHandle(string bundleFilePath, PackageBundle packageBundle, RawBundle rawBundle)
|
||||
public VirtualRawBundleHandle(PackageBundle packageBundle, RawBundle rawBundle)
|
||||
{
|
||||
_bundleFilePath = bundleFilePath;
|
||||
_packageBundle = packageBundle;
|
||||
_rawBundle = rawBundle;
|
||||
}
|
||||
|
||||
@@ -8,27 +8,18 @@ namespace YooAsset
|
||||
/// </summary>
|
||||
internal sealed class WebGameAssetBundleHandle : IBundleHandle
|
||||
{
|
||||
private readonly string _bundleFilePath;
|
||||
private readonly PackageBundle _packageBundle;
|
||||
private readonly AssetBundle _assetBundle;
|
||||
private readonly IWebGamePlatform _platform;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public string BundleFilePath
|
||||
{
|
||||
get { return _bundleFilePath; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建 WebGameAssetBundleHandle 实例
|
||||
/// </summary>
|
||||
/// <param name="bundleFilePath">资源包文件的本地路径</param>
|
||||
/// <param name="packageBundle">资源包描述</param>
|
||||
/// <param name="assetBundle">已加载的 AssetBundle 对象</param>
|
||||
/// <param name="platform">平台实现</param>
|
||||
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;
|
||||
|
||||
@@ -94,27 +94,34 @@ namespace YooAsset
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region BundleFileHandle -- GetRawFileData / GetRawFileText
|
||||
#region BundleFileHandle -- GetBundleFilePath / GetRawFileData / GetRawFileText
|
||||
public sealed partial class BundleFileHandle
|
||||
{
|
||||
/// <summary>
|
||||
/// v2.3: rawFileHandle.GetRawFilePath()
|
||||
/// </summary>
|
||||
[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.");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// v2.3: rawFileHandle.GetRawFileData()
|
||||
/// </summary>
|
||||
[Obsolete("Read file manually via GetBundleFilePath().")]
|
||||
[Obsolete("Use LoadAssetAsync<RawFileObject>() 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<RawFileObject>() to read binary data via RawFileObject.GetBytes().");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// v2.3: rawFileHandle.GetRawFileText()
|
||||
/// </summary>
|
||||
[Obsolete("Read file manually via GetBundleFilePath().")]
|
||||
[Obsolete("Use LoadAssetAsync<RawFileObject>() 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<RawFileObject>() to read text data via RawFileObject.GetText().");
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
@@ -38,6 +38,13 @@ namespace YooAsset
|
||||
/// <returns>加载资源包操作句柄</returns>
|
||||
FSLoadPackageBundleOperation LoadPackageBundleAsync(FSLoadPackageBundleOptions options);
|
||||
|
||||
/// <summary>
|
||||
/// 确保资源包文件已就绪
|
||||
/// </summary>
|
||||
/// <param name="options">确保资源包已就绪的选项参数</param>
|
||||
/// <returns>确保资源包已就绪的操作句柄</returns>
|
||||
FSEnsurePackageBundleOperation EnsurePackageBundleAsync(FSEnsurePackageBundleOptions options);
|
||||
|
||||
/// <summary>
|
||||
/// 下载资源包
|
||||
/// </summary>
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
/// <summary>
|
||||
/// 确保资源包已就绪的操作基类
|
||||
/// </summary>
|
||||
internal abstract class FSEnsurePackageBundleOperation : AsyncOperationBase
|
||||
{
|
||||
/// <summary>
|
||||
/// 资源包文件的本地路径
|
||||
/// </summary>
|
||||
public string BundleFilePath { get; protected set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 确保资源包已就绪的失败实现
|
||||
/// </summary>
|
||||
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()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f11e7e5e45702bb459771f57e1b84fdc
|
||||
guid: 104d90c1b2424984d86d037cc4672f41
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
@@ -0,0 +1,19 @@
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
/// <summary>
|
||||
/// 确保资源包已就绪的操作选项
|
||||
/// </summary>
|
||||
internal readonly struct FSEnsurePackageBundleOptions
|
||||
{
|
||||
/// <summary>
|
||||
/// 资源包描述
|
||||
/// </summary>
|
||||
public PackageBundle Bundle { get; }
|
||||
|
||||
public FSEnsurePackageBundleOptions(PackageBundle bundle)
|
||||
{
|
||||
Bundle = bundle;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2c5756c583ed1474c9abb56419b488d6
|
||||
guid: 27f8e387050567642b3ee6da777f3189
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
@@ -175,6 +175,12 @@ namespace YooAsset
|
||||
return operation;
|
||||
}
|
||||
/// <inheritdoc />
|
||||
public FSEnsurePackageBundleOperation EnsurePackageBundleAsync(FSEnsurePackageBundleOptions options)
|
||||
{
|
||||
var operation = new BFSEnsurePackageBundleOperation(this, options);
|
||||
return operation;
|
||||
}
|
||||
/// <inheritdoc />
|
||||
public FSDownloadBundleOperation DownloadBundleAsync(FSDownloadBundleOptions options)
|
||||
{
|
||||
var operation = new BFSDownloadBundleOperation(this, options);
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6ea859176a8a53342a78b5dbb0909da0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -121,6 +121,12 @@ namespace YooAsset
|
||||
return operation;
|
||||
}
|
||||
/// <inheritdoc />
|
||||
public FSEnsurePackageBundleOperation EnsurePackageBundleAsync(FSEnsurePackageBundleOptions options)
|
||||
{
|
||||
var operation = new EFSEnsurePackageBundleOperation(this, options);
|
||||
return operation;
|
||||
}
|
||||
/// <inheritdoc />
|
||||
public FSDownloadBundleOperation DownloadBundleAsync(FSDownloadBundleOptions options)
|
||||
{
|
||||
var downloader = new EFSDownloadBundleOperation(this, options);
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 44426c6bae3a47e43be1a57e455bf520
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3df0f518860ad9042aefab0cc18bc630
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -177,6 +177,12 @@ namespace YooAsset
|
||||
return operation;
|
||||
}
|
||||
/// <inheritdoc />
|
||||
public FSEnsurePackageBundleOperation EnsurePackageBundleAsync(FSEnsurePackageBundleOptions options)
|
||||
{
|
||||
var operation = new SFSEnsurePackageBundleOperation(this, options);
|
||||
return operation;
|
||||
}
|
||||
/// <inheritdoc />
|
||||
public FSDownloadBundleOperation DownloadBundleAsync(FSDownloadBundleOptions options)
|
||||
{
|
||||
var downloader = new SFSDownloadBundleOperation(this, options);
|
||||
|
||||
@@ -96,6 +96,12 @@ namespace YooAsset
|
||||
return operation;
|
||||
}
|
||||
/// <inheritdoc />
|
||||
public virtual FSEnsurePackageBundleOperation EnsurePackageBundleAsync(FSEnsurePackageBundleOptions options)
|
||||
{
|
||||
var operation = new FSEnsurePackageBundleFailureOperation($"{nameof(WebGameFileSystem)} does not support ensure bundle file operation.");
|
||||
return operation;
|
||||
}
|
||||
/// <inheritdoc />
|
||||
public virtual FSDownloadBundleOperation DownloadBundleAsync(FSDownloadBundleOptions options)
|
||||
{
|
||||
var operation = new FSDownloadBundleCompleteOperation($"{nameof(WebGameFileSystem)} does not support download operation.");
|
||||
|
||||
@@ -102,6 +102,12 @@ namespace YooAsset
|
||||
return operation;
|
||||
}
|
||||
/// <inheritdoc />
|
||||
public FSEnsurePackageBundleOperation EnsurePackageBundleAsync(FSEnsurePackageBundleOptions options)
|
||||
{
|
||||
var operation = new FSEnsurePackageBundleFailureOperation($"{nameof(WebRemoteFileSystem)} does not support ensure bundle file operation.");
|
||||
return operation;
|
||||
}
|
||||
/// <inheritdoc />
|
||||
public FSDownloadBundleOperation DownloadBundleAsync(FSDownloadBundleOptions options)
|
||||
{
|
||||
var operation = new FSDownloadBundleCompleteOperation($"{nameof(WebRemoteFileSystem)} does not support download operation.");
|
||||
|
||||
@@ -108,6 +108,12 @@ namespace YooAsset
|
||||
return operation;
|
||||
}
|
||||
/// <inheritdoc />
|
||||
public FSEnsurePackageBundleOperation EnsurePackageBundleAsync(FSEnsurePackageBundleOptions options)
|
||||
{
|
||||
var operation = new FSEnsurePackageBundleFailureOperation($"{nameof(WebServerFileSystem)} does not support ensure bundle file operation.");
|
||||
return operation;
|
||||
}
|
||||
/// <inheritdoc />
|
||||
public FSDownloadBundleOperation DownloadBundleAsync(FSDownloadBundleOptions options)
|
||||
{
|
||||
var operation = new FSDownloadBundleCompleteOperation($"{nameof(WebServerFileSystem)} does not support download operation.");
|
||||
|
||||
@@ -47,16 +47,5 @@ namespace YooAsset
|
||||
return;
|
||||
Provider.WaitForCompletion();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取资源包文件的路径
|
||||
/// </summary>
|
||||
/// <returns>资源包文件的磁盘路径</returns>
|
||||
public string GetBundleFilePath()
|
||||
{
|
||||
if (CheckValidWithWarning() == false)
|
||||
return string.Empty;
|
||||
return Provider.LoadedBundleHandle.BundleFilePath;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -50,6 +50,16 @@ namespace YooAsset
|
||||
return _fileSystem.LoadPackageBundleAsync(options);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建资源包文件确保器
|
||||
/// </summary>
|
||||
/// <returns>返回确保资源包文件就绪的操作对象</returns>
|
||||
public FSEnsurePackageBundleOperation CreateBundleEnsurer()
|
||||
{
|
||||
var options = new FSEnsurePackageBundleOptions(Bundle);
|
||||
return _fileSystem.EnsurePackageBundleAsync(options);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建资源包下载器
|
||||
/// </summary>
|
||||
|
||||
@@ -0,0 +1,132 @@
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
/// <summary>
|
||||
/// 确保资源包已就绪的异步操作
|
||||
/// </summary>
|
||||
public sealed class EnsureBundleFileOperation : AsyncOperationBase
|
||||
{
|
||||
/// <summary>
|
||||
/// 资源包文件详情
|
||||
/// </summary>
|
||||
public readonly struct BundleDetail
|
||||
{
|
||||
/// <summary>
|
||||
/// 资源包名称
|
||||
/// </summary>
|
||||
public readonly string BundleName;
|
||||
|
||||
/// <summary>
|
||||
/// 资源包文件的本地路径
|
||||
/// </summary>
|
||||
public readonly string BundleFilePath;
|
||||
|
||||
/// <summary>
|
||||
/// 资源包类型
|
||||
/// </summary>
|
||||
public readonly int BundleType;
|
||||
|
||||
/// <summary>
|
||||
/// 文件是否加密
|
||||
/// </summary>
|
||||
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;
|
||||
|
||||
/// <summary>
|
||||
/// 资源包文件详情
|
||||
/// </summary>
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f96dcb07877ab7d4eaff7d2f9f171ecd
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,39 @@
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
/// <summary>
|
||||
/// 确保资源包文件已就绪的选项
|
||||
/// </summary>
|
||||
public readonly struct EnsureBundleFileOptions
|
||||
{
|
||||
/// <summary>
|
||||
/// 资源定位地址
|
||||
/// </summary>
|
||||
public string Location { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 资源信息
|
||||
/// </summary>
|
||||
public AssetInfo AssetInfo { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 创建确保资源包文件已就绪的选项实例
|
||||
/// </summary>
|
||||
/// <param name="location">资源定位地址</param>
|
||||
public EnsureBundleFileOptions(string location)
|
||||
{
|
||||
Location = location;
|
||||
AssetInfo = null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建确保资源包文件已就绪的选项实例
|
||||
/// </summary>
|
||||
/// <param name="assetInfo">资源信息</param>
|
||||
public EnsureBundleFileOptions(AssetInfo assetInfo)
|
||||
{
|
||||
Location = null;
|
||||
AssetInfo = assetInfo;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8a62e7d7a33c4d34a9c3b4d59a3b0a2f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -419,66 +419,6 @@ namespace YooAsset
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 资源包文件
|
||||
/// <summary>
|
||||
/// 同步加载资源包文件
|
||||
/// </summary>
|
||||
/// <param name="assetInfo">资源信息</param>
|
||||
/// <returns>返回资源包文件操作句柄</returns>
|
||||
public BundleFileHandle LoadBundleFileSync(AssetInfo assetInfo)
|
||||
{
|
||||
CheckInitialized();
|
||||
return LoadBundleFileInternal(assetInfo, true, 0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 同步加载资源包文件
|
||||
/// </summary>
|
||||
/// <param name="location">资源的定位地址</param>
|
||||
/// <returns>返回资源包文件操作句柄</returns>
|
||||
public BundleFileHandle LoadBundleFileSync(string location)
|
||||
{
|
||||
CheckInitialized();
|
||||
AssetInfo assetInfo = ConvertLocationToAssetInfo(location, null);
|
||||
return LoadBundleFileInternal(assetInfo, true, 0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步加载资源包文件
|
||||
/// </summary>
|
||||
/// <param name="assetInfo">资源信息</param>
|
||||
/// <param name="priority">加载的优先级</param>
|
||||
/// <returns>返回资源包文件操作句柄</returns>
|
||||
public BundleFileHandle LoadBundleFileAsync(AssetInfo assetInfo, uint priority = 0)
|
||||
{
|
||||
CheckInitialized();
|
||||
return LoadBundleFileInternal(assetInfo, false, priority);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步加载资源包文件
|
||||
/// </summary>
|
||||
/// <param name="location">资源的定位地址</param>
|
||||
/// <param name="priority">加载的优先级</param>
|
||||
/// <returns>返回资源包文件操作句柄</returns>
|
||||
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 场景加载
|
||||
/// <summary>
|
||||
/// 同步加载场景
|
||||
@@ -898,6 +838,84 @@ namespace YooAsset
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 资源包文件
|
||||
/// <summary>
|
||||
/// 确保资源包文件已就绪
|
||||
/// </summary>
|
||||
/// <param name="options">确保资源包文件已就绪的选项</param>
|
||||
/// <returns>返回确保资源包文件就绪的操作对象</returns>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 同步加载资源包文件
|
||||
/// </summary>
|
||||
/// <param name="assetInfo">资源信息</param>
|
||||
/// <returns>返回资源包文件操作句柄</returns>
|
||||
public BundleFileHandle LoadBundleFileSync(AssetInfo assetInfo)
|
||||
{
|
||||
CheckInitialized();
|
||||
return LoadBundleFileInternal(assetInfo, true, 0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 同步加载资源包文件
|
||||
/// </summary>
|
||||
/// <param name="location">资源的定位地址</param>
|
||||
/// <returns>返回资源包文件操作句柄</returns>
|
||||
public BundleFileHandle LoadBundleFileSync(string location)
|
||||
{
|
||||
CheckInitialized();
|
||||
AssetInfo assetInfo = ConvertLocationToAssetInfo(location, null);
|
||||
return LoadBundleFileInternal(assetInfo, true, 0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步加载资源包文件
|
||||
/// </summary>
|
||||
/// <param name="assetInfo">资源信息</param>
|
||||
/// <param name="priority">加载的优先级</param>
|
||||
/// <returns>返回资源包文件操作句柄</returns>
|
||||
public BundleFileHandle LoadBundleFileAsync(AssetInfo assetInfo, uint priority = 0)
|
||||
{
|
||||
CheckInitialized();
|
||||
return LoadBundleFileInternal(assetInfo, false, priority);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步加载资源包文件
|
||||
/// </summary>
|
||||
/// <param name="location">资源的定位地址</param>
|
||||
/// <param name="priority">加载的优先级</param>
|
||||
/// <returns>返回资源包文件操作句柄</returns>
|
||||
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 资源下载
|
||||
/// <summary>
|
||||
/// 创建资源下载器,用于下载指定的资源标签关联的资源包文件。
|
||||
|
||||
@@ -14,7 +14,7 @@ using YooAsset;
|
||||
/// 1. 异步加载 Bundle 文件,验证加载成功
|
||||
/// 2. 释放 BundleFileHandle 引用,等待一帧
|
||||
/// 3. 调用 UnloadUnusedAssetsAsync 清理未使用资源
|
||||
/// 4. 再次加载同一 Bundle 文件,验证加载成功且文件路径有效
|
||||
/// 4. 再次加载同一 Bundle 文件,验证加载成功
|
||||
/// </remarks>
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
using System.IO;
|
||||
using System.Collections;
|
||||
using UnityEngine.TestTools;
|
||||
using NUnit.Framework;
|
||||
using YooAsset;
|
||||
|
||||
/// <summary>
|
||||
/// 测试确保资源包已就绪
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// 覆盖 API: EnsureBundleFileAsync
|
||||
/// 测试内容:
|
||||
/// 1. RawBundle 包裹:异步确保资源包已就绪,验证文件路径有效(raw_file_a)
|
||||
/// 2. AssetBundle 包裹:异步确保资源包已就绪,验证文件路径有效(prefab_a)
|
||||
/// 3. ArchiveBundle 包裹:异步确保资源包已就绪,验证文件路径有效(archive_file_a)
|
||||
/// </remarks>
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7c4cd191337037a4da1cc228d1d871fc
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -10,10 +10,10 @@ using YooAsset;
|
||||
/// <remarks>
|
||||
/// 覆盖 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)
|
||||
/// </remarks>
|
||||
public class TestLoadArchiveBundle
|
||||
{
|
||||
@@ -24,7 +24,7 @@ public class TestLoadArchiveBundle
|
||||
|
||||
// 异步加载归档子文件
|
||||
{
|
||||
var assetHandle = package.LoadAssetAsync<RawFileObject>("raw_file_a");
|
||||
var assetHandle = package.LoadAssetAsync<RawFileObject>("archive_file_a");
|
||||
yield return assetHandle;
|
||||
Assert.AreEqual(EOperationStatus.Succeeded, assetHandle.Status);
|
||||
|
||||
@@ -43,7 +43,7 @@ public class TestLoadArchiveBundle
|
||||
|
||||
// 同步加载归档子文件
|
||||
{
|
||||
var assetHandle = package.LoadAssetSync<RawFileObject>("raw_file_b");
|
||||
var assetHandle = package.LoadAssetSync<RawFileObject>("archive_file_b");
|
||||
Assert.AreEqual(EOperationStatus.Succeeded, assetHandle.Status);
|
||||
|
||||
var rawFileObject = assetHandle.GetAssetObject<RawFileObject>();
|
||||
@@ -61,11 +61,11 @@ public class TestLoadArchiveBundle
|
||||
|
||||
// 重复加载同一归档子文件,验证缓存命中
|
||||
{
|
||||
var handle1 = package.LoadAssetAsync<RawFileObject>("raw_file_c");
|
||||
var handle1 = package.LoadAssetAsync<RawFileObject>("archive_file_c");
|
||||
yield return handle1;
|
||||
Assert.AreEqual(EOperationStatus.Succeeded, handle1.Status);
|
||||
|
||||
var handle2 = package.LoadAssetAsync<RawFileObject>("raw_file_c");
|
||||
var handle2 = package.LoadAssetAsync<RawFileObject>("archive_file_c");
|
||||
yield return handle2;
|
||||
Assert.AreEqual(EOperationStatus.Succeeded, handle2.Status);
|
||||
|
||||
@@ -80,7 +80,7 @@ public class TestLoadArchiveBundle
|
||||
|
||||
// 释放后卸载再重新加载,验证新旧对象不是同一实例
|
||||
{
|
||||
var assetHandle = package.LoadAssetAsync<RawFileObject>("raw_file_e");
|
||||
var assetHandle = package.LoadAssetAsync<RawFileObject>("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<RawFileObject>("raw_file_e");
|
||||
var reloadHandle = package.LoadAssetAsync<RawFileObject>("archive_file_e");
|
||||
yield return reloadHandle;
|
||||
Assert.AreEqual(EOperationStatus.Succeeded, reloadHandle.Status);
|
||||
|
||||
|
||||
@@ -12,8 +12,8 @@ using YooAsset;
|
||||
/// <remarks>
|
||||
/// 覆盖 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)
|
||||
/// </remarks>
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c0444018376a7cd4ead6a671035617d6
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1 @@
|
||||
this is archive file a !
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a84d58cf1f5f6d24aa165fe859227a5a
|
||||
TextScriptImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1 @@
|
||||
this is archive file b !
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cbf8014e6b7abb942a31ff5b316c5344
|
||||
TextScriptImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1 @@
|
||||
this is archive file c !
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ed5f41165a49cbe469594ab8f558bcfa
|
||||
TextScriptImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1 @@
|
||||
this is archive file d !
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9a66a58916a41684cb44606d5479caf1
|
||||
TextScriptImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1 @@
|
||||
this is archive file e !
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0c597b9bdd6ddd84eabd8fd3538947e9
|
||||
TextScriptImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user