internal void ReturnObjectBackToPool(GameObject returnedObject) { if (this._activePool != null && returnedObject != null) { PoolObject objectToReturnBack = null; for (int i = 0; i < this._activePool.Count; i++) { if (this._activePool[i]._object == returnedObject) { objectToReturnBack = this._activePool[i]; break; } } if (objectToReturnBack != null) { this._idlePool.Add(objectToReturnBack); this._activePool.Remove(objectToReturnBack); objectToReturnBack.DeActivatePoolObject(this.defaultParent); if (this.defaultParent != null && objectToReturnBack._object != null) { objectToReturnBack._object.transform.SetParent(this.defaultParent.transform); } } else { Debug.Log("failed to get objectToReturn!"); } } }
internal void ReturnAllObjectsToPool() { for (int i = 0; i < this._activePool.Count; i++) { PoolObject poolObject = this._activePool[i]; if (poolObject != null && poolObject._object != null) { poolObject.DeActivatePoolObject(this.defaultParent); this._idlePool.Add(poolObject); } } this._activePool = new List <PoolObject>(); for (int i = 0; i < this._waitingForActivationPool.Count; i++) { PoolObject poolObject = this._waitingForActivationPool[i]; if (poolObject != null && poolObject._object != null) { poolObject.DeActivatePoolObject(this.defaultParent); this._idlePool.Add(poolObject); } } this._waitingForActivationPool = new List <PoolObject>(); }
private PoolObject InstantiateNewPooledObject() { PoolObject objectToTake = new PoolObject(); GameObject gameObjectToCreate = Instantiate(this.poolPrefabToUse.prefab); objectToTake._object = gameObjectToCreate; objectToTake.type = this.typeName; PooledObject pooledObjectScript = gameObjectToCreate.GetComponent <PooledObject>(); if (pooledObjectScript == null) { pooledObjectScript = gameObjectToCreate.AddComponent <PooledObject>(); } objectToTake.objectScript = pooledObjectScript; if (!string.IsNullOrEmpty(this.typeName)) { pooledObjectScript.poolTypeString = this.typeName; } else { pooledObjectScript.poolBasePrefab = this.poolPrefabToUse.prefab; } if (this.defaultParent == null) { this.defaultParent = new GameObject(); if (!string.IsNullOrEmpty(this.typeName)) { this.defaultParent.name = this.typeName + "_Parent"; } else if (this.poolPrefabToUse != null && this.poolPrefabToUse.prefab != null) { this.defaultParent.name = this.poolPrefabToUse.prefab.name + "_Parent"; } } objectToTake.DeActivatePoolObject(this.defaultParent); this._idlePool.Add(objectToTake); return(objectToTake); }