EffectUIPool.cs 982 B

123456789101112131415161718192021222324252627282930313233343536
  1. using FairyGUI;
  2. using System.Collections.Generic;
  3. namespace GFGGame
  4. {
  5. public static class EffectUIPool
  6. {
  7. private static List<EffectUI> effectUIs = new List<EffectUI>();
  8. public static EffectUI CreateEffectUI(GGraph holder, string uiName, string resName, float scale = 100)
  9. {
  10. EffectUI effectUI;
  11. if (effectUIs.Count > 0)
  12. {
  13. int lastIndex = effectUIs.Count - 1;
  14. effectUI = effectUIs[lastIndex];
  15. effectUIs.RemoveAt(lastIndex);
  16. }
  17. else
  18. {
  19. effectUI = new EffectUI();
  20. }
  21. effectUI.Reset(holder, uiName, resName, scale);
  22. return effectUI;
  23. }
  24. public static void Recycle(EffectUI effect)
  25. {
  26. if (effect == null) return;
  27. effect.Release();
  28. if (effectUIs.Contains(effect)) return;
  29. effectUIs.Add(effect);
  30. }
  31. }
  32. }