feat : web server file system support raw bundle

This commit is contained in:
何冠峰
2026-05-21 22:07:44 +08:00
parent 7842235af6
commit 687dc1d9e9
4 changed files with 135 additions and 2 deletions

View File

@@ -0,0 +1,101 @@
namespace YooAsset
{
/// <summary>
/// Web服务器文件缓存加载 RawBundle 操作
/// </summary>
internal sealed class WSBCLoadRawBundleOperation : BCLoadBundleOperation
{
private enum ESteps
{
None,
GetEntry,
LoadBundle,
Done,
}
private readonly WebServerBundleCache _fileCache;
private readonly BCLoadBundleOptions _options;
private BCLoadBundleOperation _loadBundleOp;
private WebServerBundleCacheEntry _cacheEntry;
private ESteps _steps = ESteps.None;
public WSBCLoadRawBundleOperation(WebServerBundleCache fileCache, BCLoadBundleOptions options)
{
_fileCache = fileCache;
_options = options;
}
protected override void InternalStart()
{
_steps = ESteps.GetEntry;
}
protected override void InternalUpdate()
{
if (_steps == ESteps.None || _steps == ESteps.Done)
return;
if (_steps == ESteps.GetEntry)
{
_cacheEntry = _fileCache.GetEntry(_options.Bundle.BundleGuid);
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)
{
string url = DownloadUrlHelper.ToLocalFileUrl(_cacheEntry.FilePath);
var options = new LoadWebRawBundleOptions(
cacheName: _fileCache.GetType().Name,
bundle: _options.Bundle,
candidateUrls: new[] { url },
rawBundleDecryptor: _fileCache.Config.RawBundleDecryptor,
downloadBackend: _fileCache.Config.DownloadBackend,
downloadVerifyLevel: _fileCache.Config.DownloadVerifyLevel,
watchdogTimeout: _fileCache.Config.WatchdogTimeout,
downloadRetryPolicy: _fileCache.Config.DownloadRetryPolicy,
downloadUrlPolicy: _fileCache.Config.DownloadUrlPolicy);
_loadBundleOp = new LoadWebRawBundleOperation(options);
_loadBundleOp.StartOperation();
AddChildOperation(_loadBundleOp);
}
_loadBundleOp.UpdateOperation();
Progress = _loadBundleOp.Progress;
if (_loadBundleOp.IsDone == false)
return;
if (_loadBundleOp.Status == EOperationStatus.Succeeded)
{
if (_loadBundleOp.BundleHandle == null)
throw new YooInternalException("Loaded bundle handle is null.");
_steps = ESteps.Done;
SetResult();
BundleHandle = _loadBundleOp.BundleHandle;
}
else
{
_steps = ESteps.Done;
SetError(_loadBundleOp.Error);
}
}
}
protected override void InternalWaitForCompletion()
{
if (_steps != ESteps.Done)
{
_steps = ESteps.Done;
SetError("WebGL platform does not support synchronous loading.");
YooLogger.LogError(Error);
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 7244b365359a0d94d89188e1f114b5c9
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -30,6 +30,11 @@ namespace YooAsset
/// </summary> /// </summary>
public IBundleDecryptor AssetBundleDecryptor { get; } public IBundleDecryptor AssetBundleDecryptor { get; }
/// <summary>
/// RawBundle 解密器
/// </summary>
public IBundleDecryptor RawBundleDecryptor { get; }
/// <summary> /// <summary>
/// 下载后台 /// 下载后台
/// </summary> /// </summary>
@@ -46,13 +51,14 @@ namespace YooAsset
public IDownloadUrlPolicy DownloadUrlPolicy { get; } public IDownloadUrlPolicy DownloadUrlPolicy { get; }
public Configuration(int watchdogTimeout, bool disableUnityWebCache, public Configuration(int watchdogTimeout, bool disableUnityWebCache,
EFileVerifyLevel downloadVerifyLevel, IBundleDecryptor assetBundleDecryptor, EFileVerifyLevel downloadVerifyLevel, IBundleDecryptor assetBundleDecryptor, IBundleDecryptor rawBundleDecryptor,
IDownloadBackend downloadBackend, IDownloadRetryPolicy downloadRetryPolicy, IDownloadUrlPolicy downloadUrlPolicy) IDownloadBackend downloadBackend, IDownloadRetryPolicy downloadRetryPolicy, IDownloadUrlPolicy downloadUrlPolicy)
{ {
WatchdogTimeout = watchdogTimeout; WatchdogTimeout = watchdogTimeout;
DisableUnityWebCache = disableUnityWebCache; DisableUnityWebCache = disableUnityWebCache;
DownloadVerifyLevel = downloadVerifyLevel; DownloadVerifyLevel = downloadVerifyLevel;
AssetBundleDecryptor = assetBundleDecryptor; AssetBundleDecryptor = assetBundleDecryptor;
RawBundleDecryptor = rawBundleDecryptor;
DownloadBackend = downloadBackend; DownloadBackend = downloadBackend;
DownloadRetryPolicy = downloadRetryPolicy; DownloadRetryPolicy = downloadRetryPolicy;
DownloadUrlPolicy = downloadUrlPolicy; DownloadUrlPolicy = downloadUrlPolicy;
@@ -139,6 +145,11 @@ namespace YooAsset
var operation = new WSBCLoadAssetBundleOperation(this, options); var operation = new WSBCLoadAssetBundleOperation(this, options);
return operation; return operation;
} }
else if (options.Bundle.GetBundleType() == (int)EBundleType.RawBundle)
{
var operation = new WSBCLoadRawBundleOperation(this, options);
return operation;
}
else else
{ {
string error = $"{nameof(WebServerBundleCache)} does not support bundle type: {options.Bundle.GetBundleType()}."; string error = $"{nameof(WebServerBundleCache)} does not support bundle type: {options.Bundle.GetBundleType()}.";

View File

@@ -61,6 +61,11 @@ namespace YooAsset
/// </summary> /// </summary>
public IBundleDecryptor AssetBundleDecryptor { get; private set; } public IBundleDecryptor AssetBundleDecryptor { get; private set; }
/// <summary>
/// 自定义参数RawBundle 解密器
/// </summary>
public IBundleDecryptor RawBundleDecryptor { get; private set; }
/// <summary> /// <summary>
/// 自定义参数:资源清单解密器 /// 自定义参数:资源清单解密器
/// </summary> /// </summary>
@@ -154,6 +159,10 @@ namespace YooAsset
{ {
AssetBundleDecryptor = FileSystemHelper.CastParameter<IBundleDecryptor>(paramName, value); AssetBundleDecryptor = FileSystemHelper.CastParameter<IBundleDecryptor>(paramName, value);
} }
else if (paramName == nameof(EFileSystemParameter.RawbundleDecryptor))
{
RawBundleDecryptor = FileSystemHelper.CastParameter<IBundleDecryptor>(paramName, value);
}
else if (paramName == nameof(EFileSystemParameter.ManifestDecryptor)) else if (paramName == nameof(EFileSystemParameter.ManifestDecryptor))
{ {
ManifestDecryptor = FileSystemHelper.CastParameter<IManifestDecryptor>(paramName, value); ManifestDecryptor = FileSystemHelper.CastParameter<IManifestDecryptor>(paramName, value);
@@ -199,6 +208,7 @@ namespace YooAsset
disableUnityWebCache: DisableUnityWebCache, disableUnityWebCache: DisableUnityWebCache,
downloadVerifyLevel: DownloadVerifyLevel, downloadVerifyLevel: DownloadVerifyLevel,
assetBundleDecryptor: AssetBundleDecryptor, assetBundleDecryptor: AssetBundleDecryptor,
rawBundleDecryptor: RawBundleDecryptor,
downloadBackend: DownloadBackend, downloadBackend: DownloadBackend,
downloadRetryPolicy: DownloadRetryPolicy, downloadRetryPolicy: DownloadRetryPolicy,
downloadUrlPolicy: DownloadUrlPolicy); downloadUrlPolicy: DownloadUrlPolicy);