mirror of
https://github.com/tuyoogame/YooAsset.git
synced 2026-05-30 05:28:46 +00:00
feat : web server file system support raw bundle
This commit is contained in:
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 7244b365359a0d94d89188e1f114b5c9
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -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()}.";
|
||||||
|
|||||||
@@ -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);
|
||||||
|
|||||||
Reference in New Issue
Block a user