feat: add EnsureBundleFileAsync operation

This commit is contained in:
何冠峰
2026-05-15 10:56:24 +08:00
parent 322c4a9847
commit 45ecd8baff
74 changed files with 1000 additions and 374 deletions

View File

@@ -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

View File

@@ -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;

View File

@@ -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);