refactor : 重构代码

This commit is contained in:
何冠峰
2026-01-16 10:30:02 +08:00
parent b0e85017d2
commit 611ac886b3
24 changed files with 339 additions and 81 deletions

View File

@@ -55,7 +55,7 @@ namespace YooAsset.Editor
string packageName = directoryInfo.Name;
try
{
bool result = CatalogTools.CreateCatalogFile(null, packageName, packageRoot); //TODO 自行处理解密
bool result = CatalogFileHelper.CreateFile(null, packageName, packageRoot); //TODO 自行处理解密
if (result == false)
{
Debug.LogError($"Create package {packageName} catalog file failed ! See the detail error in console !");

View File

@@ -47,7 +47,7 @@ namespace YooAsset.Editor
{
try
{
bool result = CatalogTools.CreateEmptyCatalogFile(_packageName, string.Empty, outputPath);
bool result = CatalogFileHelper.CreateEmptyFile(_packageName, string.Empty, outputPath);
if (result == false)
{
Debug.LogError($"Create package {_packageName} catalog file failed ! See the detail error in console !");

View File

@@ -106,11 +106,11 @@ namespace YooAsset.Editor
// 加载补丁清单1
byte[] bytesData1 = FileUtility.ReadAllBytes(_manifestPath1);
PackageManifest manifest1 = ManifestTools.DeserializeFromBinary(bytesData1, null); //TODO 自行处理解密
PackageManifest manifest1 = PackageManifestTools.DeserializeFromBinary(bytesData1, null); //TODO 自行处理解密
// 加载补丁清单1
byte[] bytesData2 = FileUtility.ReadAllBytes(_manifestPath2);
PackageManifest manifest2 = ManifestTools.DeserializeFromBinary(bytesData2, null); //TODO 自行处理解密
PackageManifest manifest2 = PackageManifestTools.DeserializeFromBinary(bytesData2, null); //TODO 自行处理解密
// 拷贝文件列表
foreach (var bundle2 in manifest2.BundleList)

View File

@@ -71,7 +71,7 @@ namespace YooAsset.Editor
// 加载补丁清单
byte[] bytesData = FileUtility.ReadAllBytes(manifestFilePath);
PackageManifest manifest = ManifestTools.DeserializeFromBinary(bytesData, null); //TODO 自行处理解密
PackageManifest manifest = PackageManifestTools.DeserializeFromBinary(bytesData, null); //TODO 自行处理解密
// 拷贝文件列表
int fileCount = 0;

View File

@@ -32,7 +32,7 @@ namespace YooAsset
string pacakgeDirectory = subDirectory.FullName;
try
{
bool result = CatalogTools.CreateCatalogFile(null, packageName, pacakgeDirectory); //TODO 自行处理解密
bool result = CatalogFileHelper.CreateFile(null, packageName, pacakgeDirectory); //TODO 自行处理解密
if (result == false)
{
Debug.LogError($"Create package {packageName} catalog file failed ! See the detail error in console !");

View File

@@ -1,4 +1,6 @@
using YooAsset;
using System.Collections.Generic;
using UnityEngine;
using YooAsset;
#region InitializeParameters
/// <summary>
@@ -144,7 +146,27 @@ public class UpdatePackageManifestOperation : AsyncOperationBase
}
#endregion
public static class CompatibleOldVersion
#region ImportFileInfo
public struct ImportFileInfo
{
/// <summary>
/// 本地文件路径
/// </summary>
public string FilePath;
/// <summary>
/// 资源包名称
/// </summary>
public string BundleName;
/// <summary>
/// 资源包GUID
/// </summary>
public string BundleGUID;
}
#endregion
public static class CompatibleResourcePackage
{
/// <summary>
/// 兼容Yoo2版本
@@ -221,15 +243,14 @@ public static class CompatibleOldVersion
OperationSystem.StartOperation(package.PackageName, wrapper);
return wrapper;
}
/// <summary>
/// 兼容Yoo2版本
/// </summary>
public static RequestPackageVersionOperation RequestPackageVersionAsync(this ResourcePackage package, bool appendTimeTicks = true, int timeout = 60)
{
var options = new RequestPackageVersionOptions(appendTimeTicks, timeout);
var operation = package.RequestPackageVersionAsync(options);
return operation;
return package.RequestPackageVersionAsync(options);
}
/// <summary>
@@ -243,15 +264,14 @@ public static class CompatibleOldVersion
OperationSystem.StartOperation(package.PackageName, wrapper);
return wrapper;
}
/// <summary>
/// 兼容Yoo2版本
/// </summary>
public static PreDownloadContentOperation PreDownloadContentAsync(this ResourcePackage package, string packageVersion, int timeout = 60)
{
var options = new PreDownloadContentOptions(packageVersion, timeout);
var operation = package.PreDownloadContentAsync(options);
return operation;
return package.PreDownloadContentAsync(options);
}
/// <summary>
@@ -271,4 +291,216 @@ public static class CompatibleOldVersion
var options = new ClearCacheFilesOptions(fileClearMode, clearParam);
return package.ClearCacheFilesAsync(options);
}
/// <summary>
/// 兼容Yoo2版本
/// </summary>
public static UnloadUnusedAssetsOperation UnloadUnusedAssetsAsync(this ResourcePackage package, int loopCount)
{
var options = new UnloadUnusedAssetsOptions(loopCount);
return package.UnloadUnusedAssetsAsync(options);
}
#region
/// <summary>
/// 兼容Yoo2版本
/// </summary>
public static ResourceDownloaderOperation CreateResourceDownloader(this ResourcePackage package, int downloadingMaxNumber, int failedTryAgain)
{
var options = new ResourceDownloaderOptions(downloadingMaxNumber, failedTryAgain);
return package.CreateResourceDownloader(options);
}
/// <summary>
/// 兼容Yoo2版本
/// </summary>
public static ResourceDownloaderOperation CreateResourceDownloader(this ResourcePackage package, string tag, int downloadingMaxNumber, int failedTryAgain)
{
string[] tags = new string[] { tag };
var options = new ResourceDownloaderOptions(tags, downloadingMaxNumber, failedTryAgain);
return package.CreateResourceDownloader(options);
}
/// <summary>
/// 兼容Yoo2版本
/// </summary>
public static ResourceDownloaderOperation CreateResourceDownloader(this ResourcePackage package, string[] tags, int downloadingMaxNumber, int failedTryAgain)
{
var options = new ResourceDownloaderOptions(tags, downloadingMaxNumber, failedTryAgain);
return package.CreateResourceDownloader(options);
}
/// <summary>
/// 兼容Yoo2版本
/// </summary>
public static ResourceDownloaderOperation CreateBundleDownloader(this ResourcePackage package, string location, bool recursiveDownload, int downloadingMaxNumber, int failedTryAgain)
{
var assetInfo = package.ConvertLocationToAssetInfo(location, null);
var options = new BundleDownloaderOptions(assetInfo, recursiveDownload, downloadingMaxNumber, failedTryAgain);
return package.CreateBundleDownloader(options);
}
public static ResourceDownloaderOperation CreateBundleDownloader(this ResourcePackage package, string location, int downloadingMaxNumber, int failedTryAgain)
{
return package.CreateBundleDownloader(location, false, downloadingMaxNumber, failedTryAgain);
}
/// <summary>
/// 兼容Yoo2版本
/// </summary>
public static ResourceDownloaderOperation CreateBundleDownloader(this ResourcePackage package, string[] locations, bool recursiveDownload, int downloadingMaxNumber, int failedTryAgain)
{
List<AssetInfo> assetInfos = new List<AssetInfo>(locations.Length);
foreach (var location in locations)
{
var assetInfo = package.ConvertLocationToAssetInfo(location, null);
assetInfos.Add(assetInfo);
}
var options = new BundleDownloaderOptions(assetInfos.ToArray(), recursiveDownload, downloadingMaxNumber, failedTryAgain);
return package.CreateBundleDownloader(options);
}
public static ResourceDownloaderOperation CreateBundleDownloader(this ResourcePackage package, string[] locations, int downloadingMaxNumber, int failedTryAgain)
{
return package.CreateBundleDownloader(locations, false, downloadingMaxNumber, failedTryAgain);
}
/// <summary>
/// 兼容Yoo2版本
/// </summary>
public static ResourceDownloaderOperation CreateBundleDownloader(this ResourcePackage package, AssetInfo assetInfo, bool recursiveDownload, int downloadingMaxNumber, int failedTryAgain)
{
AssetInfo[] assetInfos = new AssetInfo[] { assetInfo };
var options = new BundleDownloaderOptions(assetInfos, recursiveDownload, downloadingMaxNumber, failedTryAgain);
return package.CreateBundleDownloader(options);
}
public static ResourceDownloaderOperation CreateBundleDownloader(this ResourcePackage package, AssetInfo assetInfo, int downloadingMaxNumber, int failedTryAgain)
{
return package.CreateBundleDownloader(assetInfo, false, downloadingMaxNumber, failedTryAgain);
}
/// <summary>
/// 兼容Yoo2版本
/// </summary>
public static ResourceDownloaderOperation CreateBundleDownloader(this ResourcePackage package, AssetInfo[] assetInfos, bool recursiveDownload, int downloadingMaxNumber, int failedTryAgain)
{
var options = new BundleDownloaderOptions(assetInfos, recursiveDownload, downloadingMaxNumber, failedTryAgain);
return package.CreateBundleDownloader(options);
}
public static ResourceDownloaderOperation CreateBundleDownloader(this ResourcePackage package, AssetInfo[] assetInfos, int downloadingMaxNumber, int failedTryAgain)
{
return package.CreateBundleDownloader(assetInfos, false, downloadingMaxNumber, failedTryAgain);
}
#endregion
#region
/// <summary>
/// 兼容Yoo2版本
/// </summary>
public static ResourceUnpackerOperation CreateResourceUnpacker(this ResourcePackage package, int unpackingMaxNumber, int failedTryAgain)
{
var options = new ResourceUnpackerOptions(unpackingMaxNumber, failedTryAgain);
return package.CreateResourceUnpacker(options);
}
/// <summary>
/// 兼容Yoo2版本
/// </summary>
public static ResourceUnpackerOperation CreateResourceUnpacker(this ResourcePackage package, string tag, int unpackingMaxNumber, int failedTryAgain)
{
string[] tags = new string[] { tag };
var options = new ResourceUnpackerOptions(tags, unpackingMaxNumber, failedTryAgain);
return package.CreateResourceUnpacker(options);
}
/// <summary>
/// 兼容Yoo2版本
/// </summary>
public static ResourceUnpackerOperation CreateResourceUnpacker(this ResourcePackage package, string[] tags, int unpackingMaxNumber, int failedTryAgain)
{
var options = new ResourceUnpackerOptions(tags, unpackingMaxNumber, failedTryAgain);
return package.CreateResourceUnpacker(options);
}
#endregion
#region
/// <summary>
/// 兼容Yoo2版本
/// </summary>
public static ResourceImporterOperation CreateResourceImporter(this ResourcePackage package, string[] filePaths, int importerMaxNumber, int failedTryAgain)
{
ImportFileInfo[] fileInfos = new ImportFileInfo[filePaths.Length];
for (int i = 0; i < filePaths.Length; i++)
{
ImportFileInfo fileInfo = new ImportFileInfo();
fileInfo.FilePath = filePaths[i];
fileInfos[i] = fileInfo;
}
return package.CreateResourceImporter(fileInfos, importerMaxNumber, failedTryAgain);
}
/// <summary>
/// 兼容Yoo2版本
/// </summary>
public static ResourceImporterOperation CreateResourceImporter(this ResourcePackage package, ImportFileInfo[] fileInfos, int importerMaxNumber, int failedTryAgain)
{
ImportBundleInfo[] bundleInfos = new ImportBundleInfo[fileInfos.Length];
for (int i = 0; i < fileInfos.Length; i++)
{
ImportBundleInfo bundleInfo = new ImportBundleInfo();
bundleInfo.FilePath = fileInfos[i].FilePath;
bundleInfo.BundleName = fileInfos[i].BundleName;
bundleInfo.BundleGUID = fileInfos[i].BundleGUID;
bundleInfos[i] = bundleInfo;
}
var options = new BundleImporterOptions(bundleInfos, importerMaxNumber, failedTryAgain);
return package.CreateResourceImporter(options);
}
#endregion
}
public static class CompatibleAssetHandle
{
public static GameObject InstantiateSync(this AssetHandle handle, Transform parent)
{
var options = new InstantiateOptions(true, parent, false);
return handle.InstantiateSync(options);
}
public static GameObject InstantiateSync(this AssetHandle handle, Transform parent, bool worldPositionStays)
{
var options = new InstantiateOptions(true, parent, worldPositionStays);
return handle.InstantiateSync(options);
}
public static GameObject InstantiateSync(this AssetHandle handle, Vector3 position, Quaternion rotation)
{
var options = new InstantiateOptions(true, position, rotation);
return handle.InstantiateSync(options);
}
public static GameObject InstantiateSync(this AssetHandle handle, Vector3 position, Quaternion rotation, Transform parent)
{
var options = new InstantiateOptions(true, parent, position, rotation);
return handle.InstantiateSync(options);
}
public static InstantiateOperation InstantiateAsync(this AssetHandle handle, Transform parent, bool actived = true)
{
var options = new InstantiateOptions(actived, parent, false);
return handle.InstantiateAsync(options);
}
public static InstantiateOperation InstantiateAsync(this AssetHandle handle, Transform parent, bool worldPositionStays, bool actived = true)
{
var options = new InstantiateOptions(actived, parent, worldPositionStays);
return handle.InstantiateAsync(options);
}
public static InstantiateOperation InstantiateAsync(this AssetHandle handle, Vector3 position, Quaternion rotation, bool actived = true)
{
var options = new InstantiateOptions(actived, position, rotation);
return handle.InstantiateAsync(options);
}
public static InstantiateOperation InstantiateAsync(this AssetHandle handle, Vector3 position, Quaternion rotation, Transform parent, bool actived = true)
{
var options = new InstantiateOptions(actived, parent, position, rotation);
return handle.InstantiateAsync(options);
}
}

View File

@@ -14,6 +14,7 @@ public class LoadAssetsByTagOperation<TObject> : AsyncOperationBase where TObjec
Done,
}
private readonly string _packageName;
private readonly string _tag;
private ESteps _steps = ESteps.None;
private List<AssetHandle> _handles;
@@ -24,8 +25,9 @@ public class LoadAssetsByTagOperation<TObject> : AsyncOperationBase where TObjec
public List<TObject> AssetObjects { private set; get; }
public LoadAssetsByTagOperation(string tag)
public LoadAssetsByTagOperation(string packageName, string tag)
{
_packageName = packageName;
_tag = tag;
}
internal override void InternalStart()
@@ -39,11 +41,12 @@ public class LoadAssetsByTagOperation<TObject> : AsyncOperationBase where TObjec
if (_steps == ESteps.LoadAssets)
{
AssetInfo[] assetInfos = YooAssets.GetAssetInfos(_tag);
var package = YooAssets.GetPackage(_packageName);
AssetInfo[] assetInfos = package.GetAssetInfos(_tag);
_handles = new List<AssetHandle>(assetInfos.Length);
foreach (var assetInfo in assetInfos)
{
var handle = YooAssets.LoadAssetAsync(assetInfo);
var handle = package.LoadAssetAsync(assetInfo);
_handles.Add(handle);
}
_steps = ESteps.CheckResult;

View File

@@ -6,9 +6,9 @@ using YooAsset;
public static class YooAssetsExtension
{
public static LoadGameObjectOperation LoadGameObjectAsync(this ResourcePackage resourcePackage, string location, Vector3 position, Quaternion rotation, Transform parent, bool destroyGoOnRelease = false)
public static LoadGameObjectOperation LoadGameObjectAsync(this ResourcePackage package, string location, Vector3 position, Quaternion rotation, Transform parent, bool destroyGoOnRelease = false)
{
var operation = new LoadGameObjectOperation(location, position, rotation, parent, destroyGoOnRelease);
var operation = new LoadGameObjectOperation(package.PackageName, location, position, rotation, parent, destroyGoOnRelease);
OperationSystem.StartOperation(OperationSystem.GLOBAL_SCHEDULER_NAME, operation);
return operation;
}
@@ -23,6 +23,7 @@ public class LoadGameObjectOperation : AsyncOperationBase
Done,
}
private readonly string _packageName;
private readonly string _location;
private readonly Vector3 _positon;
private readonly Quaternion _rotation;
@@ -36,9 +37,10 @@ public class LoadGameObjectOperation : AsyncOperationBase
/// </summary>
public GameObject Go { private set; get; }
public LoadGameObjectOperation(string location, Vector3 position, Quaternion rotation, Transform parent, bool destroyGoOnRelease = false)
public LoadGameObjectOperation(string packageName, string location, Vector3 position, Quaternion rotation, Transform parent, bool destroyGoOnRelease = false)
{
_packageName = packageName;
_location = location;
_positon = position;
_rotation = rotation;
@@ -58,7 +60,8 @@ public class LoadGameObjectOperation : AsyncOperationBase
{
if (_handle == null)
{
_handle = YooAssets.LoadAssetAsync<GameObject>(_location);
var package = YooAssets.GetPackage(_packageName);
_handle = package.LoadAssetAsync<GameObject>(_location);
}
Progress = _handle.Progress;

View File

@@ -50,8 +50,8 @@ namespace YooAsset
{
var manifest = loadPackageManifestOp.Manifest;
var packageBundle = GetPackageBundle(manifest, testLocation);
var options = new DownloadFileOptions(1);
var downloadFileOp = fileSystem.DownloadFileAsync(packageBundle, options);
var options = new DownloadFileOptions(packageBundle, 1);
var downloadFileOp = fileSystem.DownloadFileAsync(options);
OperationSystem.StartOperation(packageName, downloadFileOp);
yield return downloadFileOp;
if (downloadFileOp.Status != EOperationStatus.Succeed)
@@ -70,7 +70,8 @@ namespace YooAsset
{
var manifest = loadPackageManifestOp.Manifest;
var packageBundle = GetPackageBundle(manifest, testLocation);
var loadBundleFileOp = fileSystem.LoadBundleFile(packageBundle);
var loadBundleFileOptions = new LoadBundleOptions(packageBundle);
var loadBundleFileOp = fileSystem.LoadBundleAsync(loadBundleFileOptions);
OperationSystem.StartOperation(packageName, loadBundleFileOp);
yield return loadBundleFileOp;
if (loadBundleFileOp.Status != EOperationStatus.Succeed)

View File

@@ -100,7 +100,7 @@ public class BattleRoom
if (_startWaitTimer.Update(Time.deltaTime))
{
// 生成实体
var assetHandle = YooAssets.LoadAssetAsync<GameObject>("player_ship");
var assetHandle = GameManager.Instance.GamePakcage.LoadAssetAsync<GameObject>("player_ship");
assetHandle.Completed += (AssetHandle handle) =>
{
handle.InstantiateSync(_roomRoot.transform);
@@ -117,7 +117,7 @@ public class BattleRoom
Quaternion spawnRotation = Quaternion.identity;
// 生成实体
var assetHandle = YooAssets.LoadAssetAsync<GameObject>(enemyLocation);
var assetHandle = GameManager.Instance.GamePakcage.LoadAssetAsync<GameObject>(enemyLocation);
assetHandle.Completed += (AssetHandle handle) =>
{
handle.InstantiateSync(spawnPosition, spawnRotation, _roomRoot.transform);
@@ -166,7 +166,7 @@ public class BattleRoom
var msg = message as BattleEventDefine.PlayerDead;
// 创建爆炸效果
var assetHandle = YooAssets.LoadAssetAsync<GameObject>("explosion_player");
var assetHandle = GameManager.Instance.GamePakcage.LoadAssetAsync<GameObject>("explosion_player");
assetHandle.Completed += (AssetHandle handle) =>
{
handle.InstantiateSync(msg.Position, msg.Rotation, _roomRoot.transform);
@@ -181,7 +181,7 @@ public class BattleRoom
var msg = message as BattleEventDefine.EnemyDead;
// 创建爆炸效果
var assetHandle = YooAssets.LoadAssetAsync<GameObject>("explosion_enemy");
var assetHandle = GameManager.Instance.GamePakcage.LoadAssetAsync<GameObject>("explosion_enemy");
assetHandle.Completed += (AssetHandle handle) =>
{
handle.InstantiateSync(msg.Position, msg.Rotation, _roomRoot.transform);
@@ -196,7 +196,7 @@ public class BattleRoom
var msg = message as BattleEventDefine.AsteroidExplosion;
// 创建爆炸效果
var assetHandle = YooAssets.LoadAssetAsync<GameObject>("explosion_asteroid");
var assetHandle = GameManager.Instance.GamePakcage.LoadAssetAsync<GameObject>("explosion_asteroid");
assetHandle.Completed += (AssetHandle handle) =>
{
handle.InstantiateSync(msg.Position, msg.Rotation, _roomRoot.transform);
@@ -211,7 +211,7 @@ public class BattleRoom
var msg = message as BattleEventDefine.PlayerFireBullet;
// 创建子弹实体
var assetHandle = YooAssets.LoadAssetAsync<GameObject>("player_bullet");
var assetHandle = GameManager.Instance.GamePakcage.LoadAssetAsync<GameObject>("player_bullet");
assetHandle.Completed += (AssetHandle handle) =>
{
handle.InstantiateSync(msg.Position, msg.Rotation, _roomRoot.transform);
@@ -223,7 +223,7 @@ public class BattleRoom
var msg = message as BattleEventDefine.EnemyFireBullet;
// 创建子弹实体
var assetHandle = YooAssets.LoadAssetAsync<GameObject>("enemy_bullet");
var assetHandle = GameManager.Instance.GamePakcage.LoadAssetAsync<GameObject>("enemy_bullet");
assetHandle.Completed += (AssetHandle handle) =>
{
handle.InstantiateSync(msg.Position, msg.Rotation, _roomRoot.transform);

View File

@@ -19,6 +19,11 @@ public class GameManager
private readonly EventGroup _eventGroup = new EventGroup();
/// <summary>
/// 游戏包裹
/// </summary>
public ResourcePackage GamePakcage;
/// <summary>
/// 协程启动器
/// </summary>
@@ -47,11 +52,11 @@ public class GameManager
{
if (message is SceneEventDefine.ChangeToHomeScene)
{
YooAssets.LoadSceneAsync("scene_home");
GamePakcage.LoadSceneAsync("scene_home");
}
else if (message is SceneEventDefine.ChangeToBattleScene)
{
YooAssets.LoadSceneAsync("scene_battle");
GamePakcage.LoadSceneAsync("scene_battle");
}
}
}

View File

@@ -14,12 +14,12 @@ internal class SceneBattle : MonoBehaviour
private IEnumerator Start()
{
// 加载战斗页面
_windowHandle = YooAssets.LoadAssetAsync<GameObject>("UIBattle");
_windowHandle = GameManager.Instance.GamePakcage.LoadAssetAsync<GameObject>("UIBattle");
yield return _windowHandle;
_windowHandle.InstantiateSync(CanvasDesktop.transform);
// 加载背景音乐
_musicHandle = YooAssets.LoadAssetAsync<AudioClip>("music_background");
_musicHandle = GameManager.Instance.GamePakcage.LoadAssetAsync<AudioClip>("music_background");
yield return _musicHandle;
// 播放背景音乐

View File

@@ -11,7 +11,7 @@ public class SceneHome : MonoBehaviour
private IEnumerator Start()
{
// 加载主页面
_windowHandle = YooAssets.LoadAssetAsync<GameObject>("UIHome");
_windowHandle = GameManager.Instance.GamePakcage.LoadAssetAsync<GameObject>("UIHome");
yield return _windowHandle;
_windowHandle.InstantiateSync(CanvasDesktop.transform);

View File

@@ -40,10 +40,13 @@ internal class FsmInitializePackage : IStateNode
InitializationOperation initializationOperation = null;
if (playMode == EPlayMode.EditorSimulateMode)
{
var buildResult = EditorSimulateModeHelper.SimulateBuild(packageName);
var buildResult = EditorSimulateBuildInvoker.Build(packageName);
var packageRoot = buildResult.PackageRootDirectory;
var createParameters = new EditorSimulateModeParameters();
createParameters.EditorFileSystemParameters = FileSystemParameters.CreateDefaultEditorFileSystemParameters(packageRoot);
createParameters.EditorFileSystemParameters.AddParameter(FileSystemParametersDefine.VIRTUAL_WEBGL_MODE, true);
createParameters.EditorFileSystemParameters.AddParameter(FileSystemParametersDefine.VIRTUAL_DOWNLOAD_MODE, true);
createParameters.EditorFileSystemParameters.AddParameter(FileSystemParametersDefine.VIRTUAL_DOWNLOAD_SPEED, 1024 * 1000);
initializationOperation = package.InitializeAsync(createParameters);
}
@@ -63,7 +66,11 @@ internal class FsmInitializePackage : IStateNode
IRemoteServices remoteServices = new RemoteServices(defaultHostServer, fallbackHostServer);
var createParameters = new HostPlayModeParameters();
createParameters.BuildinFileSystemParameters = FileSystemParameters.CreateDefaultBuildinFileSystemParameters();
createParameters.BuildinFileSystemParameters.AddParameter(FileSystemParametersDefine.COPY_BUILDIN_PACKAGE_MANIFEST, true);
createParameters.CacheFileSystemParameters = FileSystemParameters.CreateDefaultCacheFileSystemParameters(remoteServices);
createParameters.CacheFileSystemParameters.AddParameter(FileSystemParametersDefine.DOWNLOAD_MAX_CONCURRENCY, 5);
createParameters.CacheFileSystemParameters.AddParameter(FileSystemParametersDefine.DOWNLOAD_MAX_REQUEST_PER_FRAME, 1);
createParameters.CacheFileSystemParameters.AddParameter(FileSystemParametersDefine.DOWNLOAD_WATCH_DOG_TIME, 10);
initializationOperation = package.InitializeAsync(createParameters);
}

View File

@@ -14,8 +14,7 @@ internal class FsmStartGame : IStateNode
PatchEventDefine.PatchStepsChange.SendEventMessage("开始游戏!");
// 设置默认的资源包
var gamePackage = YooAssets.GetPackage("DefaultPackage");
YooAssets.SetDefaultPackage(gamePackage);
GameManager.Instance.GamePakcage = YooAssets.GetPackage("DefaultPackage");
// 切换到主页面场景
SceneEventDefine.ChangeToHomeScene.SendEventMessage();

View File

@@ -22,7 +22,7 @@ public static class TestPackageBuilder
buildParameters.BuildOutputRoot = outputRoot;
buildParameters.BuildinFileRoot = AssetBundleBuilderHelper.GetStreamingAssetsRoot();
buildParameters.BuildPipeline = EBuildPipeline.EditorSimulateBuildPipeline.ToString();
buildParameters.BuildBundleType = (int)EBuildBundleType.VirtualBundle;
buildParameters.BuildBundleType = (int)EBundleType.VirtualBundle;
buildParameters.BuildTarget = EditorUserBuildSettings.activeBuildTarget;
buildParameters.PackageName = packageName;
buildParameters.PackageVersion = "TestVersion";
@@ -58,7 +58,7 @@ public static class TestPackageBuilder
buildParameters.BuildOutputRoot = outputRoot;
buildParameters.BuildinFileRoot = AssetBundleBuilderHelper.GetStreamingAssetsRoot();
buildParameters.BuildPipeline = EBuildPipeline.ScriptableBuildPipeline.ToString();
buildParameters.BuildBundleType = (int)EBuildBundleType.AssetBundle;
buildParameters.BuildBundleType = (int)EBundleType.AssetBundle;
buildParameters.BuildTarget = EditorUserBuildSettings.activeBuildTarget;
buildParameters.PackageName = packageName;
buildParameters.PackageVersion = "TestVersion";
@@ -98,7 +98,7 @@ public static class TestPackageBuilder
buildParameters.BuildOutputRoot = outputRoot;
buildParameters.BuildinFileRoot = AssetBundleBuilderHelper.GetStreamingAssetsRoot();
buildParameters.BuildPipeline = EBuildPipeline.ScriptableBuildPipeline.ToString();
buildParameters.BuildBundleType = (int)EBuildBundleType.AssetBundle;
buildParameters.BuildBundleType = (int)EBundleType.AssetBundle;
buildParameters.BuildTarget = EditorUserBuildSettings.activeBuildTarget;
buildParameters.PackageName = packageName;
buildParameters.PackageVersion = "TestVersion";
@@ -137,7 +137,7 @@ public static class TestPackageBuilder
buildParameters.BuildOutputRoot = outputRoot;
buildParameters.BuildinFileRoot = AssetBundleBuilderHelper.GetStreamingAssetsRoot();
buildParameters.BuildPipeline = EBuildPipeline.RawFileBuildPipeline.ToString();
buildParameters.BuildBundleType = (int)EBuildBundleType.RawBundle;
buildParameters.BuildBundleType = (int)EBundleType.RawBundle;
buildParameters.BuildTarget = EditorUserBuildSettings.activeBuildTarget;
buildParameters.PackageName = packageName;
buildParameters.PackageVersion = "TestVersion";

View File

@@ -8,9 +8,9 @@ using YooAsset;
/// <summary>
/// 文件偏移加密方式
/// </summary>
public class TestFileOffsetEncryption : IEncryptionServices
public class TestFileOffsetEncryption : IBundleEncryptionServices
{
public EncryptResult Encrypt(EncryptFileInfo fileInfo)
public EncryptResult Encrypt(EncryptBundleInfo fileInfo)
{
// 说明对TestRes3资源目录进行加密
if (fileInfo.BundleName.Contains("_testres3_"))
@@ -37,15 +37,15 @@ public class TestFileOffsetEncryption : IEncryptionServices
/// <summary>
/// 资源文件偏移解密类
/// </summary>
public class TestFileOffsetDecryption : IDecryptionServices
public class TestFileOffsetDecryption : IBundleDecryptionServices
{
/// <summary>
/// 同步方式获取解密的资源包对象
/// 注意:加载流对象在资源包对象释放的时候会自动释放
/// </summary>
DecryptResult IDecryptionServices.LoadAssetBundle(DecryptFileInfo fileInfo)
DecryptSyncResult IBundleDecryptionServices.LoadAssetBundleSync(DecryptBundleInfo fileInfo)
{
DecryptResult decryptResult = new DecryptResult();
var decryptResult = new DecryptSyncResult();
decryptResult.ManagedStream = null;
decryptResult.Result = AssetBundle.LoadFromFile(fileInfo.FileLoadPath, fileInfo.FileLoadCRC, GetFileOffset());
return decryptResult;
@@ -55,9 +55,9 @@ public class TestFileOffsetDecryption : IDecryptionServices
/// 异步方式获取解密的资源包对象
/// 注意:加载流对象在资源包对象释放的时候会自动释放
/// </summary>
DecryptResult IDecryptionServices.LoadAssetBundleAsync(DecryptFileInfo fileInfo)
DecryptAsyncResult IBundleDecryptionServices.LoadAssetBundleAsync(DecryptBundleInfo fileInfo)
{
DecryptResult decryptResult = new DecryptResult();
DecryptAsyncResult decryptResult = new DecryptAsyncResult();
decryptResult.ManagedStream = null;
decryptResult.CreateRequest = AssetBundle.LoadFromFileAsync(fileInfo.FileLoadPath, fileInfo.FileLoadCRC, GetFileOffset());
return decryptResult;
@@ -66,15 +66,15 @@ public class TestFileOffsetDecryption : IDecryptionServices
/// <summary>
/// 后备方式获取解密的资源包对象
/// </summary>
DecryptResult IDecryptionServices.LoadAssetBundleFallback(DecryptFileInfo fileInfo)
DecryptSyncResult IBundleDecryptionServices.LoadAssetBundleFallback(DecryptBundleInfo fileInfo)
{
return new DecryptResult();
return new DecryptSyncResult();
}
/// <summary>
/// 获取解密的字节数据
/// </summary>
byte[] IDecryptionServices.ReadFileData(DecryptFileInfo fileInfo)
byte[] IBundleDecryptionServices.ReadFileData(DecryptBundleInfo fileInfo)
{
throw new System.NotImplementedException();
}
@@ -82,7 +82,7 @@ public class TestFileOffsetDecryption : IDecryptionServices
/// <summary>
/// 获取解密的文本数据
/// </summary>
string IDecryptionServices.ReadFileText(DecryptFileInfo fileInfo)
string IBundleDecryptionServices.ReadFileText(DecryptBundleInfo fileInfo)
{
throw new System.NotImplementedException();
}

View File

@@ -33,9 +33,9 @@ public class BundleStream : FileStream
/// <summary>
/// 文件流加密方式
/// </summary>
public class TestFileStreamEncryption : IEncryptionServices
public class TestFileStreamEncryption : IBundleEncryptionServices
{
public EncryptResult Encrypt(EncryptFileInfo fileInfo)
public EncryptResult Encrypt(EncryptBundleInfo fileInfo)
{
// 说明对TestRes3资源目录进行加密
if (fileInfo.BundleName.Contains("_testres3_"))
@@ -63,15 +63,15 @@ public class TestFileStreamEncryption : IEncryptionServices
/// <summary>
/// 资源文件流解密类
/// </summary>
public class TestFileStreamDecryption : IDecryptionServices
public class TestFileStreamDecryption : IBundleDecryptionServices
{
/// <summary>
/// 同步方式获取解密的资源包对象
/// </summary>
DecryptResult IDecryptionServices.LoadAssetBundle(DecryptFileInfo fileInfo)
DecryptSyncResult IBundleDecryptionServices.LoadAssetBundleSync(DecryptBundleInfo fileInfo)
{
BundleStream bundleStream = new BundleStream(fileInfo.FileLoadPath, FileMode.Open, FileAccess.Read, FileShare.Read);
DecryptResult decryptResult = new DecryptResult();
var decryptResult = new DecryptSyncResult();
decryptResult.ManagedStream = bundleStream;
decryptResult.Result = AssetBundle.LoadFromStream(bundleStream, fileInfo.FileLoadCRC, GetManagedReadBufferSize());
return decryptResult;
@@ -80,10 +80,10 @@ public class TestFileStreamDecryption : IDecryptionServices
/// <summary>
/// 异步方式获取解密的资源包对象
/// </summary>
DecryptResult IDecryptionServices.LoadAssetBundleAsync(DecryptFileInfo fileInfo)
DecryptAsyncResult IBundleDecryptionServices.LoadAssetBundleAsync(DecryptBundleInfo fileInfo)
{
BundleStream bundleStream = new BundleStream(fileInfo.FileLoadPath, FileMode.Open, FileAccess.Read, FileShare.Read);
DecryptResult decryptResult = new DecryptResult();
var decryptResult = new DecryptAsyncResult();
decryptResult.ManagedStream = bundleStream;
decryptResult.CreateRequest = AssetBundle.LoadFromStreamAsync(bundleStream, fileInfo.FileLoadCRC, GetManagedReadBufferSize());
return decryptResult;
@@ -94,11 +94,11 @@ public class TestFileStreamDecryption : IDecryptionServices
/// 注意:当正常解密方法失败后,会触发后备加载!
/// 说明建议通过LoadFromMemory()方法加载资源包作为保底机制。
/// </summary>
DecryptResult IDecryptionServices.LoadAssetBundleFallback(DecryptFileInfo fileInfo)
DecryptSyncResult IBundleDecryptionServices.LoadAssetBundleFallback(DecryptBundleInfo fileInfo)
{
byte[] fileData = File.ReadAllBytes(fileInfo.FileLoadPath);
var assetBundle = AssetBundle.LoadFromMemory(fileData);
DecryptResult decryptResult = new DecryptResult();
var decryptResult = new DecryptSyncResult();
decryptResult.Result = assetBundle;
return decryptResult;
}
@@ -106,7 +106,7 @@ public class TestFileStreamDecryption : IDecryptionServices
/// <summary>
/// 获取解密的字节数据
/// </summary>
byte[] IDecryptionServices.ReadFileData(DecryptFileInfo fileInfo)
byte[] IBundleDecryptionServices.ReadFileData(DecryptBundleInfo fileInfo)
{
throw new System.NotImplementedException();
}
@@ -114,7 +114,7 @@ public class TestFileStreamDecryption : IDecryptionServices
/// <summary>
/// 获取解密的文本数据
/// </summary>
string IDecryptionServices.ReadFileText(DecryptFileInfo fileInfo)
string IBundleDecryptionServices.ReadFileText(DecryptBundleInfo fileInfo)
{
throw new System.NotImplementedException();
}
@@ -129,9 +129,9 @@ public class TestFileStreamDecryption : IDecryptionServices
/// WebGL平台解密类
/// 注意WebGL平台支持内存解密
/// </summary>
public class TestWebFileMemoryDecryption : IWebDecryptionServices
public class TestWebFileMemoryDecryption : IWebBundleDecryptionServices
{
public WebDecryptResult LoadAssetBundle(WebDecryptFileInfo fileInfo)
public WebDecryptSyncResult LoadAssetBundleSync(WebDecryptBundleInfo fileInfo)
{
/*
byte[] copyData = new byte[fileInfo.FileData.Length];
@@ -152,7 +152,7 @@ public class TestWebFileMemoryDecryption : IWebDecryptionServices
fileInfo.FileData[i] ^= BundleStream.KEY;
}
WebDecryptResult decryptResult = new WebDecryptResult();
WebDecryptSyncResult decryptResult = new WebDecryptSyncResult();
decryptResult.Result = AssetBundle.LoadFromMemory(fileInfo.FileData);
return decryptResult;
}

View File

@@ -23,7 +23,8 @@ public class TestBundleEncryption
yield return assetHandle;
Assert.AreEqual(EOperationStatus.Succeed, assetHandle.Status);
var go = assetHandle.InstantiateSync(Vector3.zero, Quaternion.identity);
var options = new InstantiateOptions(true, Vector3.zero, Quaternion.identity);
var go = assetHandle.InstantiateSync(options);
Assert.IsNotNull(go);
}
@@ -33,7 +34,8 @@ public class TestBundleEncryption
var assetHandle = package.LoadAssetSync<GameObject>("prefab_encryptB");
Assert.AreEqual(EOperationStatus.Succeed, assetHandle.Status);
var go = assetHandle.InstantiateSync(Vector3.zero, Quaternion.identity);
var options = new InstantiateOptions(true, Vector3.zero, Quaternion.identity);
var go = assetHandle.InstantiateSync(options);
Assert.IsNotNull(go);
}
}

View File

@@ -23,7 +23,8 @@ public class TestBundleReference
Assert.AreEqual(EOperationStatus.Succeed, assetHandle.Status);
var pos = new Vector3(-1, -1, 0);
var go = assetHandle.InstantiateSync(pos, Quaternion.identity);
var options = new InstantiateOptions(true, pos, Quaternion.identity);
var go = assetHandle.InstantiateSync(options);
Assert.IsNotNull(go);
}
@@ -36,7 +37,8 @@ public class TestBundleReference
Assert.AreEqual(EOperationStatus.Succeed, heroHandle.Status);
var pos = new Vector3(1, -1, 0);
heroObject = heroHandle.InstantiateSync(pos, Quaternion.identity);
var options = new InstantiateOptions(true, pos, Quaternion.identity);
heroObject = heroHandle.InstantiateSync(options);
Assert.IsNotNull(heroObject);
}
@@ -61,7 +63,8 @@ public class TestBundleReference
Assert.AreEqual(EOperationStatus.Succeed, heroHandle.Status);
var pos = new Vector3(1, -1, 0);
heroObject = heroHandle.InstantiateSync(pos, Quaternion.identity);
var options = new InstantiateOptions(true, pos, Quaternion.identity);
heroObject = heroHandle.InstantiateSync(options);
Assert.IsNotNull(heroObject);
// 检测材质球关联的纹理是否为空

View File

@@ -16,7 +16,8 @@ public class TestBundleUnpacker
ResourcePackage package = YooAssets.GetPackage(TestDefine.AssetBundlePackageName);
Assert.IsNotNull(package);
var resourceUnpacker = package.CreateResourceUnpacker("unpack", 10, 1);
var options = new ResourceUnpackerOptions("unpack", 10, 1);
var resourceUnpacker = package.CreateResourceUnpacker(options);
Assert.AreEqual(resourceUnpacker.TotalDownloadCount, 2);
resourceUnpacker.BeginDownload();

View File

@@ -16,7 +16,8 @@ public class TestBundleDownloader
ResourcePackage package = YooAssets.GetPackage(TestDefine.AssetBundlePackageName);
Assert.IsNotNull(package);
var downloader = package.CreateResourceDownloader(10, 1);
var options = new ResourceDownloaderOptions(10, 1);
var downloader = package.CreateResourceDownloader(options);
Assert.AreNotEqual(downloader.TotalDownloadCount, 0);
downloader.BeginDownload();

View File

@@ -20,16 +20,17 @@ public class TestBundleImporter
DirectoryInfo packageDir = new DirectoryInfo(packageRoot);
string fileRoot = $"{packageDir.Parent.FullName}/OutputCache";
ImportFileInfo fileInfoA = new ImportFileInfo();
ImportBundleInfo fileInfoA = new ImportBundleInfo();
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();
ImportBundleInfo fileInfoB = new ImportBundleInfo();
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);
ImportBundleInfo[] importInfos = { fileInfoA, fileInfoB };
var options = new BundleImporterOptions(importInfos, 10, 1);
var unpacker = package.CreateResourceImporter(options);
Assert.AreEqual(unpacker.TotalDownloadCount, 2);
unpacker.BeginDownload();

View File

@@ -52,7 +52,7 @@ public class TestLoadScene
// 异步销毁附加场景
yield return new WaitForSeconds(0.2f);
{
var unloadSceneOp = cachedHandle.UnloadAsync();
var unloadSceneOp = cachedHandle.UnloadSceneAsync();
yield return unloadSceneOp;
Assert.AreEqual(EOperationStatus.Succeed, unloadSceneOp.Status);
}