private GameObject CreateNewItemAndAddToPool(PooledPrefabDefinition definition, bool startActive) { //Not sure where in space they should go, will keep it at 0,0,0 for now. GameObject instance = Instantiate(definition.prefabToBePooled, transform); instance.SetActive(startActive); return(AddToPool(instance)); }
/// <summary> /// Labelled as "Button_name" So the team is aware this function is called from the editor, since no usage can be found otherwise /// with a "Find all references". Called by the object named "Spawn button" in the editor /// </summary> public void Button_SpawnAmount() { if (_definitionsToPool.Count <= 0) { Debug.LogError("Error, nothing to spawn", this); return; } for (int i = 0; i < GetInputAmount(); i++) { //Spawn a random one PooledPrefabDefinition def = _definitionsToPool[UnityEngine.Random.Range(0, _definitionsToPool.Count)]; SpawnItem(def); } }
public void SpawnItem(PooledPrefabDefinition definition) { //First try find an existing item for (int i = 0; i < _currentPool.Count; i++) { if (!_currentPool[i].activeSelf) { _currentPool[i].SetActive(true); _objectsActive++; onObjectSpawned?.Invoke(_objectsActive); return; } } //Expand CreateNewItemAndAddToPool(definition, startActive: true); }