public T GetPooledObject <T>(PoolableID _id) where T : Component { Pool _pool = GetPoolForID(_id); if (_pool == null) { return(null); } return(_pool.GetObject().GetComponent <T>()); }
// 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); }
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); }
public void AddPool(PoolableID _id, PoolerObject _prefab) { MyPools.Add(new Pool(this, _id, _prefab)); }
public Pool(ObjectPooler _owner, PoolableID _ID, PoolerObject _prefab) { Owner = _owner; Prefab = _prefab; IDs.Add(_ID); }
public bool HasPoolForID(PoolableID _id) { return(GetPoolForID(_id) != null); }