/// <summary> /// Despawns the specified objectToDespawn. /// </summary> /// <param name="objectToDespawn">Object to despawn.</param> public void Despawn(PoolableObject objectToDespawn) { if (objectToDespawn == null) { Debug.LogWarning("Despawning empty obj..."); return; } if (!IsPoolManagerInitialized) { Debug.LogWarning("The Pool manager has not been initialized"); return; } if (objectToDespawn != null) { PoolableObjectPool sp = GetPool(objectToDespawn.OriginObjectPool); if (sp != null) { sp.Despawn(objectToDespawn); } else { Debug.LogWarningFormat(this, "A pool with the name [{0}] doesn't exist!. Can't despawn from there.", objectToDespawn.OriginObjectPool); } } }
/// <summary> /// Creates the pool with the parameters provided. /// </summary> /// <returns><c>true</c>, if pool was created, <c>false</c> otherwise.</returns> /// <param name="poolId">Pool identifier.</param> /// <param name="spawnable">Spawnable.</param> /// <param name="preLoadedInstances">Pre loaded instances.</param> /// <param name="limitInstances">If set to <c>true</c> limit instances.</param> /// <param name="limitCounter">Limit counter.</param> public override bool CreatePool(string poolId, PoolableObject spawnable, int preLoadedInstances = 0, bool limitInstances = false, int limitCounter = 0) { PoolableObjectPool op = GetPool(poolId); if (op == null) { if (_isLogged) { Debug.Log("As this pool doesnt exist we will create it.", this); } op = new PoolableObjectPool(poolId, spawnable, preLoadedInstances, limitInstances, limitCounter); op.showDebugInfo = _isLogged; op.InitPool(); return(true); } else { if (_isLogged) { Debug.LogWarningFormat(this, "A pool with the name [{0}] already exist!", poolId); } } return(false); }
/// <summary> /// Spawns an instance of the specified poolId with the provided position, rotation and newParent. /// </summary> /// <param name="poolId">Pool identifier.</param> /// <param name="position">localPosition.</param> /// <param name="rotation">localRotation.</param> /// <param name="newParent">New parent.</param> public override PoolableObject Spawn(string poolId, Vector3 position = default(Vector3), Quaternion rotation = default(Quaternion), Transform newParent = null) { if (!poolManagerInitialized) { if (_isLogged) { Debug.LogWarning("The Pool Manager Is not ready yet!", this); } return(null); } PoolableObjectPool sp = GetPool(poolId); if (sp != null) { return(sp.Spawn(position, rotation, newParent)); } else { if (_isLogged) { Debug.LogWarningFormat(this, "A pool with the name [{0}] doesn't exist!. Can't spawn from there.", poolId); } return(null); } }
/// <summary> /// Despawns all objects from pool. /// </summary> /// <param name="poolId">Pool identifier.</param> public void DespawnAllObjectsFromPool(string poolId) { PoolableObjectPool sp = GetPool(poolId); if (sp != null) { sp.DespawnAll(); } }
public override void AddPool(PoolableObjectPool objectPool) { if (wrappedService != null && objectPool != null) { Debug.LogFormat("Adding Pool: {0} with Spwn:{1}, preload:{2} Limit:{3} to {4} instances", objectPool.poolId, objectPool.poolableObjectPrefab.name, objectPool.numberOfPreloadedObjects, objectPool.limitInstances, objectPool.spawnLimit); wrappedService.AddPool(objectPool); } }
/// <summary> /// Destroys the pool with the id provided. /// </summary> /// <param name="poolId">Pool identifier.</param> public override void DestroyPool(string poolId) { PoolableObjectPool op = GetPool(poolId); if (op == null) { op.DestroyPool(); poolsList.Remove(op); poolsMap.Remove(poolId); } else { Debug.LogWarningFormat(this, "A pool with the name [{0}] doesn't exist!", poolId); } }
/// <summary> /// Adds the pool provided to the manager. /// </summary> /// <param name="objectPool">Object pool.</param> public override void AddPool(PoolableObjectPool objectPool) { if (objectPool != null) { if (!poolsMap.ContainsKey(objectPool.poolId)) { poolsMap.Add(objectPool.poolId, objectPool); if (poolManagerInitialized) { poolsList.Add(objectPool); objectPool.InitPool(); } } else { Debug.LogWarningFormat(this, "A pool with the name [{0}] already exist!", objectPool.poolId); } } }
/// <summary> /// Adds the pool provided to the manager. /// </summary> /// <param name="objectPool">Object pool.</param> public abstract void AddPool(PoolableObjectPool objectPool);