#define Graph_And_Chart_PRO using System; using System.Collections.Generic; using System.Linq; using System.Text; using UnityEngine; namespace ChartAndGraph { /// /// pools gameobjects for repeated use /// /// class GameObjectPool where T : MonoBehaviour { List mPool = new List(); public void RecycleObject(T obj) { mPool.Add(obj); } public T TakeObject() { if (mPool.Count == 0) return default(T); int last = mPool.Count - 1; T res = mPool[last]; mPool.RemoveAt(last); if (res.gameObject.activeInHierarchy == false) res.gameObject.SetActive(true); return res; } public void DestoryAll() { for (int i = 0; i < mPool.Count; i++) { T t = mPool[i]; if (t != null && t.gameObject != null) { ChartCommon.SafeDestroy(t.gameObject); } } mPool.Clear(); } public void DeactivateObjects() { for (int i = 0; i < mPool.Count; i++) { T t = mPool[i]; if (t != null && t.gameObject != null) { if (t.gameObject.activeInHierarchy) t.gameObject.SetActive(false); } } } } }