Exemple #1
0
        Pool CreateNewPoolPart(PoolSettingsSO poolSet)
        {
            Transform newHolder = new GameObject("Holder_" + poolSet.key).transform;

            newHolder.SetParent(transform);
            Pool newPoolPart = new Pool(this, poolSet, newHolder);

            dictionary.Add(poolSet.key, newPoolPart);
            if (poolSet.GetPool() == null)
            {
                poolSet.SetPool(newPoolPart);
            }
            return(newPoolPart);
        }
        /// <summary>
        /// Use it to return object to pool instead destroying
        /// </summary>
        public virtual void ReturnToPool()
        {
            IsInPool = true;
            gameObject.SetActive(false);
            Pool poolInst = poolSet.GetPool();

            if (poolInst != null)
            {
                if (transform.parent != poolInst.holder)
                {
                    transform.SetParent(poolInst.holder, false);
                }
            }
            poolSet.ReturnToPool(this);
        }