/// <summary> /// 특정 오브젝트를 풀에 반환하고 비활성화 시키는 역할입니다. /// </summary> /// <param name="obj">반환할 오브젝트</param> public void Return(PooledUnityObject obj) { obj.gameObject.SetActive(false); if (activePool.Contains(obj)) { activePool.Remove(obj); } objectPool.Add(obj); }
public void Allocate(int alloCount) { //poolCount 초과 시 만들고 List에 추가 for (int i = 0; i < alloCount; ++i) { PooledUnityObject obj = GameObject.Instantiate <PooledUnityObject>(pooledObj); obj.name = assetName + i.ToString(); //objectPool.Add(obj); //obj.gameObject.SetActive(false); Return(obj); } }
/// <summary> /// 모든 오브젝트들을 없애고, 풀 자체를 해제해주는 역할입니다. /// 게임이 끝났을 때, 풀을 없애야할 때 불러줍니다. /// </summary> public void Dispose() { if (objectPool == null) { return; } ReturnAll(); for (int i = 0; i < objectPool.Count; i++) { PooledUnityObject obj = objectPool[i]; GameObject.Destroy(obj.gameObject); } objectPool = null; }
/// <summary> /// 현재 사용하고 있는 오브젝트들을 전부 반환하고, 비활성화 시키는 역할입니다. /// </summary> public void ReturnAll() { if (objectPool == null) { return; } for (int i = 0; i < objectPool.Count; i++) { PooledUnityObject activeObj = activePool[i]; if (activeObj != null) { Return(activeObj); } } }