mirror of
https://github.com/tuyoogame/YooAsset.git
synced 2026-05-21 16:00:32 +00:00
feat : web remote file system support raw bundle
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bf6535c1839c8b04697179268cda275c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -30,6 +30,11 @@ namespace YooAsset
|
||||
/// </summary>
|
||||
public IBundleDecryptor AssetBundleDecryptor { get; }
|
||||
|
||||
/// <summary>
|
||||
/// RawBundle 解密器
|
||||
/// </summary>
|
||||
public IBundleDecryptor RawBundleDecryptor { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 远程服务接口
|
||||
/// </summary>
|
||||
@@ -51,13 +56,14 @@ namespace YooAsset
|
||||
public IDownloadUrlPolicy DownloadUrlPolicy { get; }
|
||||
|
||||
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)
|
||||
{
|
||||
WatchdogTimeout = watchdogTimeout;
|
||||
DisableUnityWebCache = disableUnityWebCache;
|
||||
DownloadVerifyLevel = downloadVerifyLevel;
|
||||
AssetBundleDecryptor = assetBundleDecryptor;
|
||||
RawBundleDecryptor = rawBundleDecryptor;
|
||||
RemoteService = remoteService;
|
||||
DownloadBackend = downloadBackend;
|
||||
DownloadRetryPolicy = downloadRetryPolicy;
|
||||
@@ -137,6 +143,11 @@ namespace YooAsset
|
||||
var operation = new WRBCLoadAssetBundleOperation(this, options);
|
||||
return operation;
|
||||
}
|
||||
else if (options.Bundle.GetBundleType() == (int)EBundleType.RawBundle)
|
||||
{
|
||||
var operation = new WRBCLoadRawBundleOperation(this, options);
|
||||
return operation;
|
||||
}
|
||||
else
|
||||
{
|
||||
string error = $"{nameof(WebRemoteBundleCache)} does not support bundle type: {options.Bundle.GetBundleType()}.";
|
||||
|
||||
@@ -55,6 +55,11 @@ namespace YooAsset
|
||||
/// </summary>
|
||||
public IBundleDecryptor AssetBundleDecryptor { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// 自定义参数:RawBundle 解密器
|
||||
/// </summary>
|
||||
public IBundleDecryptor RawBundleDecryptor { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// 自定义参数:资源清单解密器
|
||||
/// </summary>
|
||||
@@ -152,6 +157,10 @@ namespace YooAsset
|
||||
{
|
||||
AssetBundleDecryptor = FileSystemHelper.CastParameter<IBundleDecryptor>(paramName, value);
|
||||
}
|
||||
else if (paramName == nameof(EFileSystemParameter.RawbundleDecryptor))
|
||||
{
|
||||
RawBundleDecryptor = FileSystemHelper.CastParameter<IBundleDecryptor>(paramName, value);
|
||||
}
|
||||
else if (paramName == nameof(EFileSystemParameter.ManifestDecryptor))
|
||||
{
|
||||
ManifestDecryptor = FileSystemHelper.CastParameter<IManifestDecryptor>(paramName, value);
|
||||
@@ -192,6 +201,7 @@ namespace YooAsset
|
||||
disableUnityWebCache: DisableUnityWebCache,
|
||||
downloadVerifyLevel: DownloadVerifyLevel,
|
||||
assetBundleDecryptor: AssetBundleDecryptor,
|
||||
rawBundleDecryptor: RawBundleDecryptor,
|
||||
remoteService: RemoteService,
|
||||
downloadBackend: DownloadBackend,
|
||||
downloadRetryPolicy: DownloadRetryPolicy,
|
||||
|
||||
Reference in New Issue
Block a user