using System.Collections; using System.Collections.Generic; using UnityEngine; using System; namespace vnxbqy.UI { public class PopUpNumPool { public static event Action recycleAllEvent; static Dictionary pools = new Dictionary(); public static PopUpNum Require(PopUpNum.Pattern _pattern) { GameObjectPoolManager.GameObjectPool pool = null; var poolKey = (int)_pattern; if (!pools.ContainsKey(poolKey)) { var prefab = UILoader.LoadPrefab(StringUtility.Contact("PopUpNum_", _pattern)); if (prefab != null) { pool = GameObjectPoolManager.Instance.RequestPool(prefab); pools[poolKey] = pool; } } else { pool = pools[poolKey]; } if (pool != null) { var instance = pool.Request(); var popupNum = instance.GetComponent(); popupNum.pattern = _pattern; popupNum.enabled = true; return popupNum; } else { return null; } } public static void Recycle(PopUpNum _popupNum) { var pattern = _popupNum.pattern; GameObjectPoolManager.GameObjectPool pool; if (pools.TryGetValue((int)pattern, out pool)) { pool.Release(_popupNum.gameObject); _popupNum.SetEnable(false); } } public static void RecycleAll() { if (recycleAllEvent != null) { recycleAllEvent(); } } public static void Clear() { foreach (var key in pools.Keys) { var pool = pools[key]; if (pool != null) { pool.Clear(); } } pools.Clear(); } } }