2022-08-01 11:51:35 +08:00
|
|
|
|
# 解决方案
|
|
|
|
|
|
2022-08-01 11:54:48 +08:00
|
|
|
|
### FairyGUI支持解决方案
|
2022-08-01 11:51:35 +08:00
|
|
|
|
|
|
|
|
|
注意:在FairyGUI的面板销毁的时候,将资源句柄列表释放,否则会造成资源泄漏。
|
|
|
|
|
|
|
|
|
|
````c#
|
|
|
|
|
// 资源句柄列表
|
|
|
|
|
private List<AssetOperationHandle> _handles = new List<AssetOperationHandle>(100);
|
|
|
|
|
|
|
|
|
|
// 加载方法
|
|
|
|
|
private object LoadFunc(string name, string extension, System.Type type, out DestroyMethod method)
|
|
|
|
|
{
|
|
|
|
|
method = DestroyMethod.None; //注意:这里一定要设置为None
|
2022-10-22 10:51:14 +08:00
|
|
|
|
string location = $"Assets/FairyRes/{name}{extension}";
|
2023-03-30 17:41:42 +08:00
|
|
|
|
var package = YooAssets.GetPackage("DefaultPackage");
|
|
|
|
|
var handle = package.LoadAssetSync(location , type);
|
2022-08-01 11:51:35 +08:00
|
|
|
|
_handles.Add(handle);
|
|
|
|
|
return handle.AssetObject;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 执行FairyGUI的添加包函数
|
|
|
|
|
UIPackage.AddPackage(name, LoadFunc);
|
|
|
|
|
|
|
|
|
|
// 释放资源句柄列表
|
|
|
|
|
private void ReleaseHandles()
|
|
|
|
|
{
|
|
|
|
|
foreach(var handle in _handles)
|
|
|
|
|
{
|
|
|
|
|
handle.Release();
|
|
|
|
|
}
|
|
|
|
|
_handles.Clear();
|
|
|
|
|
}
|
|
|
|
|
````
|
|
|
|
|
|
2022-08-01 11:54:48 +08:00
|
|
|
|
### UniTask支持解决方案
|
2022-08-01 11:51:35 +08:00
|
|
|
|
|
2023-03-17 11:56:10 +08:00
|
|
|
|
详情参考 [UniTask 配置教程](../Assets/YooAsset/Samples~/UniTask%20Sample/README.md)
|
2022-10-08 16:25:36 +08:00
|
|
|
|
|
|
|
|
|
### 分布式构建解决方案
|
|
|
|
|
|
|
|
|
|
**1.3.0+版本升级指南**
|
|
|
|
|
|
|
|
|
|
在升级之前请导出AssetBundleCollector的配置为XML文件,然后升级YooAssets库。
|
|
|
|
|
|
|
|
|
|
首次需要打开AssetBundleCollector窗口,然后导入之前保存的XML文件。
|
|
|
|
|
|
|
|
|
|
在运行游戏之前,请保证资源包可以构建成功!
|
|
|
|
|
|
|
|
|
|
```c#
|
|
|
|
|
IEnumerator Start()
|
|
|
|
|
{
|
|
|
|
|
// 初始化YooAssets资源系统(必须代码)
|
|
|
|
|
YooAssets.Initialize();
|
|
|
|
|
|
|
|
|
|
// 创建资源包实例
|
2023-03-30 17:41:42 +08:00
|
|
|
|
var package = YooAssets.CreatePackage("DefaultPackage");
|
2022-10-08 16:25:36 +08:00
|
|
|
|
|
|
|
|
|
// 初始化资源包
|
|
|
|
|
......
|
2022-10-22 10:51:14 +08:00
|
|
|
|
yield return package.InitializeAsync(createParameters);
|
2022-10-08 16:25:36 +08:00
|
|
|
|
|
|
|
|
|
// 更新资源包版本
|
|
|
|
|
......
|
2022-11-21 09:52:18 +08:00
|
|
|
|
var operation = package.UpdatePackageManifestAsync(packageCRC);
|
2022-10-08 16:36:07 +08:00
|
|
|
|
yield return operation;
|
2022-10-08 16:25:36 +08:00
|
|
|
|
|
|
|
|
|
// 下载更新文件
|
2022-10-22 10:51:14 +08:00
|
|
|
|
var downloader = package.CreatePatchDownloader(downloadingMaxNum, failedTryAgain);
|
2022-10-08 16:25:36 +08:00
|
|
|
|
downloader.BeginDownload();
|
|
|
|
|
yield return downloader;
|
|
|
|
|
|
|
|
|
|
// 加载资源对象
|
2022-10-22 10:51:14 +08:00
|
|
|
|
var assetHandle = package.LoadAssetAsync("Assets/GameRes/npc.prefab");
|
2022-10-08 16:25:36 +08:00
|
|
|
|
yield return assetHandle;
|
|
|
|
|
......
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|