public void ReturnToPool(EntityBase entityBase) { PoolObjectData poolObject = new PoolObjectData(CellParent.transform, entityBase); SetDefoultComponents(entityBase); poolObject.SetNullParam(); PoolObjectStack.Push(poolObject); }
public void CreateNewElements(int count) { for (int i = 0; i < count; i++) { GameObject newObject = Object.Instantiate(Prefab); EntityBase entityBase = newObject.GetComponent <EntityBase>(); entityBase.GetEntityComponent <PoolComponent>().id = Prefab.GetInstanceID(); PoolObjectData poolObject = new PoolObjectData(CellParent.transform, entityBase); poolObject.SetNullParam(); PoolObjectStack.Push(poolObject); } }
public GameObject GetFromPool(Vector3 position, Quaternion rotation, Transform Parent) { if (PoolObjectStack.Count > 0) { PoolObjectData obj = PoolObjectStack.Pop(); obj.SetNewParam(position, rotation, Parent); obj.thisEntityBase.Awake(); return(obj.thisGameObject); } else { GameObject obj = Object.Instantiate(Prefab, position, rotation, Parent); obj.GetComponent <EntityBase>().GetEntityComponent <PoolComponent>().id = Prefab.GetInstanceID(); optimal_pool_count++; return(obj); } }