//If a object spawned without the use of the pooler add it to a pool public static void AddMissingObject(PoolableObject prefab) { //Check if it already has pool to enter if (_pools.ContainsKey(prefab)) { prefab.Initialize(_pools[prefab]); _pools[prefab].Return(prefab); } else //If it doesn't have a pool create a new one { InitializePool(prefab); prefab.Initialize(_pools[prefab]); } }
private void Stock(int count) { for (int i = 0; i < count; i++) { PoolableObject newObject = Object.Instantiate(_original); newObject.Initialize(this); Return(newObject); } }
private PoolableObject CreateObject() { PoolableObject po = GameObject.Instantiate <PoolableObject> (poolObject); po.name += " " + idx; po.Initialize(this); po.transform.SetParent(gRoot.transform); idx++; return(po); }
private PoolableObject AddPooledObject() { PoolableObject instance = Instantiate <PoolableObject>(m_Definition.ObjectType, Vector3.zero, Quaternion.identity, transform); //Parent it to ourselves if (instance == null) { //Destroy(instance); throw new MissingComponentException("Component PoolableObject was not found on the prefab " + m_Definition.ObjectType.ToString()); } else { instance.Initialize(); instance.Deactivate(); m_PooledObjects.Add(instance); return(instance); } }