| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- using FairyGUI;
- using System.Collections.Generic;
- using System;
- namespace GFGGame
- {
- public static class EffectUIPool
- {
- private static List<EffectUI> effectUIs = new List<EffectUI>();
- public static void CreateEffectUI(GGraph holder, string uiName, string resName, float scale = 100,
- Action<EffectUI> 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);
- }
- }
- }
|