Esempio n. 1
0
 /// <summary>
 /// 2017-8-2
 /// Destroys any GameObjects that is not currently
 /// in use, and has not been used for a long time (stale time).
 /// </summary>
 public void Expire(bool immediate = false)
 {
     if (this.staleDuration == UNLIMITED)
     {
         return;
     }
     PCoroutine.CreateCoroutineRunner(ExpireEnumerator(immediate), prefab.name);
 }
Esempio n. 2
0
            /// <summary>
            /// 2017-8-4
            /// Ensures the pool has not exceeded the maximum pool size.
            /// This only needs to be called if the pool's maximum size has been reduced,
            /// and only if the pool was used extensively (or prewarmed) prior to the reduction.
            /// The culling occurs as objects are Returned to the pool -- so no
            /// objects will be destroyed while still in use.
            /// </summary>
            public void Cull(bool immediate = false)
            {
                //  if the pool size is set to 'infinite' then do nothing
                if (this.maxObjects == UNLIMITED)
                {
                    return;
                }

                PCoroutine.CreateCoroutineRunner(CullEnumerator(immediate));
            }
Esempio n. 3
0
            /// <summary>
            /// 2017-8-4
            /// Destroys any objects that is not currently
            /// in use, and has not been used for a long time (stale time).
            /// </summary>
            public void Expire(bool immediate = false)
            {
                if (this.staleDuration == UNLIMITED)
                {
                    return;
                }

                string name = typeof(T).ToString();

                PCoroutine.CreateCoroutineRunner(ExpireEnumerator(immediate), name);
            }
Esempio n. 4
0
            /// <summary>
            /// 2017-8-7
            /// Pre-instantiates a number of items for the pool.
            /// The generation is distributed over [duration] seconds.
            /// Prewarm will never create more than one item per frame.
            /// </summary>
            public void Prewarm(int count, float duration)
            {
                if (count <= 0)
                {
                    return;
                }

                float delay = Mathf.Max(1 / 60f, duration / count);

                PCoroutine.CreateCoroutineRunner(PrewarmEnumerator(count, delay), prefab.name);
            }
Esempio n. 5
0
        /// <summary>
        /// 2017-8-10
        /// Stand alone, fire and forget coroutine runner.
        /// Creates a temporary GameObject and attaches a PCoroutine
        /// MonoBehaviour. This is used to run coroutines for delayed
        /// actions. The GameObject deletes itself once complete.
        /// </summary>
        public static void CreateCoroutineRunner(IEnumerator ienumerator, string name = "")
        {
            //  Create a game object with no renderer or geometry
            GameObject g = new GameObject("_CoroutineRunner_" + name + "_" + Time.time);

            //  Attach a PCoroutine MonoBehavior to the GameObject
            PCoroutine pcoroutine = g.AddComponent <PCoroutine>();

            //  Start the coroutines
            pcoroutine.StartCoroutine(pcoroutine.DestroyWhenFinished(ienumerator));
        }
Esempio n. 6
0
            /// <summary>
            /// 2017-8-4
            /// Ensures the pool has not exceeded the maximum pool size.
            /// This only needs to be called if the pool's maximum size has been reduced,
            /// and only if the pool was used extensively (or prewarmed) prior to the reduction.
            /// The culling occurs as objects are Returned to the pool -- so no
            /// objects will be destroyed while still in use.
            /// </summary>
            public void Cull(bool immediate = false)
            {
                //  if the pool size is set to 'infinite' then do nothing
                if (this.maxObjects == UNLIMITED)
                {
                    return;
                }

                string name = typeof(T).ToString();

                PCoroutine.CreateCoroutineRunner(CullEnumerator(immediate), name);
            }
Esempio n. 7
0
            /// <summary>
            /// 2017-8-4
            /// Pre-instantiates a number of items for the pool.
            /// The generation is distributed over [duration] seconds.
            /// Prewarm will never create more than one item per frame.
            /// </summary>
            public void Prewarm(int count, float duration)
            {
                if (count <= 0)
                {
                    return;
                }

                float  delay = Mathf.Min(1 / 60f, duration / count);
                string name  = typeof(T).ToString();

                PCoroutine.CreateCoroutineRunner(PrewarmEnumerator(count, delay), name);
            }