update test sample

This commit is contained in:
何冠峰
2025-07-21 18:05:08 +08:00
parent b2776b933a
commit 7dd08e9634
49 changed files with 505 additions and 791 deletions
@@ -89,7 +89,7 @@ public class T0_InitYooAssets : IPrebuildSetup, IPostBuildCleanup
YooAsset.Editor.AssetBundleCollectorSettingData.CreateCollector(panelGroup, collector1);
}
// 预制体(构建到一个AB)
// 预制体
var prefabGroup = YooAsset.Editor.AssetBundleCollectorSettingData.CreateGroup(testPackage, "PrefabGroup");
{
var collector1 = new YooAsset.Editor.AssetBundleCollector();
@@ -166,15 +166,16 @@ public class T0_InitYooAssets : IPrebuildSetup, IPostBuildCleanup
{
var collector1 = new YooAsset.Editor.AssetBundleCollector();
collector1.CollectPath = "";
collector1.CollectorGUID = "e082d492b9da65e499cee3495be3645d"; //TestRes3/music目录
collector1.CollectorGUID = "e082d492b9da65e499cee3495be3645d"; //TestRes3/encrypt目录
collector1.CollectorType = YooAsset.Editor.ECollectorType.MainAssetCollector;
collector1.PackRuleName = nameof(YooAsset.Editor.PackSeparately);
YooAsset.Editor.AssetBundleCollectorSettingData.CreateCollector(encryptGroup, collector1);
var collector2 = new YooAsset.Editor.AssetBundleCollector();
collector2.CollectPath = "";
collector2.CollectorGUID = "8c5a1726d94498e4cbe30f5f510cc796"; //TestRes3/prefab目录
collector2.CollectorGUID = "35f454fb80a715047bcf0ce30c7c4f18"; //TestRes3/import目录
collector2.CollectorType = YooAsset.Editor.ECollectorType.MainAssetCollector;
collector2.AssetTags = "import";
collector2.PackRuleName = nameof(YooAsset.Editor.PackSeparately);
YooAsset.Editor.AssetBundleCollectorSettingData.CreateCollector(encryptGroup, collector2);
@@ -185,14 +186,6 @@ public class T0_InitYooAssets : IPrebuildSetup, IPostBuildCleanup
collector3.AssetTags = "unpack";
collector3.PackRuleName = nameof(YooAsset.Editor.PackSeparately);
YooAsset.Editor.AssetBundleCollectorSettingData.CreateCollector(encryptGroup, collector3);
var collector4 = new YooAsset.Editor.AssetBundleCollector();
collector4.CollectPath = "";
collector4.CollectorGUID = "35f454fb80a715047bcf0ce30c7c4f18"; //TestRes3/import目录
collector4.CollectorType = YooAsset.Editor.ECollectorType.MainAssetCollector;
collector4.AssetTags = "import";
collector4.PackRuleName = nameof(YooAsset.Editor.PackSeparately);
YooAsset.Editor.AssetBundleCollectorSettingData.CreateCollector(encryptGroup, collector4);
}
}
private static void CreateRawBundlePackageCollector()
@@ -47,7 +47,7 @@ public class T1_TestEditorFileSystem : IPrebuildSetup, IPostBuildCleanup
[UnityTest]
public IEnumerator A_InitializePackage()
{
// 初始化资源包
// 初始化资源包 ASSET_BUNDLE
{
string packageRoot = string.Empty;
#if UNITY_EDITOR
@@ -82,7 +82,7 @@ public class T1_TestEditorFileSystem : IPrebuildSetup, IPostBuildCleanup
Assert.AreEqual(EOperationStatus.Succeed, updateManifestOp.Status);
}
// 初始化资源包
// 初始化资源包 RAW_BUNDLE
{
string packageRoot = string.Empty;
#if UNITY_EDITOR
@@ -119,30 +119,30 @@ public class T1_TestEditorFileSystem : IPrebuildSetup, IPostBuildCleanup
}
[UnityTest]
public IEnumerator B1_TestLoadAsyncTask()
public IEnumerator B1_TestAsyncTask()
{
var tester = new TestLoadPanel();
var tester = new TestAsyncTask();
yield return tester.RuntimeTester();
}
[UnityTest]
public IEnumerator B2_TestLoadAudio()
public IEnumerator B2_TestLoadAsset()
{
var tester = new TestLoadAudio();
var tester = new TestLoadAsset();
yield return tester.RuntimeTester();
}
[UnityTest]
public IEnumerator B3_TestLoadImage()
public IEnumerator B3_TestLoadSubAssets()
{
var tester = new TestLoadImage();
var tester = new TestLoadSubAssets();
yield return tester.RuntimeTester();
}
[UnityTest]
public IEnumerator B4_TestLoadPrefab()
public IEnumerator B4_TestLoadAllAssets()
{
var tester = new TestLoadPrefab();
var tester = new TestLoadAllAssets();
yield return tester.RuntimeTester();
}
@@ -182,32 +182,9 @@ public class T1_TestEditorFileSystem : IPrebuildSetup, IPostBuildCleanup
}
[UnityTest]
public IEnumerator C_DestroyPackage()
public IEnumerator D_DestroyPackage()
{
// 销毁旧资源包
{
var package = YooAssets.GetPackage(TestDefine.AssetBundlePackageName);
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(TestDefine.AssetBundlePackageName);
Assert.IsTrue(result);
}
// 销毁旧资源包
{
var package = YooAssets.GetPackage(TestDefine.RawBundlePackageName);
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(TestDefine.RawBundlePackageName);
Assert.IsTrue(result);
}
var tester = new TestDestroyPackage();
yield return tester.RuntimeTester(true);
}
}
@@ -125,30 +125,30 @@ public class T2_TestBuldinFileSystem : IPrebuildSetup, IPostBuildCleanup
}
[UnityTest]
public IEnumerator B1_TestLoadAsyncTask()
public IEnumerator B1_TestAsyncTask()
{
var tester = new TestLoadPanel();
var tester = new TestAsyncTask();
yield return tester.RuntimeTester();
}
[UnityTest]
public IEnumerator B2_TestLoadAudio()
public IEnumerator B2_TestLoadAsset()
{
var tester = new TestLoadAudio();
var tester = new TestLoadAsset();
yield return tester.RuntimeTester();
}
[UnityTest]
public IEnumerator B3_TestLoadImage()
public IEnumerator B3_TestLoadSubAssets()
{
var tester = new TestLoadImage();
var tester = new TestLoadSubAssets();
yield return tester.RuntimeTester();
}
[UnityTest]
public IEnumerator B4_TestLoadPrefab()
public IEnumerator B4_TestLoadAllAssets()
{
var tester = new TestLoadPrefab();
var tester = new TestLoadAllAssets();
yield return tester.RuntimeTester();
}
@@ -186,7 +186,7 @@ public class T2_TestBuldinFileSystem : IPrebuildSetup, IPostBuildCleanup
var tester = new TestLoadVideo();
yield return tester.RuntimeTester();
}
[UnityTest]
public IEnumerator C1_TestBundleReference()
{
@@ -201,33 +201,17 @@ public class T2_TestBuldinFileSystem : IPrebuildSetup, IPostBuildCleanup
yield return tester.RuntimeTester();
}
[UnityTest]
public IEnumerator C3_TestBundleUnpacker()
{
var tester = new TestBundleUnpacker();
yield return tester.RuntimeTester();
}
[UnityTest]
public IEnumerator D_DestroyPackage()
{
// 销毁旧资源包
{
var package = YooAssets.GetPackage(TestDefine.AssetBundlePackageName);
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(TestDefine.AssetBundlePackageName);
Assert.IsTrue(result);
}
// 销毁旧资源包
{
var package = YooAssets.GetPackage(TestDefine.RawBundlePackageName);
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(TestDefine.RawBundlePackageName);
Assert.IsTrue(result);
}
var tester = new TestDestroyPackage();
yield return tester.RuntimeTester(true);
}
}
@@ -16,53 +16,61 @@ public class TestBundleEncryption
ResourcePackage package = YooAssets.GetPackage(TestDefine.AssetBundlePackageName);
Assert.IsNotNull(package);
// 异步加载音乐播放预制体
// 异步加载加密的预制体
// 说明:测试内置文件解压
{
var assetHandle = package.LoadAssetAsync<GameObject>("prefab_audioA");
var assetHandle = package.LoadAssetAsync<GameObject>("prefab_encryptA");
yield return assetHandle;
Assert.AreEqual(EOperationStatus.Succeed, assetHandle.Status);
var go = assetHandle.InstantiateSync(Vector3.zero, Quaternion.identity);
Assert.IsNotNull(go);
var audioSource = go.GetComponent<AudioSource>();
Assert.IsNotNull(audioSource.clip);
}
// 同步加载音乐播放预制体
// 同步加载加密的预制体
// 说明:测试内置文件解压
{
var assetHandle = package.LoadAssetSync<GameObject>("prefab_audioB");
yield return assetHandle;
var assetHandle = package.LoadAssetSync<GameObject>("prefab_encryptB");
Assert.AreEqual(EOperationStatus.Succeed, assetHandle.Status);
var go = assetHandle.InstantiateSync(Vector3.zero, Quaternion.identity);
Assert.IsNotNull(go);
var audioSource = go.GetComponent<AudioSource>();
Assert.IsNotNull(audioSource.clip);
}
yield return new WaitForSeconds(1f);
}
}
/* 资源代码流程
* 内置文件解压(加载器)
* 内置文件解压(加载器触发)
BuildinFileSystem::LoadBundleFile()
{
_unpackFileSystem.LoadBundleFile(bundle);
if (IsUnpackBundleFile(bundle))
{
_unpackFileSystem.LoadBundleFile(bundle);
}
}
UnpackFileSystem::LoadAssetBundleOperation()
UnpackFileSystem::LoadBundleFile()
{
DownloadFileOptions options = new DownloadFileOptions(int.MaxValue, 60);
_unpackFileSystem.DownloadFileAsync(_bundle, options);
var operation = new DCFSLoadAssetBundleOperation(this, bundle);
return operation;
}
DCFSLoadAssetBundleOperation::InternalUpdate()
{
if (_steps == ESteps.DownloadFile)
{
DownloadFileOptions options = new DownloadFileOptions(int.MaxValue);
_unpackFileSystem.DownloadFileAsync(_bundle, options);
}
}
UnpackFileSystem::DownloadFileAsync()
{
//RemoteServices返回内置文件路径
string mainURL = RemoteServices.GetRemoteMainURL(bundle.FileName);
string fallbackURL = RemoteServices.GetRemoteFallbackURL(bundle.FileName);
options.SetURL(mainURL, fallbackURL);
return new DownloadPackageBundleOperation(bundle, options);
if (string.IsNullOrEmpty(options.ImportFilePath))
{
//RemoteServices返回内置文件路径
string mainURL = RemoteServices.GetRemoteMainURL(bundle.FileName);
string fallbackURL = RemoteServices.GetRemoteFallbackURL(bundle.FileName);
options.SetURL(mainURL, fallbackURL);
var downloader = new DownloadPackageBundleOperation(bundle, options);
return downloader;
}
}
*/
@@ -19,29 +19,31 @@ public class TestBundleUnpacker
var resourceUnpacker = package.CreateResourceUnpacker("unpack", 10, 1);
Assert.AreEqual(resourceUnpacker.TotalDownloadCount, 2);
resourceUnpacker.BeginDownload();
yield return resourceUnpacker;
Assert.AreEqual(EOperationStatus.Succeed, resourceUnpacker.Status);
// 等待一秒
yield return new WaitForSeconds(1f);
}
}
/* 资源代码流程
* 内置文件解压(解压器)
* 内置文件解压(解压器触发)
BundleInfo::CreateDownloader()
{
return _buildFileSystem.DownloadFileAsync(Bundle, options);
}
BuildinFileSystem::DownloadFileAsync()
{
options.ImportFilePath = xxxxxx;
_unpackFileSystem.DownloadFileAsync(bundle, options);
options.ImportFilePath = GetBuildinFileLoadPath(bundle);
return _unpackFileSystem.DownloadFileAsync(bundle, options);
}
UnpackFileSystem::DownloadFileAsync()
{
string mainURL = ConvertToWWWPath(options.ImportFilePath);
options.SetURL(mainURL, mainURL);
return new DownloadPackageBundleOperation(bundle, options);
if (string.IsNullOrEmpty(options.ImportFilePath) == false)
{
string mainURL = ConvertToWWWPath(options.ImportFilePath);
options.SetURL(mainURL, mainURL);
var downloader = new DownloadPackageBundleOperation(bundle, options);
return downloader;
}
}
*/
@@ -92,8 +92,6 @@ public class T3_TestCacheFileSystem : IPrebuildSetup, IPostBuildCleanup
}
}
[UnityTest]
public IEnumerator B1_TestBundlePlaying()
{
@@ -115,6 +113,13 @@ public class T3_TestCacheFileSystem : IPrebuildSetup, IPostBuildCleanup
yield return tester.RuntimeTester();
}
[UnityTest]
public IEnumerator D_DestroyPackage()
{
var tester = new TestDestroyPackage();
yield return tester.RuntimeTester(false);
}
private static void CopyDirectory(string sourceDir, string targetDir)
{
// 检查源目录是否存在
@@ -17,31 +17,30 @@ public class TestBundleDownloader
Assert.IsNotNull(package);
var downloader = package.CreateResourceDownloader(10, 1);
if (downloader.TotalDownloadCount == 0)
{
Assert.Fail($"Test downloader not found any file !");
}
Assert.AreNotEqual(downloader.TotalDownloadCount, 0);
downloader.BeginDownload();
downloader.DownloadFinishCallback = (DownloaderFinishData data) =>
{
if (data.Succeed == false)
Assert.Fail($"Test downloader failed ! {downloader.Error}");
};
// 等待一秒
yield return new WaitForSeconds(1f);
yield return downloader;
Assert.AreEqual(EOperationStatus.Succeed, downloader.Status);
}
}
/* 资源代码流程
* 远端文件下载(下载器)
* 远端文件下载(下载器触发)
BundleInfo::CreateDownloader()
{
return _buildFileSystem.DownloadFileAsync(Bundle, options);
}
CacheFileSystem::DownloadFileAsync()
{
//RemoteServices返回CDN文件路径
string mainURL = RemoteServices.GetRemoteMainURL(bundle.FileName);
string fallbackURL = RemoteServices.GetRemoteFallbackURL(bundle.FileName);
options.SetURL(mainURL, fallbackURL);
return new DownloadPackageBundleOperation(bundle, options);
if (string.IsNullOrEmpty(options.ImportFilePath))
{
//RemoteServices返回CDN文件路径
string mainURL = RemoteServices.GetRemoteMainURL(bundle.FileName);
string fallbackURL = RemoteServices.GetRemoteFallbackURL(bundle.FileName);
options.SetURL(mainURL, fallbackURL);
var downloader = new DownloadPackageBundleOperation(bundle, options);
return downloader;
}
}
*/
@@ -35,14 +35,11 @@ public class TestBundleImporter
unpacker.BeginDownload();
yield return unpacker;
Assert.AreEqual(EOperationStatus.Succeed, unpacker.Status);
// 等待一秒
yield return new WaitForSeconds(1f);
}
}
/* 资源代码流程
* 本地文件导入(导入器)
* 本地文件导入(导入器触发)
BundleInfo::CreateDownloader()
{
options.ImportFilePath = _importFilePath;
@@ -50,8 +47,12 @@ BundleInfo::CreateDownloader()
}
CacheFileSystem::DownloadFileAsync()
{
string mainURL = ConvertToWWWPath(options.ImportFilePath);
options.SetURL(mainURL, mainURL);
return new DownloadPackageBundleOperation(bundle, options);
if (string.IsNullOrEmpty(options.ImportFilePath) == false)
{
string mainURL = ConvertToWWWPath(options.ImportFilePath);
options.SetURL(mainURL, mainURL);
var downloader = new DownloadPackageBundleOperation(bundle, options);
return downloader;
}
}
*/
@@ -16,28 +16,27 @@ public class TestBundlePlaying
ResourcePackage package = YooAssets.GetPackage(TestDefine.AssetBundlePackageName);
Assert.IsNotNull(package);
if (package.IsNeedDownloadFromRemote("panel_a") == false)
if (package.IsNeedDownloadFromRemote("prefab_encryptA") == false)
{
Assert.Fail("Load bundle is already existed !");
}
if (package.IsNeedDownloadFromRemote("panel_b") == false)
if (package.IsNeedDownloadFromRemote("prefab_encryptB") == false)
{
Assert.Fail("Load bundle is already existed !");
}
// 测试异步加载
// 测试异步加载远端资源
{
var assetsHandle = package.LoadAssetAsync<GameObject>("panel_a");
var assetsHandle = package.LoadAssetAsync<GameObject>("prefab_encryptA");
yield return assetsHandle;
Assert.AreEqual(EOperationStatus.Succeed, assetsHandle.Status);
}
// 测试同步加载
// 测试同步加载远端资源
{
// 验证失败结果
UnityEngine.TestTools.LogAssert.ignoreFailingMessages = true;
var assetsHandle = package.LoadAssetSync<GameObject>("panel_b");
yield return assetsHandle;
var assetsHandle = package.LoadAssetSync<GameObject>("prefab_encryptB");
Assert.AreEqual(EOperationStatus.Failed, assetsHandle.Status);
UnityEngine.TestTools.LogAssert.ignoreFailingMessages = false;
@@ -46,34 +45,38 @@ public class TestBundlePlaying
package.UnloadUnusedAssetsAsync();
// 验证成功结果
// 说明:同步加载也会触发远端下载任务!
yield return new WaitForSeconds(1f);
assetsHandle = package.LoadAssetSync<GameObject>("panel_b");
yield return assetsHandle;
assetsHandle = package.LoadAssetSync<GameObject>("prefab_encryptB");
Assert.AreEqual(EOperationStatus.Succeed, assetsHandle.Status);
}
// 等待一秒
yield return new WaitForSeconds(1f);
}
}
/* 资源代码流程
* 远端文件下载(加载器)
* 远端文件下载(加载器触发)
CacheFileSystem::LoadBundleFile()
{
_cacheFileSystem.LoadBundleFile(bundle);
}
CacheFileSystem::LoadAssetBundleOperation()
DCFSLoadAssetBundleOperation::InternalUpdate()
{
DownloadFileOptions options = new DownloadFileOptions(int.MaxValue, 60);
_cacheFileSystem.DownloadFileAsync(_bundle, options);
if (_steps == ESteps.DownloadFile)
{
DownloadFileOptions options = new DownloadFileOptions(int.MaxValue);
_cacheFileSystem.DownloadFileAsync(_bundle, options);
}
}
CacheFileSystem::DownloadFileAsync()
{
//RemoteServices返回CDN文件路径
string mainURL = RemoteServices.GetRemoteMainURL(bundle.FileName);
string fallbackURL = RemoteServices.GetRemoteFallbackURL(bundle.FileName);
options.SetURL(mainURL, fallbackURL);
return new DownloadPackageBundleOperation(bundle, options);
if (string.IsNullOrEmpty(options.ImportFilePath))
{
//RemoteServices返回CDN文件路径
string mainURL = RemoteServices.GetRemoteMainURL(bundle.FileName);
string fallbackURL = RemoteServices.GetRemoteFallbackURL(bundle.FileName);
options.SetURL(mainURL, fallbackURL);
var downloader = new DownloadPackageBundleOperation(bundle, options);
return downloader;
}
}
*/
@@ -0,0 +1,43 @@
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 TestDestroyPackage
{
public IEnumerator RuntimeTester(bool destroyRawPackage)
{
// 销毁旧资源包 ASSET_BUNDLE
{
var package = YooAssets.GetPackage(TestDefine.AssetBundlePackageName);
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(TestDefine.AssetBundlePackageName);
Assert.IsTrue(result);
}
// 销毁旧资源包 RAW_BUNDLE
if (destroyRawPackage)
{
var package = YooAssets.GetPackage(TestDefine.RawBundlePackageName);
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(TestDefine.RawBundlePackageName);
Assert.IsTrue(result);
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 2772d71ea8e24f844b0ad661a3c85ee6
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,44 @@
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 TestLoadAllAssets
{
public IEnumerator RuntimeTester()
{
ResourcePackage package = YooAssets.GetPackage(TestDefine.AssetBundlePackageName);
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 allAssetsHandle = package.LoadAllAssetsSync<GameObject>("prefab_x");
Assert.AreEqual(EOperationStatus.Succeed, allAssetsHandle.Status);
var allAssetObjects = allAssetsHandle.AllAssetObjects;
Assert.IsNotNull(allAssetObjects);
int count = allAssetObjects.Count;
Assert.AreEqual(count, 3);
}
}
}
@@ -9,14 +9,14 @@ using UnityEngine.TestTools;
using NUnit.Framework;
using YooAsset;
public class TestLoadAudio
public class TestLoadAsset
{
public IEnumerator RuntimeTester()
{
ResourcePackage package = YooAssets.GetPackage(TestDefine.AssetBundlePackageName);
Assert.IsNotNull(package);
// 音乐异步加载
// 异步加载音乐
{
var assetHandle = package.LoadAssetAsync<AudioClip>("music_a");
yield return assetHandle;
@@ -26,7 +26,7 @@ public class TestLoadAudio
Assert.IsNotNull(audioClip);
}
// 音效异步加载
// 异步加载音效
{
var assetHandle = package.LoadAssetAsync<AudioClip>("sound_a");
yield return assetHandle;
@@ -36,10 +36,9 @@ public class TestLoadAudio
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;
@@ -10,16 +10,16 @@ using UnityEngine.TestTools;
using NUnit.Framework;
using YooAsset;
public class TestLoadPanel
public class TestAsyncTask
{
public IEnumerator RuntimeTester()
{
ResourcePackage package = YooAssets.GetPackage(TestDefine.AssetBundlePackageName);
Assert.IsNotNull(package);
// 异步加载面板
// Task异步加载面板
{
var assetsHandle = package.LoadAssetAsync<GameObject>("panel_canvas");
var assetsHandle = package.LoadAssetAsync<GameObject>("canvas");
var handleTask = assetsHandle.Task;
while (!handleTask.IsCompleted)
yield return null;
@@ -28,7 +28,7 @@ public class TestLoadPanel
var instantiateOp = assetsHandle.InstantiateAsync();
var operationTask = instantiateOp.Task;
while (!handleTask.IsCompleted)
while (!operationTask.IsCompleted)
yield return null;
yield return null;
Assert.AreEqual(EOperationStatus.Succeed, instantiateOp.Status);
@@ -1,64 +0,0 @@
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
{
public IEnumerator RuntimeTester()
{
ResourcePackage package = YooAssets.GetPackage(TestDefine.AssetBundlePackageName);
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_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);
GameObject.Destroy(instantiateOp.Result);
}
// 同步加载指定预制体
{
var assetsHandle = package.LoadAssetSync<GameObject>("prefab_c");
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);
GameObject.Destroy(instantiateOp.Result);
}
}
}
@@ -27,11 +27,10 @@ public class TestLoadScene
Assert.IsNotNull(scene);
}
// 异步加载附加场景
yield return new WaitForSeconds(1f);
// 同步加载附加场景
yield return new WaitForSeconds(0.2f);
{
var sceneHandle = package.LoadSceneAsync("scene_b", LoadSceneMode.Additive);
yield return sceneHandle;
var sceneHandle = package.LoadSceneSync("scene_b", LoadSceneMode.Additive);
Assert.AreEqual(EOperationStatus.Succeed, sceneHandle.Status);
var scene = sceneHandle.SceneObject;
@@ -39,18 +38,21 @@ public class TestLoadScene
}
// 异步加载附加场景
yield return new WaitForSeconds(1f);
yield return new WaitForSeconds(0.2f);
SceneHandle cachedHandle;
{
var sceneHandle = package.LoadSceneSync("scene_c", LoadSceneMode.Additive);
yield return sceneHandle;
Assert.AreEqual(EOperationStatus.Succeed, sceneHandle.Status);
cachedHandle = package.LoadSceneSync("scene_c", LoadSceneMode.Additive);
yield return cachedHandle;
Assert.AreEqual(EOperationStatus.Succeed, cachedHandle.Status);
var scene = sceneHandle.SceneObject;
var scene = cachedHandle.SceneObject;
Assert.IsNotNull(scene);
}
// 异步销毁附加场景
yield return new WaitForSeconds(1f);
var unloadSceneOp = sceneHandle.UnloadAsync();
// 异步销毁附加场景
yield return new WaitForSeconds(0.2f);
{
var unloadSceneOp = cachedHandle.UnloadAsync();
yield return unloadSceneOp;
Assert.AreEqual(EOperationStatus.Succeed, unloadSceneOp.Status);
}
@@ -9,7 +9,7 @@ using UnityEngine.TestTools;
using NUnit.Framework;
using YooAsset;
public class TestLoadImage
public class TestLoadSubAssets
{
public IEnumerator RuntimeTester()
{
@@ -32,7 +32,6 @@ public class TestLoadImage
// 同步加载子对象
{
var subAssetsHandle = package.LoadSubAssetsSync<Sprite>("image_b");
yield return subAssetsHandle;
Assert.AreEqual(EOperationStatus.Succeed, subAssetsHandle.Status);
var subAssetObjects = subAssetsHandle.SubAssetObjects;