【m】框架大更新
This commit is contained in:
@@ -0,0 +1,150 @@
|
||||
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 T3_TestCacheFileSystem : IPrebuildSetup, IPostBuildCleanup
|
||||
{
|
||||
public void Setup()
|
||||
{
|
||||
}
|
||||
public void Cleanup()
|
||||
{
|
||||
}
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator A_InitializePackage()
|
||||
{
|
||||
// 清空旧的缓存目录
|
||||
string projectPath = Path.GetDirectoryName(Application.dataPath);
|
||||
string cacheRoot = $"{projectPath}/yoo";
|
||||
Directory.Delete(cacheRoot, true);
|
||||
|
||||
// 拷贝打包资源到本地服务器
|
||||
{
|
||||
string packageRoot = string.Empty;
|
||||
#if UNITY_EDITOR
|
||||
packageRoot = UnityEditor.EditorPrefs.GetString(T2_TestBuldinFileSystem.ASSET_BUNDLE_PACKAGE_ROOT_KEY);
|
||||
#endif
|
||||
if (Directory.Exists(packageRoot) == false)
|
||||
throw new Exception($"Not found package root : {packageRoot}");
|
||||
|
||||
string testServerDirectory = "C://xampp/htdocs/CDN/Android/Test";
|
||||
CopyDirectory(packageRoot, testServerDirectory);
|
||||
}
|
||||
|
||||
// 初始化资源包 ASSET_BUNDLE
|
||||
{
|
||||
var package = YooAssets.CreatePackage(TestDefine.AssetBundlePackageName);
|
||||
|
||||
// 初始化资源包
|
||||
var initParams = new HostPlayModeParameters();
|
||||
var fileDecryption = new TestFileStreamDecryption();
|
||||
var manifestServices = new TestRestoreManifest();
|
||||
|
||||
string hostServerIP = "http://127.0.0.1/CDN/Android/Test/";
|
||||
var remoteServices = new TestRemoteServices(hostServerIP);
|
||||
initParams.BuildinFileSystemParameters = null;
|
||||
initParams.CacheFileSystemParameters = FileSystemParameters.CreateDefaultCacheFileSystemParameters(remoteServices, fileDecryption);
|
||||
initParams.CacheFileSystemParameters.AddParameter(FileSystemParametersDefine.MANIFEST_SERVICES, manifestServices);
|
||||
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);
|
||||
}
|
||||
}
|
||||
private class TestRemoteServices : IRemoteServices
|
||||
{
|
||||
private readonly string _localServerRoot;
|
||||
|
||||
public TestRemoteServices(string localServerRoot)
|
||||
{
|
||||
_localServerRoot = localServerRoot;
|
||||
}
|
||||
string IRemoteServices.GetRemoteMainURL(string fileName)
|
||||
{
|
||||
return $"{_localServerRoot}/{fileName}";
|
||||
}
|
||||
string IRemoteServices.GetRemoteFallbackURL(string fileName)
|
||||
{
|
||||
return $"{_localServerRoot}/{fileName}";
|
||||
}
|
||||
}
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator C1_TestBundlePlaying()
|
||||
{
|
||||
var tester = new TestBundlePlaying();
|
||||
yield return tester.RuntimeTester();
|
||||
}
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator C2_TestBundleImporter()
|
||||
{
|
||||
var tester = new TestBundleImporter();
|
||||
yield return tester.RuntimeTester();
|
||||
}
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator C3_TestBundleDownloader()
|
||||
{
|
||||
var tester = new TestBundleDownloader();
|
||||
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)
|
||||
{
|
||||
// 检查源目录是否存在
|
||||
if (!Directory.Exists(sourceDir))
|
||||
{
|
||||
throw new DirectoryNotFoundException($"源目录不存在: {sourceDir}");
|
||||
}
|
||||
|
||||
// 创建目标目录(如果不存在)
|
||||
Directory.CreateDirectory(targetDir);
|
||||
|
||||
// 拷贝所有文件
|
||||
foreach (string file in Directory.GetFiles(sourceDir))
|
||||
{
|
||||
string fileName = Path.GetFileName(file);
|
||||
string destFile = Path.Combine(targetDir, fileName);
|
||||
File.Copy(file, destFile, true); // true 表示覆盖已存在文件
|
||||
}
|
||||
|
||||
// 递归拷贝子目录
|
||||
foreach (string subDir in Directory.GetDirectories(sourceDir))
|
||||
{
|
||||
string dirName = Path.GetFileName(subDir);
|
||||
string newTargetDir = Path.Combine(targetDir, dirName);
|
||||
CopyDirectory(subDir, newTargetDir);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a680882da8a6755498514f4fd2210a34
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,46 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
using NUnit.Framework;
|
||||
using YooAsset;
|
||||
|
||||
/// <summary>
|
||||
/// 测试远端文件下载
|
||||
/// </summary>
|
||||
public class TestBundleDownloader
|
||||
{
|
||||
public IEnumerator RuntimeTester()
|
||||
{
|
||||
ResourcePackage package = YooAssets.GetPackage(TestDefine.AssetBundlePackageName);
|
||||
Assert.IsNotNull(package);
|
||||
|
||||
var downloader = package.CreateResourceDownloader(10, 1);
|
||||
Assert.AreNotEqual(downloader.TotalDownloadCount, 0);
|
||||
|
||||
downloader.BeginDownload();
|
||||
yield return downloader;
|
||||
Assert.AreEqual(EOperationStatus.Succeed, downloader.Status);
|
||||
}
|
||||
}
|
||||
|
||||
/* 资源代码流程
|
||||
* 远端文件下载(下载器触发)
|
||||
BundleInfo::CreateDownloader()
|
||||
{
|
||||
return _buildFileSystem.DownloadFileAsync(Bundle, options);
|
||||
}
|
||||
CacheFileSystem::DownloadFileAsync()
|
||||
{
|
||||
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,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6d1ca2e6dac603a459531fb09e61fd31
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,58 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
using NUnit.Framework;
|
||||
using YooAsset;
|
||||
|
||||
/// <summary>
|
||||
/// 测试本地文件导入
|
||||
/// </summary>
|
||||
public class TestBundleImporter
|
||||
{
|
||||
public IEnumerator RuntimeTester()
|
||||
{
|
||||
ResourcePackage package = YooAssets.GetPackage(TestDefine.AssetBundlePackageName);
|
||||
Assert.IsNotNull(package);
|
||||
|
||||
string packageRoot = UnityEditor.EditorPrefs.GetString(T2_TestBuldinFileSystem.ASSET_BUNDLE_PACKAGE_ROOT_KEY);
|
||||
DirectoryInfo packageDir = new DirectoryInfo(packageRoot);
|
||||
string fileRoot = $"{packageDir.Parent.FullName}/OutputCache";
|
||||
|
||||
ImportFileInfo fileInfoA = new ImportFileInfo();
|
||||
fileInfoA.FilePath = $"{fileRoot}/assets_samples_test_sample_testres3_import_prefab_importa.bundle.encrypt";
|
||||
fileInfoA.BundleName = "assets_samples_test_sample_testres3_import_prefab_importa.bundle";
|
||||
|
||||
ImportFileInfo fileInfoB = new ImportFileInfo();
|
||||
fileInfoB.FilePath = $"{fileRoot}/assets_samples_test_sample_testres3_import_prefab_importb.bundle.encrypt";
|
||||
fileInfoB.BundleName = "assets_samples_test_sample_testres3_import_prefab_importb.bundle";
|
||||
|
||||
ImportFileInfo[] importInfos = { fileInfoA, fileInfoB };
|
||||
var unpacker = package.CreateResourceImporter(importInfos, 10, 1);
|
||||
Assert.AreEqual(unpacker.TotalDownloadCount, 2);
|
||||
|
||||
unpacker.BeginDownload();
|
||||
yield return unpacker;
|
||||
Assert.AreEqual(EOperationStatus.Succeed, unpacker.Status);
|
||||
}
|
||||
}
|
||||
|
||||
/* 资源代码流程
|
||||
* 本地文件导入(导入器触发)
|
||||
BundleInfo::CreateDownloader()
|
||||
{
|
||||
options.ImportFilePath = _importFilePath;
|
||||
return _cacheFileSystem.DownloadFileAsync(Bundle, options);
|
||||
}
|
||||
CacheFileSystem::DownloadFileAsync()
|
||||
{
|
||||
if (string.IsNullOrEmpty(options.ImportFilePath) == false)
|
||||
{
|
||||
string mainURL = ConvertToWWWPath(options.ImportFilePath);
|
||||
options.SetURL(mainURL, mainURL);
|
||||
var downloader = new DownloadPackageBundleOperation(bundle, options);
|
||||
return downloader;
|
||||
}
|
||||
}
|
||||
*/
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 84a2bd73c962d0a4c9c3373ee8cd5380
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,82 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
using NUnit.Framework;
|
||||
using YooAsset;
|
||||
|
||||
/// <summary>
|
||||
/// 测试边玩边下
|
||||
/// </summary>
|
||||
public class TestBundlePlaying
|
||||
{
|
||||
public IEnumerator RuntimeTester()
|
||||
{
|
||||
ResourcePackage package = YooAssets.GetPackage(TestDefine.AssetBundlePackageName);
|
||||
Assert.IsNotNull(package);
|
||||
|
||||
if (package.IsNeedDownloadFromRemote("prefab_encryptA") == false)
|
||||
{
|
||||
Assert.Fail("Load bundle is already existed !");
|
||||
}
|
||||
if (package.IsNeedDownloadFromRemote("prefab_encryptB") == false)
|
||||
{
|
||||
Assert.Fail("Load bundle is already existed !");
|
||||
}
|
||||
|
||||
// 测试异步加载远端资源
|
||||
{
|
||||
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>("prefab_encryptB");
|
||||
Assert.AreEqual(EOperationStatus.Failed, assetsHandle.Status);
|
||||
UnityEngine.TestTools.LogAssert.ignoreFailingMessages = false;
|
||||
|
||||
// 清理加载器
|
||||
assetsHandle.Release();
|
||||
package.UnloadUnusedAssetsAsync();
|
||||
|
||||
// 验证成功结果
|
||||
// 说明:同步加载也会触发远端下载任务!
|
||||
yield return new WaitForSeconds(1f);
|
||||
assetsHandle = package.LoadAssetSync<GameObject>("prefab_encryptB");
|
||||
Assert.AreEqual(EOperationStatus.Succeed, assetsHandle.Status);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* 资源代码流程
|
||||
* 远端文件下载(加载器触发)
|
||||
CacheFileSystem::LoadBundleFile()
|
||||
{
|
||||
_cacheFileSystem.LoadBundleFile(bundle);
|
||||
}
|
||||
DCFSLoadAssetBundleOperation::InternalUpdate()
|
||||
{
|
||||
if (_steps == ESteps.DownloadFile)
|
||||
{
|
||||
DownloadFileOptions options = new DownloadFileOptions(int.MaxValue);
|
||||
_cacheFileSystem.DownloadFileAsync(_bundle, options);
|
||||
}
|
||||
}
|
||||
CacheFileSystem::DownloadFileAsync()
|
||||
{
|
||||
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,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6db248f26f2eaaa4282a7bbdf709c321
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user