using FairyGUI; using System.Collections.Generic; using System; namespace GFGGame { public static class EffectUIPool { private static List effectUIs = new List(); public static void CreateEffectUI(GGraph holder, string uiName, string resName, float scale = 100, Action onComplete = null) { EffectUI effectUI; if (effectUIs.Count > 0) { int lastIndex = effectUIs.Count - 1; effectUI = effectUIs[lastIndex]; effectUIs.RemoveAt(lastIndex); } else { effectUI = new EffectUI(); } effectUI.Reset(holder, uiName, resName, scale, EffectUIType.UI, (success) => { if (success) { onComplete?.Invoke(effectUI); } else { // 加载失败,回收effectUI Recycle(effectUI); onComplete?.Invoke(null); } }); } public static void Recycle(EffectUI effect) { if (effect == null) return; effect.Release(); if (effectUIs.Contains(effect)) return; effectUIs.Add(effect); } } }