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(); +} +```` +