mirror of
https://github.com/tuyoogame/YooAsset.git
synced 2026-05-29 12:41:00 +00:00
update test sample
This commit is contained in:
@@ -71,7 +71,7 @@ public static class TestPackageBuilder
|
|||||||
buildParameters.ClearBuildCacheFiles = true;
|
buildParameters.ClearBuildCacheFiles = true;
|
||||||
buildParameters.UseAssetDependencyDB = true;
|
buildParameters.UseAssetDependencyDB = true;
|
||||||
buildParameters.BuiltinShadersBundleName = builtinShaderBundleName;
|
buildParameters.BuiltinShadersBundleName = builtinShaderBundleName;
|
||||||
buildParameters.EncryptionServices = new FileStreamTestEncryption();
|
buildParameters.EncryptionServices = new TestFileStreamEncryption();
|
||||||
|
|
||||||
var pipeline = new ScriptableBuildPipeline();
|
var pipeline = new ScriptableBuildPipeline();
|
||||||
BuildResult buildResult = pipeline.Run(buildParameters, false);
|
BuildResult buildResult = pipeline.Run(buildParameters, false);
|
||||||
@@ -108,7 +108,7 @@ public static class TestPackageBuilder
|
|||||||
buildParameters.CompressOption = ECompressOption.LZ4;
|
buildParameters.CompressOption = ECompressOption.LZ4;
|
||||||
buildParameters.ClearBuildCacheFiles = true;
|
buildParameters.ClearBuildCacheFiles = true;
|
||||||
buildParameters.UseAssetDependencyDB = true;
|
buildParameters.UseAssetDependencyDB = true;
|
||||||
buildParameters.EncryptionServices = new FileStreamTestEncryption();
|
buildParameters.EncryptionServices = new TestFileStreamEncryption();
|
||||||
|
|
||||||
var pipeline = new BuiltinBuildPipeline();
|
var pipeline = new BuiltinBuildPipeline();
|
||||||
BuildResult buildResult = pipeline.Run(buildParameters, false);
|
BuildResult buildResult = pipeline.Run(buildParameters, false);
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ public class T2_TestBuldinFileSystem : IPrebuildSetup, IPostBuildCleanup
|
|||||||
|
|
||||||
// 初始化资源包
|
// 初始化资源包
|
||||||
var initParams = new OfflinePlayModeParameters();
|
var initParams = new OfflinePlayModeParameters();
|
||||||
var decryption = new FileStreamTestDecryption();
|
var decryption = new TestFileStreamDecryption();
|
||||||
initParams.BuildinFileSystemParameters = FileSystemParameters.CreateDefaultBuildinFileSystemParameters(decryption, packageRoot);
|
initParams.BuildinFileSystemParameters = FileSystemParameters.CreateDefaultBuildinFileSystemParameters(decryption, packageRoot);
|
||||||
initParams.BuildinFileSystemParameters.AddParameter(FileSystemParametersDefine.DISABLE_CATALOG_FILE, true);
|
initParams.BuildinFileSystemParameters.AddParameter(FileSystemParametersDefine.DISABLE_CATALOG_FILE, true);
|
||||||
var initializeOp = package.InitializeAsync(initParams);
|
var initializeOp = package.InitializeAsync(initParams);
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ public class TestBundleEncryption
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 文件流加密方式
|
/// 文件流加密方式
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class FileStreamTestEncryption : IEncryptionServices
|
public class TestFileStreamEncryption : IEncryptionServices
|
||||||
{
|
{
|
||||||
public EncryptResult Encrypt(EncryptFileInfo fileInfo)
|
public EncryptResult Encrypt(EncryptFileInfo fileInfo)
|
||||||
{
|
{
|
||||||
@@ -64,7 +64,7 @@ public class FileStreamTestEncryption : IEncryptionServices
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 文件偏移加密方式
|
/// 文件偏移加密方式
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class FileOffsetTestEncryption : IEncryptionServices
|
public class TestFileOffsetEncryption : IEncryptionServices
|
||||||
{
|
{
|
||||||
public EncryptResult Encrypt(EncryptFileInfo fileInfo)
|
public EncryptResult Encrypt(EncryptFileInfo fileInfo)
|
||||||
{
|
{
|
||||||
@@ -119,7 +119,7 @@ public class BundleStream : FileStream
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 资源文件流解密类
|
/// 资源文件流解密类
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class FileStreamTestDecryption : IDecryptionServices
|
public class TestFileStreamDecryption : IDecryptionServices
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 同步方式获取解密的资源包对象
|
/// 同步方式获取解密的资源包对象
|
||||||
@@ -180,7 +180,7 @@ public class FileStreamTestDecryption : IDecryptionServices
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 资源文件偏移解密类
|
/// 资源文件偏移解密类
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class FileOffsetTestDecryption : IDecryptionServices
|
public class TestFileOffsetDecryption : IDecryptionServices
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 同步方式获取解密的资源包对象
|
/// 同步方式获取解密的资源包对象
|
||||||
@@ -240,7 +240,7 @@ public class FileOffsetTestDecryption : IDecryptionServices
|
|||||||
/// WebGL平台解密类
|
/// WebGL平台解密类
|
||||||
/// 注意:WebGL平台支持内存解密
|
/// 注意:WebGL平台支持内存解密
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class WebFileStreamTestDecryption : IWebDecryptionServices
|
public class TestWebFileStreamDecryption : IWebDecryptionServices
|
||||||
{
|
{
|
||||||
public WebDecryptResult LoadAssetBundle(WebDecryptFileInfo fileInfo)
|
public WebDecryptResult LoadAssetBundle(WebDecryptFileInfo fileInfo)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -0,0 +1,55 @@
|
|||||||
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
using System.Text;
|
||||||
|
using System.Collections;
|
||||||
|
using UnityEngine;
|
||||||
|
using NUnit.Framework;
|
||||||
|
using YooAsset;
|
||||||
|
|
||||||
|
public class TestManifestEncryption : IManifestServices
|
||||||
|
{
|
||||||
|
public byte[] ProcessManifest(byte[] fileData)
|
||||||
|
{
|
||||||
|
return XorProcess(fileData, "YOO");
|
||||||
|
}
|
||||||
|
public byte[] RestoreManifest(byte[] fileData)
|
||||||
|
{
|
||||||
|
return XorProcess(fileData, "YOO");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 使用异或加密/解密字节数组
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="data">输入数据</param>
|
||||||
|
/// <param name="key">加密密钥</param>
|
||||||
|
/// <returns>处理后的字节数组</returns>
|
||||||
|
public static byte[] XorProcess(byte[] data, byte[] key)
|
||||||
|
{
|
||||||
|
if (data == null)
|
||||||
|
throw new ArgumentNullException(nameof(data));
|
||||||
|
|
||||||
|
if (key == null || key.Length == 0)
|
||||||
|
throw new ArgumentException("Key cannot be null or empty");
|
||||||
|
|
||||||
|
byte[] result = new byte[data.Length];
|
||||||
|
for (int i = 0; i < data.Length; i++)
|
||||||
|
{
|
||||||
|
// 循环使用密钥中的字节
|
||||||
|
result[i] = (byte)(data[i] ^ key[i % key.Length]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 使用字符串密钥进行异或处理(自动转换编码)
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="data">输入数据</param>
|
||||||
|
/// <param name="key">字符串密钥</param>
|
||||||
|
/// <returns>处理后的字节数组</returns>
|
||||||
|
public static byte[] XorProcess(byte[] data, string key)
|
||||||
|
{
|
||||||
|
byte[] keyBytes = System.Text.Encoding.UTF8.GetBytes(key);
|
||||||
|
return XorProcess(data, keyBytes);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 437432f4d3838124085c13253d0c0094
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
Reference in New Issue
Block a user