Example #1
0
        /// <summary>
        /// Gets an object from the pool
        /// If the pool does not exist it will be created
        /// </summary>
        /// <param name="template">Object to get</param>
        /// <returns>A clone of the object requested</returns>
        public GameObject Get(GameObject template, bool setActive = true)
        {
            GObjectPool pool = GetOrCreatePool(template);
            GameObject  obj  = pool.Get(setActive);

            return(obj);
        }
Example #2
0
        /// <summary>
        /// Gets an object from the pool
        /// If the pool does not exist it will be created
        /// </summary>
        /// <param name="template">Object to get</param>
        /// <param name="position">Position of object in local space</param>
        /// <param name="rotation">Rotation of object in local space</param>
        /// <param name="parent">Object to set as the parent</param>
        /// <returns>A clone of the object requested</returns>
        public GameObject Get(GameObject template, Vector3 position, Quaternion rotation, Transform parent, bool setActive = true)
        {
            GObjectPool pool = GetOrCreatePool(template);
            GameObject  obj  = pool.Get(position, rotation, parent, setActive);

            return(obj);
        }
Example #3
0
        private GObjectPool GetOrCreatePool(GameObject template)
        {
            GObjectPool pool;

            if (_pools.TryGetValue(template.name, out pool))
            {
                return(pool);
            }

            pool = new GObjectPool(this, template);
            _pools[pool.Type] = pool;
            return(pool);
        }
Example #4
0
        /// <summary>
        /// Fills a pool with the specified number of objects
        /// </summary>
        /// <param name="template">Object to pool</param>
        /// <param name="numToAllocate">Number of objects to allocate</param>
        public void PreallocateObjects(GameObject template, int numToAllocate)
        {
            GObjectPool pool = GetOrCreatePool(template);

            pool.Preallocate(numToAllocate);
        }