//-------------------------------------------------------- // [Author]: 第二世界 // [ Date ]: Saturday, December 09, 2017 //-------------------------------------------------------- using UnityEngine; using System.Collections; using UnityEngine.UI; using System.Collections.Generic; namespace vnxbqy.UI { public class DialogueBubblePool { static Dictionary pools = new Dictionary(); public static DialogueBubble Require(DialogueBubble.Pattern _pattern) { var intPattern = (int)_pattern; GameObjectPoolManager.GameObjectPool pool = null; if (!pools.ContainsKey(intPattern)) { var prefab = UILoader.LoadPrefab(StringUtility.Contact("DialogueBubble_", _pattern)); if (prefab != null) { pool = GameObjectPoolManager.Instance.RequestPool(prefab); pools[intPattern] = pool; } } else { pool = pools[intPattern]; } if (pool != null) { var instance = pool.Request(); var dialogueBubble = instance.GetComponent(); dialogueBubble.pattern = _pattern; return dialogueBubble; } else { return null; } } public static void Recycle(DialogueBubble _dialogueBubble) { var intPattern = (int)_dialogueBubble.pattern; if (pools.ContainsKey(intPattern)) { var pool = pools[intPattern]; pool.Release(_dialogueBubble.gameObject); _dialogueBubble.transform.SetParent(null); _dialogueBubble.SetActive(false); } } public static void Clear() { foreach (var pool in pools.Values) { pool.Clear(); } pools.Clear(); } } }