Beispiel #1
0
 // return a pooled object to the pool
 public void ReturnObject(PoolerObject _obj)
 {
     _obj.gameObject.SetActive(false);
     _obj.transform.parent        = Owner.transform;
     _obj.transform.localPosition = Vector3.zero;
     available.Enqueue(_obj);
 }
Beispiel #2
0
        // return an available object or spawn a new one
        public GameObject GetObject()
        {
            if (available == null)
            {
                available = new Queue <PoolerObject>();
            }
            if (available.Count == 0)
            {
                PoolerObject newObject = Instantiate(Prefab, Vector3.zero, Quaternion.identity);
                newObject.ParentPool = this;
                pooledCount++;

                if (pooledCount > MAX_POOLED)
                {
                    Debug.LogWarning("The " + IDs[0] + " Pool is at " + pooledCount + " objects! This is probably not normal D:");
                }

                return(newObject.gameObject);
            }

            available.Peek().gameObject.SetActive(true);
            return(available.Dequeue().gameObject);
        }
Beispiel #3
0
 public void AddPool(PoolableID _id, PoolerObject _prefab)
 {
     MyPools.Add(new Pool(this, _id, _prefab));
 }
Beispiel #4
0
 public Pool(ObjectPooler _owner, PoolableID _ID, PoolerObject _prefab)
 {
     Owner  = _owner;
     Prefab = _prefab;
     IDs.Add(_ID);
 }