Exemple #1
0
 public void Dispose <T> (UTObject target) where T : UTObject
 {
     if (!Pool.ContainsKey(typeof(T)))
     {
         Pool.Add(typeof(T), new Stack <UTObject> ());
     }
     target.SetActive(false);
     Pool [typeof(T)].Push(target);
 }
Exemple #2
0
    public UTObject Get <T> (string name) where T : UTObject, new()
    {
        if (Pool.ContainsKey(typeof(T)) &&
            Pool [typeof(T)].Count > 0)
        {
            UTObject pooledObject = Pool [typeof(T)].Pop();
            pooledObject.SetActive(true);
            return(pooledObject);
        }

        // instantiate new T
        T newInstance = new T();

        newInstance.m_Name = name;
        return(newInstance);
    }