From efd0789e09b1a43ccdfd87d55cfc6dd5a704df1d Mon Sep 17 00:00:00 2001 From: hevinci Date: Thu, 7 Apr 2022 12:05:21 +0800 Subject: [PATCH] Update document --- Docs/CodeTutorial3.md | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/Docs/CodeTutorial3.md b/Docs/CodeTutorial3.md index c468d85..3ff2c38 100644 --- a/Docs/CodeTutorial3.md +++ b/Docs/CodeTutorial3.md @@ -121,3 +121,32 @@ IEnumerator Start() } ```` +**FairyGUI加载方案** + +注意:在FairyGUI的面板销毁的时候,将资源句柄列表释放,否则会造成资源泄漏。 + +````c# +// 资源句柄列表 +private List _handles = new List(100); + +// 加载方法 +private object LoadFunc(string name, string extension, System.Type type, out DestroyMethod method) +{ + method = DestroyMethod.None; + string location = $"FairyRes/{name}{extension}"; + var handle = YooAssets.LoadAssetSync(location , type); + _handles.Add(handle); + return handle.AssetObject; +} + +// 释放资源句柄列表 +private void ReleaseHandles() +{ + foreach(var handle in _handles) + { + handle.Release(); + } + _handles.Clear(); +} +```` +