Example #1
0
        public System.Collections.Generic.IEnumerator <float> InitializePool(ScenePoolController sceneController)
        {
            if (state != PoolState.NotInitialized)
            {
                Debugging.Logger.LogError($"{sceneController.name} is trying to initialize a pool ({name}) that is already initialized by: {(controller != null ? controller.name : "NULLCONTROLLER")}.", sceneController);

                /*if (controller == null) {
                 *  Debug.LogError("Initializing a pool that is already initialized, but the controller is null", sceneController);
                 * }*/
            }
            else
            {
                state = PoolState.Initializing;
                //isTakingInstance = false;
                controller = sceneController;
                Debugging.AssertionHelper.AssertNotNull(m_prefab, () => $"m_prefab of {name} is null", this);
                pooledObjects    = new System.Collections.Generic.Queue <Poolable>(m_initialPoolSize);
                inGameObjects    = new System.Collections.Generic.List <Poolable>(m_initialPoolSize);
                removeStartIndex = m_prefab.gameObject.name.Length + 1;
                nameBuilder      = new System.Text.StringBuilder(m_prefab.gameObject.name, removeStartIndex + DefaultNumberDecimalPlaces);
                nameBuilder.Append('_');
                currentSize   = 0;
                requestedSize = 0;
                for (int i = 0; i < m_initialPoolSize; i++)
                {
                    yield return(MEC.Timing.WaitUntilDone(MEC.Timing.RunCoroutine(CreateInitialInstances(m_worldPositionStays))));
                }
                state = PoolState.Initialized;
            }
        }
Example #2
0
 public void FinalizePool(ScenePoolController scenePoolController)
 {
     if (state == PoolState.Initialized && scenePoolController == controller)
     {
         state      = PoolState.NotInitialized;
         controller = null;
     }
     else
     {
         Debugging.Logger.LogError("You can only finalize a pool with the owner of the pool and when it had initialized.", scenePoolController.gameObject);
     }
 }