EffectUIPool.cs 1.0 KB

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