YooAsset/Docs/CodeTutorial4.md

38 lines
1018 B
Markdown
Raw Normal View History

2022-08-01 11:51:35 +08:00
# 解决方案
**FairyGUI支持解决方案**
注意在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
string location = $"FairyRes/{name}{extension}";
var handle = YooAssets.LoadAssetSync(location , type);
_handles.Add(handle);
return handle.AssetObject;
}
// 执行FairyGUI的添加包函数
UIPackage.AddPackage(name, LoadFunc);
// 释放资源句柄列表
private void ReleaseHandles()
{
foreach(var handle in _handles)
{
handle.Release();
}
_handles.Clear();
}
````
**UniTask支持解决方案**
[解决方案](https://github.com/tuyoogame/YooAsset/blob/master/Assets/YooAsset/Samples~/UniTask Sample/README.md)