feat : web remote file system support raw bundle

This commit is contained in:
何冠峰
2026-05-21 22:08:13 +08:00
parent 687dc1d9e9
commit 92e34fb8b5
4 changed files with 118 additions and 1 deletions

View File

@@ -0,0 +1,85 @@
namespace YooAsset
{
/// <summary>
/// Web远端文件缓存加载 RawBundle 操作
/// </summary>
internal sealed class WRBCLoadRawBundleOperation : BCLoadBundleOperation
{
private enum ESteps
{
None,
LoadBundle,
Done,
}
private readonly WebRemoteBundleCache _fileCache;
private readonly BCLoadBundleOptions _options;
private BCLoadBundleOperation _loadBundleOp;
private ESteps _steps = ESteps.None;
public WRBCLoadRawBundleOperation(WebRemoteBundleCache fileCache, BCLoadBundleOptions options)
{
_fileCache = fileCache;
_options = options;
}
protected override void InternalStart()
{
_steps = ESteps.LoadBundle;
}
protected override void InternalUpdate()
{
if (_steps == ESteps.None || _steps == ESteps.Done)
return;
if (_steps == ESteps.LoadBundle)
{
if (_loadBundleOp == null)
{
var urls = _fileCache.Config.RemoteService.GetRemoteUrls(_options.Bundle.GetFileName());
var options = new LoadWebRawBundleOptions(
cacheName: _fileCache.GetType().Name,
bundle: _options.Bundle,
candidateUrls: urls,
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: bf6535c1839c8b04697179268cda275c
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>
@@ -51,13 +56,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, IRemoteService remoteService, EFileVerifyLevel downloadVerifyLevel, IBundleDecryptor assetBundleDecryptor, IBundleDecryptor rawBundleDecryptor, IRemoteService remoteService,
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;
RemoteService = remoteService; RemoteService = remoteService;
DownloadBackend = downloadBackend; DownloadBackend = downloadBackend;
DownloadRetryPolicy = downloadRetryPolicy; DownloadRetryPolicy = downloadRetryPolicy;
@@ -137,6 +143,11 @@ namespace YooAsset
var operation = new WRBCLoadAssetBundleOperation(this, options); var operation = new WRBCLoadAssetBundleOperation(this, options);
return operation; return operation;
} }
else if (options.Bundle.GetBundleType() == (int)EBundleType.RawBundle)
{
var operation = new WRBCLoadRawBundleOperation(this, options);
return operation;
}
else else
{ {
string error = $"{nameof(WebRemoteBundleCache)} does not support bundle type: {options.Bundle.GetBundleType()}."; string error = $"{nameof(WebRemoteBundleCache)} does not support bundle type: {options.Bundle.GetBundleType()}.";

View File

@@ -55,6 +55,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>
@@ -152,6 +157,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);
@@ -192,6 +201,7 @@ namespace YooAsset
disableUnityWebCache: DisableUnityWebCache, disableUnityWebCache: DisableUnityWebCache,
downloadVerifyLevel: DownloadVerifyLevel, downloadVerifyLevel: DownloadVerifyLevel,
assetBundleDecryptor: AssetBundleDecryptor, assetBundleDecryptor: AssetBundleDecryptor,
rawBundleDecryptor: RawBundleDecryptor,
remoteService: RemoteService, remoteService: RemoteService,
downloadBackend: DownloadBackend, downloadBackend: DownloadBackend,
downloadRetryPolicy: DownloadRetryPolicy, downloadRetryPolicy: DownloadRetryPolicy,