/// <summary> /// Creates the waiting pool or tries to reuse one if there's already one available /// </summary> protected virtual void CreateWaitingPool() { if (!NestWaitingPool) { return; } if (!MutualizeWaitingPools) { // we create a container that will hold all the instances we create _waitingPool = new GameObject(DetermineObjectPoolName()); _objectPool = _waitingPool.AddComponent <MMMiniObjectPool>(); _objectPool.PooledGameObjects = new List <GameObject>(); return; } else { GameObject waitingPool = GameObject.Find(DetermineObjectPoolName()); if (waitingPool != null) { _waitingPool = waitingPool; _objectPool = _waitingPool.MMFGetComponentNoAlloc <MMMiniObjectPool>(); } else { _waitingPool = new GameObject(DetermineObjectPoolName()); _objectPool = _waitingPool.AddComponent <MMMiniObjectPool>(); _objectPool.PooledGameObjects = new List <GameObject>(); } } }
/// <summary> /// Creates the waiting pool or tries to reuse one if there's already one available /// </summary> protected virtual void CreateWaitingPool() { if (!MutualizeWaitingPools) { // we create a container that will hold all the instances we create _objectPool = this.gameObject.AddComponent <MMMiniObjectPool>(); _objectPool.PooledGameObjects = new List <GameObject>(); return; } else { MMMiniObjectPool waitingPool = ExistingPool(DetermineObjectPoolName(GameObjectToPool)); if (waitingPool != null) { _waitingPool = waitingPool.gameObject; _objectPool = waitingPool; } else { GameObject newPool = new GameObject(); newPool.name = DetermineObjectPoolName(GameObjectToPool); _objectPool = newPool.AddComponent <MMMiniObjectPool>(); _objectPool.PooledGameObjects = new List <GameObject>(); AddPool(_objectPool); } } }
/// <summary> /// Adds a pooler to the static list if needed /// </summary> /// <param name="pool"></param> public static void AddPool(MMMiniObjectPool pool) { if (_pools == null) { _pools = new List <MMMiniObjectPool>(_initialPoolsListCapacity); } if (!_pools.Contains(pool)) { _pools.Add(pool); } }
/// <summary> /// Removes a pooler from the static list /// </summary> /// <param name="pool"></param> public static void RemovePool(MMMiniObjectPool pool) { _pools?.Remove(pool); }