Ejemplo n.º 1
0
        private IEnumerator KillIdleControllersEnumerator()
        {
            while (AutoKillIdleControllers)
            {
                yield return(m_idleCheckIntervalWaitForSecondsRealtime); //check idle wait interval

                RemoveNullControllersFromThePool();                      //remove any null controllers (sanity check)
                int   minimumNumberOfControllers = MinimumNumberOfControllers > 0 ? MinimumNumberOfControllers : 0;
                float controllerIdleKillDuration = ControllerIdleKillDuration > 0 ? ControllerIdleKillDuration : 0;
                if (Pool.Count <= minimumNumberOfControllers)
                {
                    continue;                                                      //make sure the minimum number of controllers are in the pool before killing any more of them
                }
                for (int i = Pool.Count - 1; i >= minimumNumberOfControllers; i--) //go through the pool
                {
                    m_tempController = Pool[i];
                    if (m_tempController.gameObject.activeSelf)
                    {
                        continue;                                                             //controller is active do not kill it
                    }
                    if (m_tempController.IdleDuration < controllerIdleKillDuration)
                    {
                        continue;                                                             //controller is not killable as it has not been idle for long enough
                    }
                    Pool.Remove(m_tempController);                                            //remove controller from the pool
                    m_tempController.Kill();                                                  //kill the controller
                }
            }

            m_idleCheckCoroutine = null;
        }
Ejemplo n.º 2
0
        /// <summary> Stops all SoundyControllers from playing, destroys the GameObjects they are attached to and clears the Pool </summary>
        /// <param name="keepMinimumNumberOfControllers"> Should there be a minimum set number of controllers in the pool left after clearing? </param>
        public static void ClearPool(bool keepMinimumNumberOfControllers = false)
        {
            if (keepMinimumNumberOfControllers)
            {
                RemoveNullControllersFromThePool();           //remove any null controllers (sanity check)
                if (Pool.Count <= MinimumNumberOfControllers) //make sure the minimum number of controllers are in the pool before killing them
                {
                    if (Instance.DebugComponent)
                    {
                        DDebug.Log("Clear Pool - " + Pool.Count + " Controllers Available", Instance);
                    }
                    return;
                }

                int killedControllersCount = 0;
                for (int i = Pool.Count - 1; i >= MinimumNumberOfControllers; i--) //go through the pool
                {
                    SoundyController controller = Pool[i];
                    Pool.Remove(controller); //remove controller from the pool
                    controller.Kill();       //kill the controller
                    killedControllersCount++;
                }

                if (Instance.DebugComponent)
                {
                    DDebug.Log("Clear Pool - Killed " + killedControllersCount + " Controllers - " + Pool.Count + "' Controllers Available", Instance);
                }

                return;
            }

            SoundyController.KillAll();
            Pool.Clear();
            if (Instance.DebugComponent)
            {
                DDebug.Log("Clear Pool - Killed All Controllers - " + Pool.Count + " Controllers Available", Instance);
            }
        }