private static ObjectPool GetObjectPool(RecycleGamObject reference) { ObjectPool pool = null; if (pools.ContainsKey(reference)) { pool = pools[reference]; } else { var poolContainer = new GameObject(reference.gameObject.name + "ObjectPool"); pool = poolContainer.AddComponent <ObjectPool>(); pool.prefab = reference; pools.Add(reference, pool); } return(pool); }
public RecycleGamObject NextObject(Vector3 pos) { RecycleGamObject instance = null; foreach (var go in poolInstances) { if (go.gameObject.activeSelf != true) { instance = go; instance.transform.position = pos; } } if (instance == null) { instance = CreateInstance(pos); } instance.Restart(); return(instance); }