Пример #1
0
        public virtual T GetPooledInstance <T>() where T : Component
        {
            if (!IsResourceLoaded)
            {
                throw new NullReferenceException("Please load the resources on this PoolTool" +
                                                 " before attempting to get an instance.");
            }

            if (Pool.PoolCount == 0)
            {
                Pool.AddToPool();
            }
            var pooledInstance = Pool.GetObject();

            pooledInstance.transform.SetParent(null);
            pooledInstance.gameObject.SetActive(true);

            try { return((T)pooledInstance); }

            catch (InvalidCastException)
            {
                Debug.LogErrorFormat(this, $"Invalid type {typeof(T).Name} requested.");
                return(null);
            }
        }
Пример #2
0
 public static void AddToPool(IDamageable damageable)
 {
     pool.AddToPool(damageable);
 }