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); } }
public static void AddToPool(IDamageable damageable) { pool.AddToPool(damageable); }