diff --git a/Assets/YooAsset/Runtime/BundleCache/Services/WebServerBundleCache/Operations/WSBCLoadRawBundleOperation.cs b/Assets/YooAsset/Runtime/BundleCache/Services/WebServerBundleCache/Operations/WSBCLoadRawBundleOperation.cs new file mode 100644 index 00000000..e00022b0 --- /dev/null +++ b/Assets/YooAsset/Runtime/BundleCache/Services/WebServerBundleCache/Operations/WSBCLoadRawBundleOperation.cs @@ -0,0 +1,101 @@ +namespace YooAsset +{ + /// + /// Web服务器文件缓存加载 RawBundle 操作 + /// + 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); + } + } + } +} diff --git a/Assets/YooAsset/Runtime/BundleCache/Services/WebServerBundleCache/Operations/WSBCLoadRawBundleOperation.cs.meta b/Assets/YooAsset/Runtime/BundleCache/Services/WebServerBundleCache/Operations/WSBCLoadRawBundleOperation.cs.meta new file mode 100644 index 00000000..1632508b --- /dev/null +++ b/Assets/YooAsset/Runtime/BundleCache/Services/WebServerBundleCache/Operations/WSBCLoadRawBundleOperation.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 7244b365359a0d94d89188e1f114b5c9 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/YooAsset/Runtime/BundleCache/Services/WebServerBundleCache/WebServerBundleCache.cs b/Assets/YooAsset/Runtime/BundleCache/Services/WebServerBundleCache/WebServerBundleCache.cs index a09f79ce..dfd17971 100644 --- a/Assets/YooAsset/Runtime/BundleCache/Services/WebServerBundleCache/WebServerBundleCache.cs +++ b/Assets/YooAsset/Runtime/BundleCache/Services/WebServerBundleCache/WebServerBundleCache.cs @@ -30,6 +30,11 @@ namespace YooAsset /// public IBundleDecryptor AssetBundleDecryptor { get; } + /// + /// RawBundle 解密器 + /// + public IBundleDecryptor RawBundleDecryptor { get; } + /// /// 下载后台 /// @@ -45,14 +50,15 @@ namespace YooAsset /// public IDownloadUrlPolicy DownloadUrlPolicy { get; } - public Configuration(int watchdogTimeout, bool disableUnityWebCache, - EFileVerifyLevel downloadVerifyLevel, IBundleDecryptor assetBundleDecryptor, + public Configuration(int watchdogTimeout, bool disableUnityWebCache, + EFileVerifyLevel downloadVerifyLevel, IBundleDecryptor assetBundleDecryptor, IBundleDecryptor rawBundleDecryptor, IDownloadBackend downloadBackend, IDownloadRetryPolicy downloadRetryPolicy, IDownloadUrlPolicy downloadUrlPolicy) { WatchdogTimeout = watchdogTimeout; DisableUnityWebCache = disableUnityWebCache; DownloadVerifyLevel = downloadVerifyLevel; AssetBundleDecryptor = assetBundleDecryptor; + RawBundleDecryptor = rawBundleDecryptor; DownloadBackend = downloadBackend; DownloadRetryPolicy = downloadRetryPolicy; DownloadUrlPolicy = downloadUrlPolicy; @@ -139,6 +145,11 @@ namespace YooAsset var operation = new WSBCLoadAssetBundleOperation(this, options); return operation; } + else if (options.Bundle.GetBundleType() == (int)EBundleType.RawBundle) + { + var operation = new WSBCLoadRawBundleOperation(this, options); + return operation; + } else { string error = $"{nameof(WebServerBundleCache)} does not support bundle type: {options.Bundle.GetBundleType()}."; diff --git a/Assets/YooAsset/Runtime/FileSystem/Services/WebServerFileSystem/WebServerFileSystem.cs b/Assets/YooAsset/Runtime/FileSystem/Services/WebServerFileSystem/WebServerFileSystem.cs index 8367e408..3ae8705f 100644 --- a/Assets/YooAsset/Runtime/FileSystem/Services/WebServerFileSystem/WebServerFileSystem.cs +++ b/Assets/YooAsset/Runtime/FileSystem/Services/WebServerFileSystem/WebServerFileSystem.cs @@ -61,6 +61,11 @@ namespace YooAsset /// public IBundleDecryptor AssetBundleDecryptor { get; private set; } + /// + /// 自定义参数:RawBundle 解密器 + /// + public IBundleDecryptor RawBundleDecryptor { get; private set; } + /// /// 自定义参数:资源清单解密器 /// @@ -154,6 +159,10 @@ namespace YooAsset { AssetBundleDecryptor = FileSystemHelper.CastParameter(paramName, value); } + else if (paramName == nameof(EFileSystemParameter.RawbundleDecryptor)) + { + RawBundleDecryptor = FileSystemHelper.CastParameter(paramName, value); + } else if (paramName == nameof(EFileSystemParameter.ManifestDecryptor)) { ManifestDecryptor = FileSystemHelper.CastParameter(paramName, value); @@ -199,6 +208,7 @@ namespace YooAsset disableUnityWebCache: DisableUnityWebCache, downloadVerifyLevel: DownloadVerifyLevel, assetBundleDecryptor: AssetBundleDecryptor, + rawBundleDecryptor: RawBundleDecryptor, downloadBackend: DownloadBackend, downloadRetryPolicy: DownloadRetryPolicy, downloadUrlPolicy: DownloadUrlPolicy);