update test sample

pull/455/head
何冠峰 2025-01-03 17:27:04 +08:00
parent 6bf8e3643b
commit 8ff16f7205
26 changed files with 680 additions and 75 deletions

View File

@ -22,7 +22,7 @@ public static class TestSimulateBuilder
buildParameters.BuildBundleType = (int)EBuildBundleType.VirtualBundle; buildParameters.BuildBundleType = (int)EBuildBundleType.VirtualBundle;
buildParameters.BuildTarget = EditorUserBuildSettings.activeBuildTarget; buildParameters.BuildTarget = EditorUserBuildSettings.activeBuildTarget;
buildParameters.PackageName = packageName; buildParameters.PackageName = packageName;
buildParameters.PackageVersion = "Simulate"; buildParameters.PackageVersion = "ESBP_Simulate";
buildParameters.FileNameStyle = EFileNameStyle.HashName; buildParameters.FileNameStyle = EFileNameStyle.HashName;
buildParameters.BuildinFileCopyOption = EBuildinFileCopyOption.None; buildParameters.BuildinFileCopyOption = EBuildinFileCopyOption.None;
buildParameters.BuildinFileCopyParams = string.Empty; buildParameters.BuildinFileCopyParams = string.Empty;
@ -50,7 +50,7 @@ public static class TestSimulateBuilder
buildParameters.BuildBundleType = (int)EBuildBundleType.AssetBundle; buildParameters.BuildBundleType = (int)EBuildBundleType.AssetBundle;
buildParameters.BuildTarget = EditorUserBuildSettings.activeBuildTarget; buildParameters.BuildTarget = EditorUserBuildSettings.activeBuildTarget;
buildParameters.PackageName = packageName; buildParameters.PackageName = packageName;
buildParameters.PackageVersion = "Simulate"; buildParameters.PackageVersion = "SBP_Simulate";
buildParameters.EnableSharePackRule = true; buildParameters.EnableSharePackRule = true;
buildParameters.VerifyBuildingResult = true; buildParameters.VerifyBuildingResult = true;
buildParameters.FileNameStyle = EFileNameStyle.HashName; buildParameters.FileNameStyle = EFileNameStyle.HashName;
@ -83,7 +83,7 @@ public static class TestSimulateBuilder
buildParameters.BuildBundleType = (int)EBuildBundleType.AssetBundle; buildParameters.BuildBundleType = (int)EBuildBundleType.AssetBundle;
buildParameters.BuildTarget = EditorUserBuildSettings.activeBuildTarget; buildParameters.BuildTarget = EditorUserBuildSettings.activeBuildTarget;
buildParameters.PackageName = packageName; buildParameters.PackageName = packageName;
buildParameters.PackageVersion = "Simulate"; buildParameters.PackageVersion = "BBP_Simulate";
buildParameters.EnableSharePackRule = true; buildParameters.EnableSharePackRule = true;
buildParameters.VerifyBuildingResult = true; buildParameters.VerifyBuildingResult = true;
buildParameters.FileNameStyle = EFileNameStyle.HashName; buildParameters.FileNameStyle = EFileNameStyle.HashName;
@ -116,7 +116,7 @@ public static class TestSimulateBuilder
buildParameters.BuildBundleType = (int)EBuildBundleType.RawBundle; buildParameters.BuildBundleType = (int)EBuildBundleType.RawBundle;
buildParameters.BuildTarget = EditorUserBuildSettings.activeBuildTarget; buildParameters.BuildTarget = EditorUserBuildSettings.activeBuildTarget;
buildParameters.PackageName = packageName; buildParameters.PackageName = packageName;
buildParameters.PackageVersion = "Simulate"; buildParameters.PackageVersion = "RFBP_Simulate";
buildParameters.VerifyBuildingResult = true; buildParameters.VerifyBuildingResult = true;
buildParameters.FileNameStyle = EFileNameStyle.HashName; buildParameters.FileNameStyle = EFileNameStyle.HashName;
buildParameters.BuildinFileCopyOption = EBuildinFileCopyOption.None; buildParameters.BuildinFileCopyOption = EBuildinFileCopyOption.None;

View File

@ -0,0 +1,6 @@

public class AssetBundleCollectorDefine
{
public const string TestPackageName = "TestPackage";
public const string RawPackageName = "RawPackage";
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 4b69d1ce3e025474e84dd43b10068740
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -15,7 +15,7 @@ public static class AssetBundleCollectorMaker
YooAsset.Editor.AssetBundleCollectorSettingData.ClearAll(); YooAsset.Editor.AssetBundleCollectorSettingData.ClearAll();
// 创建正常文件Package // 创建正常文件Package
var testPackage = YooAsset.Editor.AssetBundleCollectorSettingData.CreatePackage("TestPackage"); var testPackage = YooAsset.Editor.AssetBundleCollectorSettingData.CreatePackage(AssetBundleCollectorDefine.TestPackageName);
testPackage.EnableAddressable = true; testPackage.EnableAddressable = true;
testPackage.AutoCollectShaders = true; testPackage.AutoCollectShaders = true;
testPackage.IgnoreRuleName = "NormalIgnoreRule"; testPackage.IgnoreRuleName = "NormalIgnoreRule";
@ -27,7 +27,7 @@ public static class AssetBundleCollectorMaker
collector1.CollectPath = ""; collector1.CollectPath = "";
collector1.CollectorGUID = "bbce3e09a17b55c46b5615e995b5fc70"; //TestRes/Audios目录 collector1.CollectorGUID = "bbce3e09a17b55c46b5615e995b5fc70"; //TestRes/Audios目录
collector1.CollectorType = YooAsset.Editor.ECollectorType.MainAssetCollector; collector1.CollectorType = YooAsset.Editor.ECollectorType.MainAssetCollector;
collector1.PackRuleName = nameof(YooAsset.Editor.PackDirectory); collector1.PackRuleName = nameof(YooAsset.Editor.PackSeparately);
YooAsset.Editor.AssetBundleCollectorSettingData.CreateCollector(audioGroup, collector1); YooAsset.Editor.AssetBundleCollectorSettingData.CreateCollector(audioGroup, collector1);
} }
@ -38,7 +38,7 @@ public static class AssetBundleCollectorMaker
collector1.CollectPath = ""; collector1.CollectPath = "";
collector1.CollectorGUID = "d4768b7c3d3101d4ea693f95b337861d"; //TestRes/Image目录 collector1.CollectorGUID = "d4768b7c3d3101d4ea693f95b337861d"; //TestRes/Image目录
collector1.CollectorType = YooAsset.Editor.ECollectorType.MainAssetCollector; collector1.CollectorType = YooAsset.Editor.ECollectorType.MainAssetCollector;
collector1.PackRuleName = nameof(YooAsset.Editor.PackDirectory); collector1.PackRuleName = nameof(YooAsset.Editor.PackSeparately);
YooAsset.Editor.AssetBundleCollectorSettingData.CreateCollector(imageGroup, collector1); YooAsset.Editor.AssetBundleCollectorSettingData.CreateCollector(imageGroup, collector1);
} }
@ -89,11 +89,12 @@ public static class AssetBundleCollectorMaker
collector1.CollectPath = ""; collector1.CollectPath = "";
collector1.CollectorGUID = "af885cf1a7abb8c44bd9d139409d2961"; //TestRes/ScriptableObject目录 collector1.CollectorGUID = "af885cf1a7abb8c44bd9d139409d2961"; //TestRes/ScriptableObject目录
collector1.CollectorType = YooAsset.Editor.ECollectorType.MainAssetCollector; collector1.CollectorType = YooAsset.Editor.ECollectorType.MainAssetCollector;
collector1.PackRuleName = nameof(YooAsset.Editor.PackSeparately);
YooAsset.Editor.AssetBundleCollectorSettingData.CreateCollector(scriptableObjectGroup, collector1); YooAsset.Editor.AssetBundleCollectorSettingData.CreateCollector(scriptableObjectGroup, collector1);
} }
// 创建原生文件Package // 创建原生文件Package
var rawPackage = YooAsset.Editor.AssetBundleCollectorSettingData.CreatePackage("RawPackage"); var rawPackage = YooAsset.Editor.AssetBundleCollectorSettingData.CreatePackage(AssetBundleCollectorDefine.RawPackageName);
rawPackage.EnableAddressable = true; rawPackage.EnableAddressable = true;
rawPackage.AutoCollectShaders = true; rawPackage.AutoCollectShaders = true;
rawPackage.IgnoreRuleName = "RawFileIgnoreRule"; rawPackage.IgnoreRuleName = "RawFileIgnoreRule";

View File

@ -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 AssetBundleCollectorPreapre : IPrebuildSetup, IPostBuildCleanup
{
void IPrebuildSetup.Setup()
{
AssetBundleCollectorMaker.MakeCollectorSettingData();
}
void IPostBuildCleanup.Cleanup()
{
}
[Test]
public void InitializeYooAssets()
{
// 初始化YooAsset
YooAssets.Initialize();
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 07f7c95e8e42fd04f81b9925b2dcf0d0
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -11,57 +11,52 @@ using YooAsset;
public class BuildinFileSystemTester : IPrebuildSetup, IPostBuildCleanup public class BuildinFileSystemTester : IPrebuildSetup, IPostBuildCleanup
{ {
private const string TEST_PACKAGE_ROOT_KEY = "TEST_PACKAGE_ROOT_KEY"; private const string BFS_TEST_PACKAGE_ROOT_KEY = "BFS_TEST_PACKAGE_ROOT_KEY";
private const string RAW_PACKAGE_ROOT_KEY = "RAW_PACKAGE_ROOT_KEY"; private const string BFS_RAW_PACKAGE_ROOT_KEY = "BFS_RAW_PACKAGE_ROOT_KEY";
void IPrebuildSetup.Setup() void IPrebuildSetup.Setup()
{ {
#if UNITY_EDITOR #if UNITY_EDITOR
AssetBundleCollectorMaker.MakeCollectorSettingData();
// 构建TestPackage // 构建TestPackage
{ {
var simulateParams = new EditorSimulateBuildParam("TestPackage"); var simulateParams = new EditorSimulateBuildParam(AssetBundleCollectorDefine.TestPackageName);
simulateParams.BuildPipelineName = "ScriptableBuildPipeline"; simulateParams.BuildPipelineName = "ScriptableBuildPipeline";
simulateParams.InvokeAssmeblyName = "YooAsset.Test.Editor"; simulateParams.InvokeAssmeblyName = "YooAsset.Test.Editor";
simulateParams.InvokeClassFullName = "TestSimulateBuilder"; simulateParams.InvokeClassFullName = "TestSimulateBuilder";
simulateParams.InvokeMethodName = "SimulateBuild"; simulateParams.InvokeMethodName = "SimulateBuild";
var simulateResult = EditorSimulateModeHelper.SimulateBuild(simulateParams); var simulateResult = EditorSimulateModeHelper.SimulateBuild(simulateParams);
UnityEditor.EditorPrefs.SetString(TEST_PACKAGE_ROOT_KEY, simulateResult.PackageRootDirectory); UnityEditor.EditorPrefs.SetString(BFS_TEST_PACKAGE_ROOT_KEY, simulateResult.PackageRootDirectory);
} }
// 构建RawPackage // 构建RawPackage
{ {
var simulateParams = new EditorSimulateBuildParam("RawPackage"); var simulateParams = new EditorSimulateBuildParam(AssetBundleCollectorDefine.RawPackageName);
simulateParams.BuildPipelineName = "RawFileBuildPipeline"; simulateParams.BuildPipelineName = "RawFileBuildPipeline";
simulateParams.InvokeAssmeblyName = "YooAsset.Test.Editor"; simulateParams.InvokeAssmeblyName = "YooAsset.Test.Editor";
simulateParams.InvokeClassFullName = "TestSimulateBuilder"; simulateParams.InvokeClassFullName = "TestSimulateBuilder";
simulateParams.InvokeMethodName = "SimulateBuild"; simulateParams.InvokeMethodName = "SimulateBuild";
var simulateResult = EditorSimulateModeHelper.SimulateBuild(simulateParams); var simulateResult = EditorSimulateModeHelper.SimulateBuild(simulateParams);
UnityEditor.EditorPrefs.SetString(RAW_PACKAGE_ROOT_KEY, simulateResult.PackageRootDirectory); UnityEditor.EditorPrefs.SetString(BFS_RAW_PACKAGE_ROOT_KEY, simulateResult.PackageRootDirectory);
} }
#endif #endif
} }
void IPostBuildCleanup.Cleanup() void IPostBuildCleanup.Cleanup()
{ {
} }
[UnitySetUp] [UnityTest]
public virtual IEnumerator RuntimeSetup() public IEnumerator InitializePackage()
{ {
// 初始化YooAsset
YooAssets.Initialize();
// 初始化TestPackage // 初始化TestPackage
{ {
string packageRoot = string.Empty; string packageRoot = string.Empty;
#if UNITY_EDITOR #if UNITY_EDITOR
packageRoot = UnityEditor.EditorPrefs.GetString(TEST_PACKAGE_ROOT_KEY); packageRoot = UnityEditor.EditorPrefs.GetString(BFS_TEST_PACKAGE_ROOT_KEY);
#endif #endif
if (Directory.Exists(packageRoot) == false) if (Directory.Exists(packageRoot) == false)
throw new Exception($"Not found package root : {packageRoot}"); throw new Exception($"Not found package root : {packageRoot}");
var package = YooAssets.CreatePackage("TestPackage"); var package = YooAssets.CreatePackage(AssetBundleCollectorDefine.TestPackageName);
// 初始化资源包 // 初始化资源包
var initParams = new OfflinePlayModeParameters(); var initParams = new OfflinePlayModeParameters();
@ -91,12 +86,12 @@ public class BuildinFileSystemTester : IPrebuildSetup, IPostBuildCleanup
{ {
string packageRoot = string.Empty; string packageRoot = string.Empty;
#if UNITY_EDITOR #if UNITY_EDITOR
packageRoot = UnityEditor.EditorPrefs.GetString(RAW_PACKAGE_ROOT_KEY); packageRoot = UnityEditor.EditorPrefs.GetString(BFS_RAW_PACKAGE_ROOT_KEY);
#endif #endif
if (Directory.Exists(packageRoot) == false) if (Directory.Exists(packageRoot) == false)
throw new Exception($"Not found package root : {packageRoot}"); throw new Exception($"Not found package root : {packageRoot}");
var package = YooAssets.CreatePackage("RawPackage"); var package = YooAssets.CreatePackage(AssetBundleCollectorDefine.RawPackageName);
// 初始化资源包 // 初始化资源包
var initParams = new OfflinePlayModeParameters(); var initParams = new OfflinePlayModeParameters();
@ -125,9 +120,58 @@ public class BuildinFileSystemTester : IPrebuildSetup, IPostBuildCleanup
} }
[UnityTest] [UnityTest]
public IEnumerator RuntimeInit() public IEnumerator TestLoadAudio()
{ {
// 声明该方法可以被自动化流程识别! var tester = new TestLoadAudio();
yield break; yield return tester.RuntimeTester();
}
[UnityTest]
public IEnumerator TestLoadImage()
{
var tester = new TestLoadImage();
yield return tester.RuntimeTester();
}
[UnityTest]
public IEnumerator TestLoadPrefab()
{
var tester = new TestLoadPrefab();
yield return tester.RuntimeTester();
}
[UnityTest]
public IEnumerator TestLoadScene()
{
var tester = new TestLoadScene();
yield return tester.RuntimeTester();
}
[UnityTest]
public IEnumerator TestLoadScriptableObject()
{
var tester = new TestLoadScriptableObject();
yield return tester.RuntimeTester();
}
[UnityTest]
public IEnumerator TestLoadSpriteAtlas()
{
var tester = new TestLoadSpriteAtlas();
yield return tester.RuntimeTester();
}
[UnityTest]
public IEnumerator TestLoadRawFile()
{
var tester = new TestLoadRawFile();
yield return tester.RuntimeTester();
}
[UnityTest]
public IEnumerator TestLoadVideo()
{
var tester = new TestLoadVideo();
yield return tester.RuntimeTester();
} }
} }

View File

@ -3,18 +3,204 @@ using System.IO;
using System.Text; using System.Text;
using System.Collections; using System.Collections;
using UnityEngine; using UnityEngine;
using UnityEngine.UI;
using UnityEngine.U2D;
using UnityEngine.TestTools; using UnityEngine.TestTools;
using NUnit.Framework;
using YooAsset; using YooAsset;
public class EditorFileSystemTester : IPrebuildSetup, IPostBuildCleanup public class EditorFileSystemTester : IPrebuildSetup, IPostBuildCleanup
{ {
public void Setup() private const string EFS_TEST_PACKAGE_ROOT_KEY = "EFS_TEST_PACKAGE_ROOT_KEY";
private const string EFS_RAW_PACKAGE_ROOT_KEY = "EFS_RAW_PACKAGE_ROOT_KEY";
void IPrebuildSetup.Setup()
{
#if UNITY_EDITOR
// 构建TestPackage
{
var simulateParams = new EditorSimulateBuildParam(AssetBundleCollectorDefine.TestPackageName);
simulateParams.BuildPipelineName = "EditorSimulateBuildPipeline";
simulateParams.InvokeAssmeblyName = "YooAsset.Test.Editor";
simulateParams.InvokeClassFullName = "TestSimulateBuilder";
simulateParams.InvokeMethodName = "SimulateBuild";
var simulateResult = EditorSimulateModeHelper.SimulateBuild(simulateParams);
UnityEditor.EditorPrefs.SetString(EFS_TEST_PACKAGE_ROOT_KEY, simulateResult.PackageRootDirectory);
}
// 构建RawPackage
{
var simulateParams = new EditorSimulateBuildParam(AssetBundleCollectorDefine.RawPackageName);
simulateParams.BuildPipelineName = "EditorSimulateBuildPipeline";
simulateParams.InvokeAssmeblyName = "YooAsset.Test.Editor";
simulateParams.InvokeClassFullName = "TestSimulateBuilder";
simulateParams.InvokeMethodName = "SimulateBuild";
var simulateResult = EditorSimulateModeHelper.SimulateBuild(simulateParams);
UnityEditor.EditorPrefs.SetString(EFS_RAW_PACKAGE_ROOT_KEY, simulateResult.PackageRootDirectory);
}
#endif
}
void IPostBuildCleanup.Cleanup()
{ {
throw new NotImplementedException();
} }
public void Cleanup() [UnityTest]
public IEnumerator DestroyPackage()
{ {
throw new NotImplementedException(); // 销毁旧资源包
{
var package = YooAssets.GetPackage(AssetBundleCollectorDefine.TestPackageName);
var destroyOp = package.DestroyAsync();
yield return destroyOp;
if (destroyOp.Status != EOperationStatus.Succeed)
Debug.LogError(destroyOp.Error);
Assert.AreEqual(EOperationStatus.Succeed, destroyOp.Status);
bool result = YooAssets.RemovePackage(AssetBundleCollectorDefine.TestPackageName);
Assert.IsTrue(result);
}
// 销毁旧资源包
{
var package = YooAssets.GetPackage(AssetBundleCollectorDefine.RawPackageName);
var destroyOp = package.DestroyAsync();
yield return destroyOp;
if (destroyOp.Status != EOperationStatus.Succeed)
Debug.LogError(destroyOp.Error);
Assert.AreEqual(EOperationStatus.Succeed, destroyOp.Status);
bool result = YooAssets.RemovePackage(AssetBundleCollectorDefine.RawPackageName);
Assert.IsTrue(result);
}
}
[UnityTest]
public IEnumerator InitializePackage()
{
// 初始化TestPackage
{
string packageRoot = string.Empty;
#if UNITY_EDITOR
packageRoot = UnityEditor.EditorPrefs.GetString(EFS_TEST_PACKAGE_ROOT_KEY);
#endif
if (Directory.Exists(packageRoot) == false)
throw new Exception($"Not found package root : {packageRoot}");
var package = YooAssets.CreatePackage(AssetBundleCollectorDefine.TestPackageName);
// 初始化资源包
var initParams = new EditorSimulateModeParameters();
initParams.EditorFileSystemParameters = FileSystemParameters.CreateDefaultEditorFileSystemParameters(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(EFS_RAW_PACKAGE_ROOT_KEY);
#endif
if (Directory.Exists(packageRoot) == false)
throw new Exception($"Not found package root : {packageRoot}");
var package = YooAssets.CreatePackage(AssetBundleCollectorDefine.RawPackageName);
// 初始化资源包
var initParams = new EditorSimulateModeParameters();
initParams.EditorFileSystemParameters = FileSystemParameters.CreateDefaultEditorFileSystemParameters(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);
}
}
[UnityTest]
public IEnumerator TestLoadAudio()
{
var tester = new TestLoadAudio();
yield return tester.RuntimeTester();
}
[UnityTest]
public IEnumerator TestLoadImage()
{
var tester = new TestLoadImage();
yield return tester.RuntimeTester();
}
[UnityTest]
public IEnumerator TestLoadPrefab()
{
var tester = new TestLoadPrefab();
yield return tester.RuntimeTester();
}
[UnityTest]
public IEnumerator TestLoadScene()
{
var tester = new TestLoadScene();
yield return tester.RuntimeTester();
}
[UnityTest]
public IEnumerator TestLoadScriptableObject()
{
var tester = new TestLoadScriptableObject();
yield return tester.RuntimeTester();
}
[UnityTest]
public IEnumerator TestLoadSpriteAtlas()
{
var tester = new TestLoadSpriteAtlas();
yield return tester.RuntimeTester();
}
[UnityTest]
public IEnumerator TestLoadRawFile()
{
var tester = new TestLoadRawFile();
yield return tester.RuntimeTester();
}
[UnityTest]
public IEnumerator TestLoadVideo()
{
var tester = new TestLoadVideo();
yield return tester.RuntimeTester();
} }
} }

View File

@ -11,13 +11,12 @@ using YooAsset;
public class TestLoadAudio public class TestLoadAudio
{ {
[UnityTest]
public IEnumerator RuntimeTester() public IEnumerator RuntimeTester()
{ {
ResourcePackage package = YooAssets.GetPackage("TestPackage"); ResourcePackage package = YooAssets.GetPackage(AssetBundleCollectorDefine.TestPackageName);
Assert.IsNotNull(package); Assert.IsNotNull(package);
// 音乐 // 音乐异步加载
{ {
var assetHandle = package.LoadAssetAsync<AudioClip>("music_a"); var assetHandle = package.LoadAssetAsync<AudioClip>("music_a");
yield return assetHandle; yield return assetHandle;
@ -27,7 +26,7 @@ public class TestLoadAudio
Assert.IsNotNull(audioClip); Assert.IsNotNull(audioClip);
} }
// 音效 // 音效异步加载
{ {
var assetHandle = package.LoadAssetAsync<AudioClip>("sound_a"); var assetHandle = package.LoadAssetAsync<AudioClip>("sound_a");
yield return assetHandle; yield return assetHandle;
@ -36,5 +35,15 @@ public class TestLoadAudio
var audioClip = assetHandle.AssetObject as AudioClip; var audioClip = assetHandle.AssetObject as AudioClip;
Assert.IsNotNull(audioClip); Assert.IsNotNull(audioClip);
} }
// 音效同步加载
{
var assetHandle = package.LoadAssetSync<AudioClip>("sound_b");
yield return assetHandle;
Assert.AreEqual(EOperationStatus.Succeed, assetHandle.Status);
var audioClip = assetHandle.AssetObject as AudioClip;
Assert.IsNotNull(audioClip);
}
} }
} }

View File

@ -11,20 +11,35 @@ using YooAsset;
public class TestLoadImage public class TestLoadImage
{ {
[UnityTest]
public IEnumerator RuntimeTester() public IEnumerator RuntimeTester()
{ {
ResourcePackage package = YooAssets.GetPackage("TestPackage"); ResourcePackage package = YooAssets.GetPackage(AssetBundleCollectorDefine.TestPackageName);
Assert.IsNotNull(package); Assert.IsNotNull(package);
var subAssetsHandle = package.LoadSubAssetsAsync<Sprite>("image_a"); // 异步加载子对象
yield return subAssetsHandle; {
Assert.AreEqual(EOperationStatus.Succeed, subAssetsHandle.Status); var subAssetsHandle = package.LoadSubAssetsAsync<Sprite>("image_a");
yield return subAssetsHandle;
Assert.AreEqual(EOperationStatus.Succeed, subAssetsHandle.Status);
var subAssetObjects = subAssetsHandle.SubAssetObjects; var subAssetObjects = subAssetsHandle.SubAssetObjects;
Assert.IsNotNull(subAssetObjects); Assert.IsNotNull(subAssetObjects);
int count = subAssetObjects.Count; int count = subAssetObjects.Count;
Assert.AreEqual(count, 3); Assert.AreEqual(count, 3);
}
// 同步加载子对象
{
var subAssetsHandle = package.LoadSubAssetsSync<Sprite>("image_b");
yield return subAssetsHandle;
Assert.AreEqual(EOperationStatus.Succeed, subAssetsHandle.Status);
var subAssetObjects = subAssetsHandle.SubAssetObjects;
Assert.IsNotNull(subAssetObjects);
int count = subAssetObjects.Count;
Assert.AreEqual(count, 3);
}
} }
} }

View File

@ -11,13 +11,12 @@ using YooAsset;
public class TestLoadPrefab public class TestLoadPrefab
{ {
[UnityTest]
public IEnumerator RuntimeTester() public IEnumerator RuntimeTester()
{ {
ResourcePackage package = YooAssets.GetPackage("TestPackage"); ResourcePackage package = YooAssets.GetPackage(AssetBundleCollectorDefine.TestPackageName);
Assert.IsNotNull(package); Assert.IsNotNull(package);
// 加载所有预制体 // 异步加载所有预制体
{ {
var allAssetsHandle = package.LoadAllAssetsAsync<GameObject>("prefab_a"); var allAssetsHandle = package.LoadAllAssetsAsync<GameObject>("prefab_a");
yield return allAssetsHandle; yield return allAssetsHandle;
@ -30,9 +29,24 @@ public class TestLoadPrefab
Assert.AreEqual(count, 3); Assert.AreEqual(count, 3);
} }
// 加载指定预制体 // 异步加载指定预制体
{ {
var assetsHandle = package.LoadAssetAsync<GameObject>("prefab_a"); var assetsHandle = package.LoadAssetAsync<GameObject>("prefab_b");
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);
}
// 同步加载指定预制体
{
var assetsHandle = package.LoadAssetSync<GameObject>("prefab_c");
yield return assetsHandle; yield return assetsHandle;
Assert.AreEqual(EOperationStatus.Succeed, assetsHandle.Status); Assert.AreEqual(EOperationStatus.Succeed, assetsHandle.Status);
Assert.IsNotNull(assetsHandle.AssetObject); Assert.IsNotNull(assetsHandle.AssetObject);

View File

@ -11,10 +11,9 @@ using YooAsset;
public class TestLoadRawFile public class TestLoadRawFile
{ {
[UnityTest]
public IEnumerator RuntimeTester() public IEnumerator RuntimeTester()
{ {
ResourcePackage package = YooAssets.GetPackage("RawPackage"); ResourcePackage package = YooAssets.GetPackage(AssetBundleCollectorDefine.RawPackageName);
Assert.IsNotNull(package); Assert.IsNotNull(package);
// 测试异步加载 // 测试异步加载

View File

@ -12,13 +12,12 @@ using YooAsset;
public class TestLoadScene public class TestLoadScene
{ {
[UnityTest]
public IEnumerator RuntimeTester() public IEnumerator RuntimeTester()
{ {
ResourcePackage package = YooAssets.GetPackage("TestPackage"); ResourcePackage package = YooAssets.GetPackage(AssetBundleCollectorDefine.TestPackageName);
Assert.IsNotNull(package); Assert.IsNotNull(package);
// 主场景 // 异步加载主场景
{ {
var sceneHandle = package.LoadSceneAsync("scene_a", LoadSceneMode.Single); var sceneHandle = package.LoadSceneAsync("scene_a", LoadSceneMode.Single);
yield return sceneHandle; yield return sceneHandle;
@ -28,7 +27,7 @@ public class TestLoadScene
Assert.IsNotNull(scene); Assert.IsNotNull(scene);
} }
// 附加场景 // 异步加载附加场景
yield return new WaitForSeconds(1f); yield return new WaitForSeconds(1f);
{ {
var sceneHandle = package.LoadSceneAsync("scene_b", LoadSceneMode.Additive); var sceneHandle = package.LoadSceneAsync("scene_b", LoadSceneMode.Additive);
@ -39,15 +38,21 @@ public class TestLoadScene
Assert.IsNotNull(scene); Assert.IsNotNull(scene);
} }
// 场景 // 异步加载附加场景
yield return new WaitForSeconds(1f); yield return new WaitForSeconds(1f);
{ {
var sceneHandle = package.LoadSceneAsync("scene_c", LoadSceneMode.Single); var sceneHandle = package.LoadSceneSync("scene_c", LoadSceneMode.Additive);
yield return sceneHandle; yield return sceneHandle;
Assert.AreEqual(EOperationStatus.Succeed, sceneHandle.Status); Assert.AreEqual(EOperationStatus.Succeed, sceneHandle.Status);
var scene = sceneHandle.SceneObject; var scene = sceneHandle.SceneObject;
Assert.IsNotNull(scene); Assert.IsNotNull(scene);
// 异步销毁附加场景
yield return new WaitForSeconds(1f);
var unloadSceneOp = sceneHandle.UnloadAsync();
yield return unloadSceneOp;
Assert.AreEqual(EOperationStatus.Succeed, unloadSceneOp.Status);
} }
} }
} }

View File

@ -11,18 +11,31 @@ using YooAsset;
public class TestLoadScriptableObject public class TestLoadScriptableObject
{ {
[UnityTest]
public IEnumerator RuntimeTester() public IEnumerator RuntimeTester()
{ {
ResourcePackage package = YooAssets.GetPackage("TestPackage"); ResourcePackage package = YooAssets.GetPackage(AssetBundleCollectorDefine.TestPackageName);
Assert.IsNotNull(package); Assert.IsNotNull(package);
var assetHandle = package.LoadAssetAsync("game_config"); // 异步加载序列化对象
yield return assetHandle; {
Assert.AreEqual(EOperationStatus.Succeed, assetHandle.Status); var assetHandle = package.LoadAssetAsync("config_a");
yield return assetHandle;
Assert.AreEqual(EOperationStatus.Succeed, assetHandle.Status);
var testScriptableObject = assetHandle.AssetObject as TestScriptableObject; var testScriptableObject = assetHandle.AssetObject as TestScriptableObject;
Assert.IsNotNull(testScriptableObject); Assert.IsNotNull(testScriptableObject);
TestLogger.Log(this, testScriptableObject.ConfigName); TestLogger.Log(this, testScriptableObject.ConfigName);
}
// 同步加载序列化对象
{
var assetHandle = package.LoadAssetSync("config_b");
yield return assetHandle;
Assert.AreEqual(EOperationStatus.Succeed, assetHandle.Status);
var testScriptableObject = assetHandle.AssetObject as TestScriptableObject;
Assert.IsNotNull(testScriptableObject);
TestLogger.Log(this, testScriptableObject.ConfigName);
}
} }
} }

View File

@ -11,10 +11,9 @@ using YooAsset;
public class TestLoadSpriteAtlas public class TestLoadSpriteAtlas
{ {
[UnityTest]
public IEnumerator RuntimeTester() public IEnumerator RuntimeTester()
{ {
ResourcePackage package = YooAssets.GetPackage("TestPackage"); ResourcePackage package = YooAssets.GetPackage(AssetBundleCollectorDefine.TestPackageName);
Assert.IsNotNull(package); Assert.IsNotNull(package);
var assetHandle = package.LoadAssetAsync<SpriteAtlas>("atlas_icon"); var assetHandle = package.LoadAssetAsync<SpriteAtlas>("atlas_icon");

View File

@ -12,10 +12,9 @@ using UnityEngine.Video;
public class TestLoadVideo public class TestLoadVideo
{ {
[UnityTest]
public IEnumerator RuntimeTester() public IEnumerator RuntimeTester()
{ {
ResourcePackage package = YooAssets.GetPackage("RawPackage"); ResourcePackage package = YooAssets.GetPackage(AssetBundleCollectorDefine.RawPackageName);
Assert.IsNotNull(package); Assert.IsNotNull(package);
var rawFileHandle = package.LoadRawFileAsync("video_logo"); var rawFileHandle = package.LoadRawFileAsync("video_logo");

Binary file not shown.

After

Width:  |  Height:  |  Size: 347 KiB

View File

@ -0,0 +1,219 @@
fileFormatVersion: 2
guid: 837b56496d5027c41a3214fcbfb6ae2f
TextureImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 13
mipmaps:
mipMapMode: 0
enableMipMap: 0
sRGBTexture: 1
linearTexture: 0
fadeOut: 0
borderMipMap: 0
mipMapsPreserveCoverage: 0
alphaTestReferenceValue: 0.5
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: 0.25
normalMapFilter: 0
flipGreenChannel: 0
isReadable: 0
streamingMipmaps: 0
streamingMipmapsPriority: 0
vTOnly: 0
ignoreMipmapLimit: 0
grayScaleToAlpha: 0
generateCubemap: 6
cubemapConvolution: 0
seamlessCubemap: 0
textureFormat: 1
maxTextureSize: 2048
textureSettings:
serializedVersion: 2
filterMode: 1
aniso: 1
mipBias: 0
wrapU: 1
wrapV: 1
wrapW: 0
nPOTScale: 0
lightmap: 0
compressionQuality: 50
spriteMode: 2
spriteExtrude: 1
spriteMeshType: 1
alignment: 0
spritePivot: {x: 0.5, y: 0.5}
spritePixelsToUnits: 100
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spriteGenerateFallbackPhysicsShape: 1
alphaUsage: 1
alphaIsTransparency: 1
spriteTessellationDetail: -1
textureType: 8
textureShape: 1
singleChannelComponent: 0
flipbookRows: 1
flipbookColumns: 1
maxTextureSizeSet: 0
compressionQualitySet: 0
textureFormatSet: 0
ignorePngGamma: 0
applyGammaDecoding: 0
swizzle: 50462976
cookieLightType: 0
platformSettings:
- serializedVersion: 3
buildTarget: DefaultTexturePlatform
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
ignorePlatformSupport: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
- serializedVersion: 3
buildTarget: Standalone
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
ignorePlatformSupport: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
- serializedVersion: 3
buildTarget: iPhone
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
ignorePlatformSupport: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
- serializedVersion: 3
buildTarget: WebGL
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
ignorePlatformSupport: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
- serializedVersion: 3
buildTarget: Android
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
ignorePlatformSupport: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
spriteSheet:
serializedVersion: 2
sprites:
- serializedVersion: 2
name: image_a_0
rect:
serializedVersion: 2
x: 21
y: 16
width: 471
height: 473
alignment: 0
pivot: {x: 0, y: 0}
border: {x: 0, y: 0, z: 0, w: 0}
outline: []
physicsShape: []
tessellationDetail: 0
bones: []
spriteID: 91146573e1a4d014a806b24fa9cb6f0d
internalID: -1425660917
vertices: []
indices:
edges: []
weights: []
- serializedVersion: 2
name: image_a_1
rect:
serializedVersion: 2
x: 526
y: 12
width: 483
height: 480
alignment: 0
pivot: {x: 0, y: 0}
border: {x: 0, y: 0, z: 0, w: 0}
outline: []
physicsShape: []
tessellationDetail: 0
bones: []
spriteID: a1731b0da909b874186c63cdcaacdf44
internalID: 1768656825
vertices: []
indices:
edges: []
weights: []
- serializedVersion: 2
name: image_a_2
rect:
serializedVersion: 2
x: 1032
y: 9
width: 484
height: 486
alignment: 0
pivot: {x: 0, y: 0}
border: {x: 0, y: 0, z: 0, w: 0}
outline: []
physicsShape: []
tessellationDetail: 0
bones: []
spriteID: 539d18f1e9de1d748adba679160d2560
internalID: -1756424530
vertices: []
indices:
edges: []
weights: []
outline: []
physicsShape: []
bones: []
spriteID: 9548a159e49be6d46a487f932e9ced9a
internalID: 0
vertices: []
indices:
edges: []
weights: []
secondaryTextures: []
nameFileIdTable:
image_a_0: -1425660917
image_a_1: 1768656825
image_a_2: -1756424530
mipmapLimitGroupName:
pSDRemoveMatte: 0
userData:
assetBundleName:
assetBundleVariant:

View File

@ -315,7 +315,7 @@ Transform:
m_GameObject: {fileID: 1622835240} m_GameObject: {fileID: 1622835240}
serializedVersion: 2 serializedVersion: 2
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalPosition: {x: -1.5, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1} m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0 m_ConstrainProportionsScale: 0
m_Children: [] m_Children: []

View File

@ -317,7 +317,7 @@ Transform:
m_GameObject: {fileID: 1590071827} m_GameObject: {fileID: 1590071827}
serializedVersion: 2 serializedVersion: 2
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalPosition: {x: 1.5, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1} m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0 m_ConstrainProportionsScale: 0
m_Children: [] m_Children: []

View File

@ -10,6 +10,6 @@ MonoBehaviour:
m_Enabled: 1 m_Enabled: 1
m_EditorHideFlags: 0 m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 11ddf12cbeb412347957744c69cfc3b6, type: 3} m_Script: {fileID: 11500000, guid: 11ddf12cbeb412347957744c69cfc3b6, type: 3}
m_Name: game_config m_Name: config_a
m_EditorClassIdentifier: m_EditorClassIdentifier:
ConfigName: yoo ConfigName: config a

View File

@ -0,0 +1,15 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 11ddf12cbeb412347957744c69cfc3b6, type: 3}
m_Name: config_b
m_EditorClassIdentifier:
ConfigName: config b

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: f028d1ae726a7154fb9893e0171af947
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,15 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 11ddf12cbeb412347957744c69cfc3b6, type: 3}
m_Name: config_c
m_EditorClassIdentifier:
ConfigName: config c

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: b389b845dd8a30b47b2b36f407447e88
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant: