EffectUIPool.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. using FairyGUI;
  2. using System.Collections.Generic;
  3. using System;
  4. namespace GFGGame
  5. {
  6. public static class EffectUIPool
  7. {
  8. private static List<EffectUI> effectUIs = new List<EffectUI>();
  9. public static void CreateEffectUI(GGraph holder, string uiName, string resName, float scale = 100,
  10. Action<EffectUI> onComplete = null)
  11. {
  12. EffectUI effectUI;
  13. if (effectUIs.Count > 0)
  14. {
  15. int lastIndex = effectUIs.Count - 1;
  16. effectUI = effectUIs[lastIndex];
  17. effectUIs.RemoveAt(lastIndex);
  18. }
  19. else
  20. {
  21. effectUI = new EffectUI();
  22. }
  23. effectUI.Reset(holder, uiName, resName, scale, EffectUIType.UI, (success) => {
  24. if (success)
  25. {
  26. onComplete?.Invoke(effectUI);
  27. }
  28. else
  29. {
  30. // 加载失败,回收effectUI
  31. Recycle(effectUI);
  32. onComplete?.Invoke(null);
  33. }
  34. });
  35. }
  36. public static void Recycle(EffectUI effect)
  37. {
  38. if (effect == null) return;
  39. effect.Release();
  40. if (effectUIs.Contains(effect)) return;
  41. effectUIs.Add(effect);
  42. }
  43. }
  44. }