/// <summary> /// Retrieves a PooledList for use, copying the contents /// of the given IEnumerable. /// </summary> static public PooledList <T> Create(IEnumerable <T> inToCopy) { PooledList <T> list = s_ObjectPool.Alloc(); list.AddRange(inToCopy); return(list); }
/// <summary> /// Returns all currently allocated prefabs to the pool. /// </summary> public void Reset() { if (m_InnerPool != null && m_ActiveObjects.Count > 0) { using (PooledList <T> tempList = PooledList <T> .Create(m_ActiveObjects)) { m_InnerPool.Free(tempList); } } }
private void OnFreeCheckComponents(IPool <T> inPool, T inElement) { using (PooledList <IPoolAllocHandler> children = PooledList <IPoolAllocHandler> .Create()) { inElement.GetComponentsInChildren <IPoolAllocHandler>(true, children); for (int i = 0, length = children.Count; i < length; ++i) { if (!m_ComponentSkipSelfAlloc || children[i] != inElement) { children[i].OnFree(); } } } }
/// <summary> /// Frees all allocated prefabs currently in the given scene. /// </summary> public int FreeAllInScene(Scene inScene) { if (m_InnerPool != null) { using (PooledList <T> tempList = PooledList <T> .Create()) { foreach (var activeObj in m_ActiveObjects) { if (activeObj.gameObject.scene == inScene) { tempList.Add(activeObj); } } int finalCount = tempList.Count; m_InnerPool.Free(tempList); return(finalCount); } } return(0); }