diff --git a/Assets/YooAsset/Runtime/BundleCache/Services/WebRemoteBundleCache/Operations/WRBCLoadRawBundleOperation.cs b/Assets/YooAsset/Runtime/BundleCache/Services/WebRemoteBundleCache/Operations/WRBCLoadRawBundleOperation.cs new file mode 100644 index 00000000..46cdd1a0 --- /dev/null +++ b/Assets/YooAsset/Runtime/BundleCache/Services/WebRemoteBundleCache/Operations/WRBCLoadRawBundleOperation.cs @@ -0,0 +1,85 @@ +namespace YooAsset +{ + /// + /// Web远端文件缓存加载 RawBundle 操作 + /// + 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); + } + } + } +} diff --git a/Assets/YooAsset/Runtime/BundleCache/Services/WebRemoteBundleCache/Operations/WRBCLoadRawBundleOperation.cs.meta b/Assets/YooAsset/Runtime/BundleCache/Services/WebRemoteBundleCache/Operations/WRBCLoadRawBundleOperation.cs.meta new file mode 100644 index 00000000..814082cb --- /dev/null +++ b/Assets/YooAsset/Runtime/BundleCache/Services/WebRemoteBundleCache/Operations/WRBCLoadRawBundleOperation.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: bf6535c1839c8b04697179268cda275c +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/YooAsset/Runtime/BundleCache/Services/WebRemoteBundleCache/WebRemoteBundleCache.cs b/Assets/YooAsset/Runtime/BundleCache/Services/WebRemoteBundleCache/WebRemoteBundleCache.cs index 0b3287f9..8b536ffa 100644 --- a/Assets/YooAsset/Runtime/BundleCache/Services/WebRemoteBundleCache/WebRemoteBundleCache.cs +++ b/Assets/YooAsset/Runtime/BundleCache/Services/WebRemoteBundleCache/WebRemoteBundleCache.cs @@ -30,6 +30,11 @@ namespace YooAsset /// public IBundleDecryptor AssetBundleDecryptor { get; } + /// + /// RawBundle 解密器 + /// + public IBundleDecryptor RawBundleDecryptor { get; } + /// /// 远程服务接口 /// @@ -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()}."; diff --git a/Assets/YooAsset/Runtime/FileSystem/Services/WebRemoteFileSystem/WebRemoteFileSystem.cs b/Assets/YooAsset/Runtime/FileSystem/Services/WebRemoteFileSystem/WebRemoteFileSystem.cs index 1193c77b..99d8a11e 100644 --- a/Assets/YooAsset/Runtime/FileSystem/Services/WebRemoteFileSystem/WebRemoteFileSystem.cs +++ b/Assets/YooAsset/Runtime/FileSystem/Services/WebRemoteFileSystem/WebRemoteFileSystem.cs @@ -55,6 +55,11 @@ namespace YooAsset /// public IBundleDecryptor AssetBundleDecryptor { get; private set; } + /// + /// 自定义参数:RawBundle 解密器 + /// + public IBundleDecryptor RawBundleDecryptor { get; private set; } + /// /// 自定义参数:资源清单解密器 /// @@ -152,6 +157,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); @@ -192,6 +201,7 @@ namespace YooAsset disableUnityWebCache: DisableUnityWebCache, downloadVerifyLevel: DownloadVerifyLevel, assetBundleDecryptor: AssetBundleDecryptor, + rawBundleDecryptor: RawBundleDecryptor, remoteService: RemoteService, downloadBackend: DownloadBackend, downloadRetryPolicy: DownloadRetryPolicy,