using System; using System.Collections.Generic; using UnityEngine; using UnityEngine.Pool; using XRLib; using XED.Interfaces; namespace XED.Manage { //TODO::Àüü ¼öÁ¤ ÇÊ¿ä. °³º°ÀûÀÎ ObjectPoolÀÌ Á¸ÀçÇϰí ÀÌ ¸Å´ÏÀú´Â ±×¿¡ ´ëÇÑ Á¢±Ù API¸¸ Á¦°øÇÏ¸é µÊ. public class ObjectPoolManager : MonoBehaviour, ISingle { [Serializable] public class ObjectInfo { //public Type objectType; public GameObject prefab; public int count; public ObjectInfo(GameObject item, int count) { this.prefab = item; this.count = count; } } public List objectInfos = new(); HashSet cachingTypes = new(); Dictionary> cachingPools = new(); Dictionary prefabTable = new(); public void AddObjectInfo(GameObject pool) { var item = new ObjectInfo(pool, 3); pool.gameObject.SetActive(false); objectInfos.Add(item); } public T Get() where T : Component { ObjectInfo targetInfo = null; if (!cachingTypes.Contains(typeof(T))) { foreach(var info in objectInfos) { if (!info.prefab.TryGetComponent(out T comp)) continue; prefabTable.Add(typeof(T), info.prefab); cachingTypes.Add(typeof(T)); var newPool = new ObjectPool (Create, Get, Release, Destroy, true, info.count); Component Create() { var result = Instantiate(comp); result.GetComponent().Pool = cachingPools[typeof(T)]; return result.GetComponent(); } cachingPools.Add(typeof(T), newPool); targetInfo = info; break; } } if(!cachingTypes.Contains(typeof(T))) { Debug.LogError($"{typeof(T)} is NOT POOL"); return default; } return cachingPools[typeof(T)].Get().GetComponent(); } void Get(Component comp) { comp.gameObject.SetActive(true); } void Release(Component comp) { //comp.gameObject.SetActive(false); } void Destroy(Component comp) { } } }