Пример #1
0
        /// <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 <MMObjectPool>();
                _objectPool.PooledGameObjects = new List <GameObject>();
                return;
            }
            else
            {
                GameObject waitingPool = GameObject.Find(DetermineObjectPoolName());
                if (waitingPool != null)
                {
                    _waitingPool = waitingPool;
                    _objectPool  = _waitingPool.MMGetComponentNoAlloc <MMObjectPool>();
                }
                else
                {
                    _waitingPool = new GameObject(DetermineObjectPoolName());
                    _objectPool  = _waitingPool.AddComponent <MMObjectPool>();
                    _objectPool.PooledGameObjects = new List <GameObject>();
                }
            }
        }
Пример #2
0
 /// <summary>
 /// Creates the waiting pool or tries to reuse one if there's already one available
 /// </summary>
 protected virtual bool CreateWaitingPool()
 {
     if (!MutualizeWaitingPools)
     {
         // we create a container that will hold all the instances we create
         _waitingPool = new GameObject(DetermineObjectPoolName());
         SceneManager.MoveGameObjectToScene(_waitingPool, this.gameObject.scene);
         _objectPool = _waitingPool.AddComponent <MMObjectPool>();
         _objectPool.PooledGameObjects = new List <GameObject>();
         ApplyNesting();
         return(true);
     }
     else
     {
         MMObjectPool objectPool = ExistingPool(DetermineObjectPoolName());
         if (objectPool != null)
         {
             _objectPool  = objectPool;
             _waitingPool = objectPool.gameObject;
             return(false);
         }
         else
         {
             _waitingPool = new GameObject(DetermineObjectPoolName());
             SceneManager.MoveGameObjectToScene(_waitingPool, this.gameObject.scene);
             _objectPool = _waitingPool.AddComponent <MMObjectPool>();
             _objectPool.PooledGameObjects = new List <GameObject>();
             ApplyNesting();
             AddPool(_objectPool);
             return(true);
         }
     }
 }
Пример #3
0
 /// <summary>
 /// Adds a pooler to the static list if needed
 /// </summary>
 /// <param name="pool"></param>
 public static void AddPool(MMObjectPool pool)
 {
     if (_pools == null)
     {
         _pools = new List <MMObjectPool>(_initialPoolsListCapacity);
     }
     if (!_pools.Contains(pool))
     {
         _pools.Add(pool);
     }
 }
Пример #4
0
 /// <summary>
 /// Removes a pooler from the static list
 /// </summary>
 /// <param name="pool"></param>
 public static void RemovePool(MMObjectPool pool)
 {
     _pools?.Remove(pool);
 }