update test sample
单元测试用例
This commit is contained in:
@@ -0,0 +1,127 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
using UnityEngine.TestTools;
|
||||
using YooAsset;
|
||||
|
||||
public static class AssetBundleCollectorMaker
|
||||
{
|
||||
public static void MakeCollectorSettingData()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
// 清空旧数据
|
||||
YooAsset.Editor.AssetBundleCollectorSettingData.ClearAll();
|
||||
|
||||
// 创建正常文件Package
|
||||
var testPackage = YooAsset.Editor.AssetBundleCollectorSettingData.CreatePackage("TestPackage");
|
||||
testPackage.EnableAddressable = true;
|
||||
testPackage.AutoCollectShaders = true;
|
||||
testPackage.IgnoreRuleName = "NormalIgnoreRule";
|
||||
|
||||
// 音频
|
||||
var audioGroup = YooAsset.Editor.AssetBundleCollectorSettingData.CreateGroup(testPackage, "AudioGroup");
|
||||
{
|
||||
var collector1 = new YooAsset.Editor.AssetBundleCollector();
|
||||
collector1.CollectPath = "";
|
||||
collector1.CollectorGUID = "bbce3e09a17b55c46b5615e995b5fc70"; //TestRes/Audios目录
|
||||
collector1.CollectorType = YooAsset.Editor.ECollectorType.MainAssetCollector;
|
||||
collector1.PackRuleName = nameof(YooAsset.Editor.PackDirectory);
|
||||
YooAsset.Editor.AssetBundleCollectorSettingData.CreateCollector(audioGroup, collector1);
|
||||
}
|
||||
|
||||
// 图片
|
||||
var imageGroup = YooAsset.Editor.AssetBundleCollectorSettingData.CreateGroup(testPackage, "ImageGroup");
|
||||
{
|
||||
var collector1 = new YooAsset.Editor.AssetBundleCollector();
|
||||
collector1.CollectPath = "";
|
||||
collector1.CollectorGUID = "d4768b7c3d3101d4ea693f95b337861d"; //TestRes/Image目录
|
||||
collector1.CollectorType = YooAsset.Editor.ECollectorType.MainAssetCollector;
|
||||
collector1.PackRuleName = nameof(YooAsset.Editor.PackDirectory);
|
||||
YooAsset.Editor.AssetBundleCollectorSettingData.CreateCollector(imageGroup, collector1);
|
||||
}
|
||||
|
||||
// 图集
|
||||
var spriteGroup = YooAsset.Editor.AssetBundleCollectorSettingData.CreateGroup(testPackage, "SpriteGroup");
|
||||
{
|
||||
var collector1 = new YooAsset.Editor.AssetBundleCollector();
|
||||
collector1.CollectPath = "";
|
||||
collector1.CollectorGUID = "634f8145b892c554ba440c212b36a933"; //TestRes/SpriteAtlas目录
|
||||
collector1.CollectorType = YooAsset.Editor.ECollectorType.MainAssetCollector;
|
||||
collector1.PackRuleName = nameof(YooAsset.Editor.PackSeparately);
|
||||
YooAsset.Editor.AssetBundleCollectorSettingData.CreateCollector(spriteGroup, collector1);
|
||||
|
||||
var collector2 = new YooAsset.Editor.AssetBundleCollector();
|
||||
collector2.CollectPath = "";
|
||||
collector2.CollectorGUID = "e41a9b5f04378154f9bd69ac5d52ec44"; //TestRes/Sprites目录
|
||||
collector2.CollectorType = YooAsset.Editor.ECollectorType.StaticAssetCollector;
|
||||
collector2.PackRuleName = nameof(YooAsset.Editor.PackDirectory);
|
||||
YooAsset.Editor.AssetBundleCollectorSettingData.CreateCollector(spriteGroup, collector2);
|
||||
}
|
||||
|
||||
// 预制体
|
||||
var prefabGroup = YooAsset.Editor.AssetBundleCollectorSettingData.CreateGroup(testPackage, "PrefabGroup");
|
||||
{
|
||||
var collector1 = new YooAsset.Editor.AssetBundleCollector();
|
||||
collector1.CollectPath = "";
|
||||
collector1.CollectorGUID = "8da7a00d90270b44898e9b165f86f005"; //TestRes/Prefab目录
|
||||
collector1.CollectorType = YooAsset.Editor.ECollectorType.MainAssetCollector;
|
||||
collector1.PackRuleName = nameof(YooAsset.Editor.PackDirectory);
|
||||
YooAsset.Editor.AssetBundleCollectorSettingData.CreateCollector(prefabGroup, collector1);
|
||||
}
|
||||
|
||||
// 场景
|
||||
var sceneGroup = YooAsset.Editor.AssetBundleCollectorSettingData.CreateGroup(testPackage, "SceneGroup");
|
||||
{
|
||||
var collector1 = new YooAsset.Editor.AssetBundleCollector();
|
||||
collector1.CollectPath = "";
|
||||
collector1.CollectorGUID = "3e169b07999abb0489113f5f4c015c89"; //TestRes/Scene目录
|
||||
collector1.CollectorType = YooAsset.Editor.ECollectorType.MainAssetCollector;
|
||||
collector1.PackRuleName = nameof(YooAsset.Editor.PackSeparately);
|
||||
YooAsset.Editor.AssetBundleCollectorSettingData.CreateCollector(sceneGroup, collector1);
|
||||
}
|
||||
|
||||
// 序列化文件
|
||||
var scriptableObjectGroup = YooAsset.Editor.AssetBundleCollectorSettingData.CreateGroup(testPackage, "ScriptableObjectGroup");
|
||||
{
|
||||
var collector1 = new YooAsset.Editor.AssetBundleCollector();
|
||||
collector1.CollectPath = "";
|
||||
collector1.CollectorGUID = "af885cf1a7abb8c44bd9d139409d2961"; //TestRes/ScriptableObject目录
|
||||
collector1.CollectorType = YooAsset.Editor.ECollectorType.MainAssetCollector;
|
||||
YooAsset.Editor.AssetBundleCollectorSettingData.CreateCollector(scriptableObjectGroup, collector1);
|
||||
}
|
||||
|
||||
// 创建原生文件Package
|
||||
var rawPackage = YooAsset.Editor.AssetBundleCollectorSettingData.CreatePackage("RawPackage");
|
||||
rawPackage.EnableAddressable = true;
|
||||
rawPackage.AutoCollectShaders = true;
|
||||
rawPackage.IgnoreRuleName = "RawFileIgnoreRule";
|
||||
|
||||
// 原生文件
|
||||
var rawFileGroup = YooAsset.Editor.AssetBundleCollectorSettingData.CreateGroup(rawPackage, "RawFileGroup");
|
||||
{
|
||||
var collector1 = new YooAsset.Editor.AssetBundleCollector();
|
||||
collector1.CollectPath = "";
|
||||
collector1.CollectorGUID = "fddaaf9430e24344196cc82ac3d006b4"; //TestRes/RawFiles目录
|
||||
collector1.CollectorType = YooAsset.Editor.ECollectorType.MainAssetCollector;
|
||||
collector1.PackRuleName = nameof(YooAsset.Editor.PackRawFile);
|
||||
YooAsset.Editor.AssetBundleCollectorSettingData.CreateCollector(rawFileGroup, collector1);
|
||||
}
|
||||
|
||||
// 视频文件
|
||||
var videoFileGroup = YooAsset.Editor.AssetBundleCollectorSettingData.CreateGroup(rawPackage, "VideoFileGroup");
|
||||
{
|
||||
var collector1 = new YooAsset.Editor.AssetBundleCollector();
|
||||
collector1.CollectPath = "";
|
||||
collector1.CollectorGUID = "9028a60fd472239448b89453084bfa0a"; //TestRes/Video目录
|
||||
collector1.CollectorType = YooAsset.Editor.ECollectorType.MainAssetCollector;
|
||||
collector1.PackRuleName = nameof(YooAsset.Editor.PackVideoFile);
|
||||
YooAsset.Editor.AssetBundleCollectorSettingData.CreateCollector(videoFileGroup, collector1);
|
||||
}
|
||||
|
||||
// 修正配置路径为空导致的错误
|
||||
YooAsset.Editor.AssetBundleCollectorSettingData.FixFile();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 88e4ec854876f3f40bce38bc880c0f6a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,133 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.U2D;
|
||||
using UnityEngine.TestTools;
|
||||
using NUnit.Framework;
|
||||
using YooAsset;
|
||||
|
||||
public class BuildinFileSystemTester : IPrebuildSetup, IPostBuildCleanup
|
||||
{
|
||||
private const string TEST_PACKAGE_ROOT_KEY = "TEST_PACKAGE_ROOT_KEY";
|
||||
private const string RAW_PACKAGE_ROOT_KEY = "RAW_PACKAGE_ROOT_KEY";
|
||||
|
||||
void IPrebuildSetup.Setup()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
AssetBundleCollectorMaker.MakeCollectorSettingData();
|
||||
|
||||
// 构建TestPackage
|
||||
{
|
||||
var simulateParams = new EditorSimulateBuildParam("TestPackage");
|
||||
simulateParams.BuildPipelineName = "ScriptableBuildPipeline";
|
||||
simulateParams.InvokeAssmeblyName = "YooAsset.Test.Editor";
|
||||
simulateParams.InvokeClassFullName = "TestSimulateBuilder";
|
||||
simulateParams.InvokeMethodName = "SimulateBuild";
|
||||
var simulateResult = EditorSimulateModeHelper.SimulateBuild(simulateParams);
|
||||
UnityEditor.EditorPrefs.SetString(TEST_PACKAGE_ROOT_KEY, simulateResult.PackageRootDirectory);
|
||||
}
|
||||
|
||||
// 构建RawPackage
|
||||
{
|
||||
var simulateParams = new EditorSimulateBuildParam("RawPackage");
|
||||
simulateParams.BuildPipelineName = "RawFileBuildPipeline";
|
||||
simulateParams.InvokeAssmeblyName = "YooAsset.Test.Editor";
|
||||
simulateParams.InvokeClassFullName = "TestSimulateBuilder";
|
||||
simulateParams.InvokeMethodName = "SimulateBuild";
|
||||
var simulateResult = EditorSimulateModeHelper.SimulateBuild(simulateParams);
|
||||
UnityEditor.EditorPrefs.SetString(RAW_PACKAGE_ROOT_KEY, simulateResult.PackageRootDirectory);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
void IPostBuildCleanup.Cleanup()
|
||||
{
|
||||
}
|
||||
|
||||
[UnitySetUp]
|
||||
public virtual IEnumerator RuntimeSetup()
|
||||
{
|
||||
// 初始化YooAsset
|
||||
YooAssets.Initialize();
|
||||
|
||||
// 初始化TestPackage
|
||||
{
|
||||
string packageRoot = string.Empty;
|
||||
#if UNITY_EDITOR
|
||||
packageRoot = UnityEditor.EditorPrefs.GetString(TEST_PACKAGE_ROOT_KEY);
|
||||
#endif
|
||||
if (Directory.Exists(packageRoot) == false)
|
||||
throw new Exception($"Not found package root : {packageRoot}");
|
||||
|
||||
var package = YooAssets.CreatePackage("TestPackage");
|
||||
|
||||
// 初始化资源包
|
||||
var initParams = new OfflinePlayModeParameters();
|
||||
initParams.BuildinFileSystemParameters = FileSystemParameters.CreateDefaultBuildinFileSystemParameters(null, packageRoot);
|
||||
var initializeOp = package.InitializeAsync(initParams);
|
||||
yield return initializeOp;
|
||||
if (initializeOp.Status != EOperationStatus.Succeed)
|
||||
Debug.LogError(initializeOp.Error);
|
||||
Assert.AreEqual(EOperationStatus.Succeed, initializeOp.Status);
|
||||
|
||||
// 请求资源版本
|
||||
var requetVersionOp = package.RequestPackageVersionAsync();
|
||||
yield return requetVersionOp;
|
||||
if (requetVersionOp.Status != EOperationStatus.Succeed)
|
||||
Debug.LogError(requetVersionOp.Error);
|
||||
Assert.AreEqual(EOperationStatus.Succeed, requetVersionOp.Status);
|
||||
|
||||
// 更新资源清单
|
||||
var updateManifestOp = package.UpdatePackageManifestAsync(requetVersionOp.PackageVersion);
|
||||
yield return updateManifestOp;
|
||||
if (updateManifestOp.Status != EOperationStatus.Succeed)
|
||||
Debug.LogError(updateManifestOp.Error);
|
||||
Assert.AreEqual(EOperationStatus.Succeed, updateManifestOp.Status);
|
||||
}
|
||||
|
||||
// 初始化RawPackage
|
||||
{
|
||||
string packageRoot = string.Empty;
|
||||
#if UNITY_EDITOR
|
||||
packageRoot = UnityEditor.EditorPrefs.GetString(RAW_PACKAGE_ROOT_KEY);
|
||||
#endif
|
||||
if (Directory.Exists(packageRoot) == false)
|
||||
throw new Exception($"Not found package root : {packageRoot}");
|
||||
|
||||
var package = YooAssets.CreatePackage("RawPackage");
|
||||
|
||||
// 初始化资源包
|
||||
var initParams = new OfflinePlayModeParameters();
|
||||
initParams.BuildinFileSystemParameters = FileSystemParameters.CreateDefaultBuildinFileSystemParameters(null, packageRoot);
|
||||
initParams.BuildinFileSystemParameters.AddParameter(FileSystemParametersDefine.APPEND_FILE_EXTENSION, true);
|
||||
var initializeOp = package.InitializeAsync(initParams);
|
||||
yield return initializeOp;
|
||||
if (initializeOp.Status != EOperationStatus.Succeed)
|
||||
Debug.LogError(initializeOp.Error);
|
||||
Assert.AreEqual(EOperationStatus.Succeed, initializeOp.Status);
|
||||
|
||||
// 请求资源版本
|
||||
var requetVersionOp = package.RequestPackageVersionAsync();
|
||||
yield return requetVersionOp;
|
||||
if (requetVersionOp.Status != EOperationStatus.Succeed)
|
||||
Debug.LogError(requetVersionOp.Error);
|
||||
Assert.AreEqual(EOperationStatus.Succeed, requetVersionOp.Status);
|
||||
|
||||
// 更新资源清单
|
||||
var updateManifestOp = package.UpdatePackageManifestAsync(requetVersionOp.PackageVersion);
|
||||
yield return updateManifestOp;
|
||||
if (updateManifestOp.Status != EOperationStatus.Succeed)
|
||||
Debug.LogError(updateManifestOp.Error);
|
||||
Assert.AreEqual(EOperationStatus.Succeed, updateManifestOp.Status);
|
||||
}
|
||||
}
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator RuntimeInit()
|
||||
{
|
||||
// 声明该方法可以被自动化流程识别!
|
||||
yield break;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bcc55b0010a446748977341328325575
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
using UnityEngine.TestTools;
|
||||
using YooAsset;
|
||||
|
||||
public class CacheFileSystemTester : IPrebuildSetup, IPostBuildCleanup
|
||||
{
|
||||
public void Setup()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void Cleanup()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a680882da8a6755498514f4fd2210a34
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
using UnityEngine.TestTools;
|
||||
using YooAsset;
|
||||
|
||||
public class EditorFileSystemTester : IPrebuildSetup, IPostBuildCleanup
|
||||
{
|
||||
public void Setup()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void Cleanup()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c2415e48396659e46baabff3fcaad34d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,192 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
using YooAsset;
|
||||
|
||||
/// <summary>
|
||||
/// 资源文件解密流
|
||||
/// </summary>
|
||||
public class BundleStream : FileStream
|
||||
{
|
||||
public const byte KEY = 64;
|
||||
|
||||
public BundleStream(string path, FileMode mode, FileAccess access, FileShare share) : base(path, mode, access, share)
|
||||
{
|
||||
}
|
||||
public BundleStream(string path, FileMode mode) : base(path, mode)
|
||||
{
|
||||
}
|
||||
|
||||
public override int Read(byte[] array, int offset, int count)
|
||||
{
|
||||
var index = base.Read(array, offset, count);
|
||||
for (int i = 0; i < array.Length; i++)
|
||||
{
|
||||
array[i] ^= KEY;
|
||||
}
|
||||
return index;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 资源文件流加载解密类
|
||||
/// </summary>
|
||||
public class FileStreamDecryption : IDecryptionServices
|
||||
{
|
||||
/// <summary>
|
||||
/// 同步方式获取解密的资源包对象
|
||||
/// 注意:加载流对象在资源包对象释放的时候会自动释放
|
||||
/// </summary>
|
||||
DecryptResult IDecryptionServices.LoadAssetBundle(DecryptFileInfo fileInfo)
|
||||
{
|
||||
BundleStream bundleStream = new BundleStream(fileInfo.FileLoadPath, FileMode.Open, FileAccess.Read, FileShare.Read);
|
||||
DecryptResult decryptResult = new DecryptResult();
|
||||
decryptResult.ManagedStream = bundleStream;
|
||||
decryptResult.Result = AssetBundle.LoadFromStream(bundleStream, fileInfo.FileLoadCRC, GetManagedReadBufferSize());
|
||||
return decryptResult;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步方式获取解密的资源包对象
|
||||
/// 注意:加载流对象在资源包对象释放的时候会自动释放
|
||||
/// </summary>
|
||||
DecryptResult IDecryptionServices.LoadAssetBundleAsync(DecryptFileInfo fileInfo)
|
||||
{
|
||||
BundleStream bundleStream = new BundleStream(fileInfo.FileLoadPath, FileMode.Open, FileAccess.Read, FileShare.Read);
|
||||
DecryptResult decryptResult = new DecryptResult();
|
||||
decryptResult.ManagedStream = bundleStream;
|
||||
decryptResult.CreateRequest = AssetBundle.LoadFromStreamAsync(bundleStream, fileInfo.FileLoadCRC, GetManagedReadBufferSize());
|
||||
return decryptResult;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取解密的字节数据
|
||||
/// </summary>
|
||||
byte[] IDecryptionServices.ReadFileData(DecryptFileInfo fileInfo)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取解密的文本数据
|
||||
/// </summary>
|
||||
string IDecryptionServices.ReadFileText(DecryptFileInfo fileInfo)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
private static uint GetManagedReadBufferSize()
|
||||
{
|
||||
return 1024;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 资源文件偏移加载解密类
|
||||
/// </summary>
|
||||
public class FileOffsetDecryption : IDecryptionServices
|
||||
{
|
||||
/// <summary>
|
||||
/// 同步方式获取解密的资源包对象
|
||||
/// 注意:加载流对象在资源包对象释放的时候会自动释放
|
||||
/// </summary>
|
||||
DecryptResult IDecryptionServices.LoadAssetBundle(DecryptFileInfo fileInfo)
|
||||
{
|
||||
DecryptResult decryptResult = new DecryptResult();
|
||||
decryptResult.ManagedStream = null;
|
||||
decryptResult.Result = AssetBundle.LoadFromFile(fileInfo.FileLoadPath, fileInfo.FileLoadCRC, GetFileOffset());
|
||||
return decryptResult;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步方式获取解密的资源包对象
|
||||
/// 注意:加载流对象在资源包对象释放的时候会自动释放
|
||||
/// </summary>
|
||||
DecryptResult IDecryptionServices.LoadAssetBundleAsync(DecryptFileInfo fileInfo)
|
||||
{
|
||||
DecryptResult decryptResult = new DecryptResult();
|
||||
decryptResult.ManagedStream = null;
|
||||
decryptResult.CreateRequest = AssetBundle.LoadFromFileAsync(fileInfo.FileLoadPath, fileInfo.FileLoadCRC, GetFileOffset());
|
||||
return decryptResult;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取解密的字节数据
|
||||
/// </summary>
|
||||
byte[] IDecryptionServices.ReadFileData(DecryptFileInfo fileInfo)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取解密的文本数据
|
||||
/// </summary>
|
||||
string IDecryptionServices.ReadFileText(DecryptFileInfo fileInfo)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
private static ulong GetFileOffset()
|
||||
{
|
||||
return 32;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 文件偏移加密方式
|
||||
/// </summary>
|
||||
public class FileOffsetEncryption : IEncryptionServices
|
||||
{
|
||||
public EncryptResult Encrypt(EncryptFileInfo fileInfo)
|
||||
{
|
||||
// 注意:只对音频资源包加密
|
||||
if (fileInfo.BundleName.Contains("_gameres_audio"))
|
||||
{
|
||||
int offset = 32;
|
||||
byte[] fileData = File.ReadAllBytes(fileInfo.FileLoadPath);
|
||||
var encryptedData = new byte[fileData.Length + offset];
|
||||
Buffer.BlockCopy(fileData, 0, encryptedData, offset, fileData.Length);
|
||||
|
||||
EncryptResult result = new EncryptResult();
|
||||
result.Encrypted = true;
|
||||
result.EncryptedData = encryptedData;
|
||||
return result;
|
||||
}
|
||||
else
|
||||
{
|
||||
EncryptResult result = new EncryptResult();
|
||||
result.Encrypted = false;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 文件流加密方式
|
||||
/// </summary>
|
||||
public class FileStreamEncryption : IEncryptionServices
|
||||
{
|
||||
public EncryptResult Encrypt(EncryptFileInfo fileInfo)
|
||||
{
|
||||
if (fileInfo.BundleName.Contains("_gameres_audio"))
|
||||
{
|
||||
var fileData = File.ReadAllBytes(fileInfo.FileLoadPath);
|
||||
for (int i = 0; i < fileData.Length; i++)
|
||||
{
|
||||
fileData[i] ^= BundleStream.KEY;
|
||||
}
|
||||
|
||||
EncryptResult result = new EncryptResult();
|
||||
result.Encrypted = true;
|
||||
result.EncryptedData = fileData;
|
||||
return result;
|
||||
}
|
||||
else
|
||||
{
|
||||
EncryptResult result = new EncryptResult();
|
||||
result.Encrypted = false;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4e7786f8fc24d464d89b91d575076759
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,40 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.U2D;
|
||||
using UnityEngine.TestTools;
|
||||
using NUnit.Framework;
|
||||
using YooAsset;
|
||||
|
||||
public class TestLoadAudio
|
||||
{
|
||||
[UnityTest]
|
||||
public IEnumerator RuntimeTester()
|
||||
{
|
||||
ResourcePackage package = YooAssets.GetPackage("TestPackage");
|
||||
Assert.IsNotNull(package);
|
||||
|
||||
// 音乐
|
||||
{
|
||||
var assetHandle = package.LoadAssetAsync<AudioClip>("music_a");
|
||||
yield return assetHandle;
|
||||
Assert.AreEqual(EOperationStatus.Succeed, assetHandle.Status);
|
||||
|
||||
var audioClip = assetHandle.AssetObject as AudioClip;
|
||||
Assert.IsNotNull(audioClip);
|
||||
}
|
||||
|
||||
// 音效
|
||||
{
|
||||
var assetHandle = package.LoadAssetAsync<AudioClip>("sound_a");
|
||||
yield return assetHandle;
|
||||
Assert.AreEqual(EOperationStatus.Succeed, assetHandle.Status);
|
||||
|
||||
var audioClip = assetHandle.AssetObject as AudioClip;
|
||||
Assert.IsNotNull(audioClip);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f4add568c6b99dd439ae31ab4953d0a2
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,30 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.U2D;
|
||||
using UnityEngine.TestTools;
|
||||
using NUnit.Framework;
|
||||
using YooAsset;
|
||||
|
||||
public class TestLoadImage
|
||||
{
|
||||
[UnityTest]
|
||||
public IEnumerator RuntimeTester()
|
||||
{
|
||||
ResourcePackage package = YooAssets.GetPackage("TestPackage");
|
||||
Assert.IsNotNull(package);
|
||||
|
||||
var subAssetsHandle = package.LoadSubAssetsAsync<Sprite>("image_a");
|
||||
yield return subAssetsHandle;
|
||||
Assert.AreEqual(EOperationStatus.Succeed, subAssetsHandle.Status);
|
||||
|
||||
var subAssetObjects = subAssetsHandle.SubAssetObjects;
|
||||
Assert.IsNotNull(subAssetObjects);
|
||||
|
||||
int count = subAssetObjects.Count;
|
||||
Assert.AreEqual(count, 3);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6414488620921db45a18cb6f333addb2
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,48 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.U2D;
|
||||
using UnityEngine.TestTools;
|
||||
using NUnit.Framework;
|
||||
using YooAsset;
|
||||
|
||||
public class TestLoadPrefab
|
||||
{
|
||||
[UnityTest]
|
||||
public IEnumerator RuntimeTester()
|
||||
{
|
||||
ResourcePackage package = YooAssets.GetPackage("TestPackage");
|
||||
Assert.IsNotNull(package);
|
||||
|
||||
// 加载所有预制体
|
||||
{
|
||||
var allAssetsHandle = package.LoadAllAssetsAsync<GameObject>("prefab_a");
|
||||
yield return allAssetsHandle;
|
||||
Assert.AreEqual(EOperationStatus.Succeed, allAssetsHandle.Status);
|
||||
|
||||
var allAssetObjects = allAssetsHandle.AllAssetObjects;
|
||||
Assert.IsNotNull(allAssetObjects);
|
||||
|
||||
int count = allAssetObjects.Count;
|
||||
Assert.AreEqual(count, 3);
|
||||
}
|
||||
|
||||
// 加载指定预制体
|
||||
{
|
||||
var assetsHandle = package.LoadAssetAsync<GameObject>("prefab_a");
|
||||
yield return assetsHandle;
|
||||
Assert.AreEqual(EOperationStatus.Succeed, assetsHandle.Status);
|
||||
Assert.IsNotNull(assetsHandle.AssetObject);
|
||||
|
||||
var instantiateOp = assetsHandle.InstantiateAsync();
|
||||
yield return instantiateOp;
|
||||
Assert.AreEqual(EOperationStatus.Succeed, instantiateOp.Status);
|
||||
|
||||
Assert.IsNotNull(instantiateOp.Result);
|
||||
TestLogger.Log(this, instantiateOp.Result.name);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 270615370ad21dc499a435e9bbc09269
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,53 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.U2D;
|
||||
using UnityEngine.TestTools;
|
||||
using NUnit.Framework;
|
||||
using YooAsset;
|
||||
|
||||
public class TestLoadRawFile
|
||||
{
|
||||
[UnityTest]
|
||||
public IEnumerator RuntimeTester()
|
||||
{
|
||||
ResourcePackage package = YooAssets.GetPackage("RawPackage");
|
||||
Assert.IsNotNull(package);
|
||||
|
||||
// 测试异步加载
|
||||
{
|
||||
var rawFileHandle = package.LoadRawFileAsync("raw_file_a");
|
||||
yield return rawFileHandle;
|
||||
Assert.AreEqual(EOperationStatus.Succeed, rawFileHandle.Status);
|
||||
|
||||
var filePath = rawFileHandle.GetRawFilePath();
|
||||
Assert.IsNotNull(filePath);
|
||||
|
||||
var fileText = rawFileHandle.GetRawFileText();
|
||||
TestLogger.Log(this, fileText);
|
||||
Assert.IsNotNull(fileText);
|
||||
|
||||
var fileData = rawFileHandle.GetRawFileData();
|
||||
Assert.IsNotNull(fileData);
|
||||
}
|
||||
|
||||
// 测试同步加载
|
||||
{
|
||||
var rawFileHandle = package.LoadRawFileSync("raw_file_b");
|
||||
Assert.AreEqual(EOperationStatus.Succeed, rawFileHandle.Status);
|
||||
|
||||
var filePath = rawFileHandle.GetRawFilePath();
|
||||
Assert.IsNotNull(filePath);
|
||||
|
||||
var fileText = rawFileHandle.GetRawFileText();
|
||||
TestLogger.Log(this, fileText);
|
||||
Assert.IsNotNull(fileText);
|
||||
|
||||
var fileData = rawFileHandle.GetRawFileData();
|
||||
Assert.IsNotNull(fileData);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 24f8c082eecb6c042879f5913356e3b3
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,53 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.U2D;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEngine.TestTools;
|
||||
using NUnit.Framework;
|
||||
using YooAsset;
|
||||
|
||||
public class TestLoadScene
|
||||
{
|
||||
[UnityTest]
|
||||
public IEnumerator RuntimeTester()
|
||||
{
|
||||
ResourcePackage package = YooAssets.GetPackage("TestPackage");
|
||||
Assert.IsNotNull(package);
|
||||
|
||||
// 主场景
|
||||
{
|
||||
var sceneHandle = package.LoadSceneAsync("scene_a", LoadSceneMode.Single);
|
||||
yield return sceneHandle;
|
||||
Assert.AreEqual(EOperationStatus.Succeed, sceneHandle.Status);
|
||||
|
||||
var scene = sceneHandle.SceneObject;
|
||||
Assert.IsNotNull(scene);
|
||||
}
|
||||
|
||||
// 附加场景
|
||||
yield return new WaitForSeconds(1f);
|
||||
{
|
||||
var sceneHandle = package.LoadSceneAsync("scene_b", LoadSceneMode.Additive);
|
||||
yield return sceneHandle;
|
||||
Assert.AreEqual(EOperationStatus.Succeed, sceneHandle.Status);
|
||||
|
||||
var scene = sceneHandle.SceneObject;
|
||||
Assert.IsNotNull(scene);
|
||||
}
|
||||
|
||||
// 主场景
|
||||
yield return new WaitForSeconds(1f);
|
||||
{
|
||||
var sceneHandle = package.LoadSceneAsync("scene_c", LoadSceneMode.Single);
|
||||
yield return sceneHandle;
|
||||
Assert.AreEqual(EOperationStatus.Succeed, sceneHandle.Status);
|
||||
|
||||
var scene = sceneHandle.SceneObject;
|
||||
Assert.IsNotNull(scene);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0d2de990b8132d043ac9e9b3c3cc881f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,28 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.U2D;
|
||||
using UnityEngine.TestTools;
|
||||
using NUnit.Framework;
|
||||
using YooAsset;
|
||||
|
||||
public class TestLoadScriptableObject
|
||||
{
|
||||
[UnityTest]
|
||||
public IEnumerator RuntimeTester()
|
||||
{
|
||||
ResourcePackage package = YooAssets.GetPackage("TestPackage");
|
||||
Assert.IsNotNull(package);
|
||||
|
||||
var assetHandle = package.LoadAssetAsync("game_config");
|
||||
yield return assetHandle;
|
||||
Assert.AreEqual(EOperationStatus.Succeed, assetHandle.Status);
|
||||
|
||||
var testScriptableObject = assetHandle.AssetObject as TestScriptableObject;
|
||||
Assert.IsNotNull(testScriptableObject);
|
||||
TestLogger.Log(this, testScriptableObject.ConfigName);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 047c3635b9a26d7438f1cbb0c22cffaf
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,36 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.U2D;
|
||||
using UnityEngine.TestTools;
|
||||
using NUnit.Framework;
|
||||
using YooAsset;
|
||||
|
||||
public class TestLoadSpriteAtlas
|
||||
{
|
||||
[UnityTest]
|
||||
public IEnumerator RuntimeTester()
|
||||
{
|
||||
ResourcePackage package = YooAssets.GetPackage("TestPackage");
|
||||
Assert.IsNotNull(package);
|
||||
|
||||
var assetHandle = package.LoadAssetAsync<SpriteAtlas>("atlas_icon");
|
||||
yield return assetHandle;
|
||||
Assert.AreEqual(EOperationStatus.Succeed, assetHandle.Status);
|
||||
|
||||
var spriteAtals = assetHandle.AssetObject as SpriteAtlas;
|
||||
Assert.IsNotNull(spriteAtals);
|
||||
|
||||
var sprite1 = spriteAtals.GetSprite("bullet");
|
||||
Assert.IsNotNull(sprite1);
|
||||
|
||||
var sprite2 = spriteAtals.GetSprite("pause");
|
||||
Assert.IsNotNull(sprite2);
|
||||
|
||||
var sprite3 = spriteAtals.GetSprite("rocket");
|
||||
Assert.IsNotNull(sprite3);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: acd8842a73aab574584f1c9676f0b46f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,40 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.U2D;
|
||||
using UnityEngine.TestTools;
|
||||
using NUnit.Framework;
|
||||
using YooAsset;
|
||||
using UnityEngine.Video;
|
||||
|
||||
public class TestLoadVideo
|
||||
{
|
||||
[UnityTest]
|
||||
public IEnumerator RuntimeTester()
|
||||
{
|
||||
ResourcePackage package = YooAssets.GetPackage("RawPackage");
|
||||
Assert.IsNotNull(package);
|
||||
|
||||
var rawFileHandle = package.LoadRawFileAsync("video_logo");
|
||||
yield return rawFileHandle;
|
||||
Assert.AreEqual(EOperationStatus.Succeed, rawFileHandle.Status);
|
||||
|
||||
// 获取视频文件地址
|
||||
string videoFilePath = rawFileHandle.GetRawFilePath();
|
||||
Assert.IsTrue(File.Exists(videoFilePath));
|
||||
|
||||
// 创建预制体播放视频
|
||||
GameObject go = new GameObject("video player");
|
||||
var videoPlayer = go.AddComponent<VideoPlayer>();
|
||||
videoPlayer.source = VideoSource.Url;
|
||||
videoPlayer.renderMode = VideoRenderMode.APIOnly;
|
||||
videoPlayer.url = videoFilePath;
|
||||
videoPlayer.Play();
|
||||
|
||||
yield return new WaitForSeconds(1f);
|
||||
Assert.IsTrue(videoPlayer.isPlaying);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0ec434834a510eb4d823b786b2b83927
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
|
||||
public static class TestLogger
|
||||
{
|
||||
public static void Log(System.Object instance, string message)
|
||||
{
|
||||
UnityEngine.Debug.Log($"[{instance.GetType().Name}] {message}");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c956aea1eb6a9764abb5c9ada33a7bb3
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
using UnityEngine.TestTools;
|
||||
using YooAsset;
|
||||
|
||||
// 自定义的配置文件
|
||||
public class TestScriptableObject : ScriptableObject
|
||||
{
|
||||
public string ConfigName = "yoo";
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 11ddf12cbeb412347957744c69cfc3b6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"name": "YooAsset.Test",
|
||||
"rootNamespace": "",
|
||||
"references": [
|
||||
"YooAsset",
|
||||
"YooAsset.Editor",
|
||||
"UnityEngine.TestRunner",
|
||||
"UnityEditor.TestRunner"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": true,
|
||||
"precompiledReferences": [
|
||||
"nunit.framework.dll"
|
||||
],
|
||||
"autoReferenced": false,
|
||||
"defineConstraints": [
|
||||
"UNITY_INCLUDE_TESTS"
|
||||
],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 70c128f3a165dff44be2ed31f1431ddd
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user