From fb8720edd3cd14ffb8ba771c5ae43124c10cadbb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BD=95=E5=86=A0=E5=B3=B0?= Date: Wed, 12 Feb 2025 11:59:09 +0800 Subject: [PATCH] update extension sample MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 抖音小游戏支持文件加密。 --- .../Operation/TTFSLoadBundleOperation.cs | 18 ++++++++++- .../TiktokFileSystem/TiktokFileSystem.cs | 30 +++++++++++++++++-- 2 files changed, 45 insertions(+), 3 deletions(-) diff --git a/Assets/YooAsset/Samples~/Extension Sample/Runtime/ExtensionFileSystem/TiktokFileSystem/Operation/TTFSLoadBundleOperation.cs b/Assets/YooAsset/Samples~/Extension Sample/Runtime/ExtensionFileSystem/TiktokFileSystem/Operation/TTFSLoadBundleOperation.cs index 9b1a7fc5..b55d0777 100644 --- a/Assets/YooAsset/Samples~/Extension Sample/Runtime/ExtensionFileSystem/TiktokFileSystem/Operation/TTFSLoadBundleOperation.cs +++ b/Assets/YooAsset/Samples~/Extension Sample/Runtime/ExtensionFileSystem/TiktokFileSystem/Operation/TTFSLoadBundleOperation.cs @@ -3,6 +3,7 @@ using UnityEngine; using UnityEngine.Networking; using YooAsset; using TTSDK; +using WeChatWASM; internal class TTFSLoadBundleOperation : FSLoadBundleOperation { @@ -49,7 +50,22 @@ internal class TTFSLoadBundleOperation : FSLoadBundleOperation if (CheckRequestResult()) { - var assetBundle = (_webRequest.downloadHandler as DownloadHandlerTTAssetBundle).assetBundle; + if (_bundle.Encrypted && _fileSystem.DecryptionServices == null) + { + _steps = ESteps.Done; + Status = EOperationStatus.Failed; + Error = $"The {nameof(IDecryptionServices)} is null !"; + YooLogger.Error(Error); + return; + } + + AssetBundle assetBundle; + var downloadHanlder = _webRequest.downloadHandler as DownloadHandlerTTAssetBundle; + if (_bundle.Encrypted) + assetBundle = _fileSystem.LoadEncryptedAssetBundle(downloadHanlder.data); + else + assetBundle = downloadHanlder.assetBundle; + if (assetBundle == null) { _steps = ESteps.Done; diff --git a/Assets/YooAsset/Samples~/Extension Sample/Runtime/ExtensionFileSystem/TiktokFileSystem/TiktokFileSystem.cs b/Assets/YooAsset/Samples~/Extension Sample/Runtime/ExtensionFileSystem/TiktokFileSystem/TiktokFileSystem.cs index 7f1954ab..b936cb2c 100644 --- a/Assets/YooAsset/Samples~/Extension Sample/Runtime/ExtensionFileSystem/TiktokFileSystem/TiktokFileSystem.cs +++ b/Assets/YooAsset/Samples~/Extension Sample/Runtime/ExtensionFileSystem/TiktokFileSystem/TiktokFileSystem.cs @@ -8,11 +8,20 @@ using System; public static class TiktokFileSystemCreater { - public static FileSystemParameters CreateByteGameFileSystemParameters(IRemoteServices remoteServices, string packageRoot) + public static FileSystemParameters CreateByteGameFileSystemParameters(string packageRoot, IRemoteServices remoteServices) { string fileSystemClass = $"{nameof(TiktokFileSystem)},YooAsset.RuntimeExtension"; var fileSystemParams = new FileSystemParameters(fileSystemClass, packageRoot); - fileSystemParams.AddParameter("REMOTE_SERVICES", remoteServices); + fileSystemParams.AddParameter(FileSystemParametersDefine.REMOTE_SERVICES, remoteServices); + return fileSystemParams; + } + + public static FileSystemParameters CreateByteGameFileSystemParameters(string packageRoot, IRemoteServices remoteServices, IWebDecryptionServices decryptionServices) + { + string fileSystemClass = $"{nameof(TiktokFileSystem)},YooAsset.RuntimeExtension"; + var fileSystemParams = new FileSystemParameters(fileSystemClass, packageRoot); + fileSystemParams.AddParameter(FileSystemParametersDefine.REMOTE_SERVICES, remoteServices); + fileSystemParams.AddParameter(FileSystemParametersDefine.DECRYPTION_SERVICES, decryptionServices); return fileSystemParams; } } @@ -89,6 +98,11 @@ internal class TiktokFileSystem : IFileSystem /// 自定义参数:远程服务接口 /// public IRemoteServices RemoteServices { private set; get; } = null; + + /// + /// 自定义参数:解密方法类 + /// + public IWebDecryptionServices DecryptionServices { private set; get; } #endregion @@ -150,6 +164,10 @@ internal class TiktokFileSystem : IFileSystem { RemoteServices = (IRemoteServices)value; } + else if (name == FileSystemParametersDefine.DECRYPTION_SERVICES) + { + DecryptionServices = (IWebDecryptionServices)value; + } else { YooLogger.Warning($"Invalid parameter : {name}"); @@ -250,6 +268,14 @@ internal class TiktokFileSystem : IFileSystem } return filePath; } + + /// + /// 加载加密资源文件 + /// + public AssetBundle LoadEncryptedAssetBundle(byte[] fileData) + { + return DecryptionServices.LoadAssetBundle(fileData); + } #endregion } #endif \ No newline at end of file