示例#1
0
    public T GetPooledObject <T>(PoolableID _id) where T : Component
    {
        Pool _pool = GetPoolForID(_id);

        if (_pool == null)
        {
            return(null);
        }
        return(_pool.GetObject().GetComponent <T>());
    }
示例#2
0
 // should only be used in editor since it's not optimized, and optimizing it could be a bit annoying.
 public bool HasPoolForID_EDITOR(PoolableID _id)
 {
     for (int i = 0; i < MyPools.Count; i++)
     {
         for (int j = 0; j < MyPools[i].IDs.Count; j++)
         {
             if (MyPools[i].IDs[j] == _id)
             {
                 return(true);
             }
         }
     }
     return(false);
 }
示例#3
0
    public Pool GetPoolForID(PoolableID _id)
    {
        Pool _pool      = null;
        int  _idIndex   = 0;
        int  _poolIndex = 0;

        for (int i = 0; i < allPoolIDs.Length; i++)
        {
            PoolableID _poolID = allPoolIDs[i];
            if (_poolID == _id)
            {
                _pool = MyPools[_poolIndex];
            }

            _idIndex++;
            if (_idIndex == idsPerPool[_poolIndex])
            {
                _idIndex = 0;
                _poolIndex++;
            }
        }

        return(_pool);
    }
示例#4
0
 public void AddPool(PoolableID _id, PoolerObject _prefab)
 {
     MyPools.Add(new Pool(this, _id, _prefab));
 }
示例#5
0
 public Pool(ObjectPooler _owner, PoolableID _ID, PoolerObject _prefab)
 {
     Owner  = _owner;
     Prefab = _prefab;
     IDs.Add(_ID);
 }
示例#6
0
 public bool HasPoolForID(PoolableID _id)
 {
     return(GetPoolForID(_id) != null);
 }