private IEnumerator DoInitSet(PoolingSet poolingSet) { if (!poolingSet.IsValid()) { yield break; } _amount = poolingSet.AmountToPool; poolingSet.Objects = new List <GameObject>(_amount); _hasFinishedCreatingSet = false; for (int j = 0; j < _amount; j++) { AddObjectToPoolingSet(poolingSet, j.ToString()); if (_incrementalInitialization) { yield return(null); } } if (!_poolingSets.Contains(poolingSet)) { _poolingSets.Add(poolingSet); } _hasFinishedCreatingSet = true; }
private GameObject GetPooledObject(PoolingSet p_set) { List <GameObject> p_collection = p_set.Objects; for (int i = 0; i < p_collection.Count; i++) { if (!p_collection[i].activeInHierarchy) { //Debug.Log("Got: " + p_collection[i].name); if (p_set.ParentTransform != null) { p_collection[i].transform.SetParent(p_set.ParentTransform); } p_collection[i].GetComponent <IPoolingItem>()?.Reset(); return(p_collection[i]); } } if (!_canIncreaseInSize) { return(null); } Debug.LogWarning("No object would be available, but we made more of: " + p_set.Prefab.name); return(AddObjectToPoolingSet(p_set, p_collection.Count.ToString())); }
public GameObject GetPooledObject(GameObject p_prefab) { PoolingSet set = GetSet(p_prefab); if (set == null) { Debug.LogWarning("No set contains the needed prefab: " + p_prefab.name); return(null); } return(GetPooledObject(set)); }
public void AddPoolingSet(PoolingSet poolingSet) { if (!poolingSet.IsValid()) { Debug.LogWarning("Set not valid!"); return; } if (!_hasInit || !_hasFinishedCreatingSet) { Debug.LogWarning("Another operation is still taking place."); return; } StartCoroutine(DoInitSet(poolingSet)); }
private GameObject AddObjectToPoolingSet(PoolingSet p_poolingSet, string p_suffix) { _go = Instantiate(p_poolingSet.Prefab); _go.name += p_poolingSet.Prefab.name + " " + p_suffix; if (p_poolingSet.ParentTransform != null) { _go.transform.SetParent(p_poolingSet.ParentTransform); } _go.SetActive(false); p_poolingSet.Objects.Add(_go); return(_go); }
public void ClearSet(PoolingSet poolingSet) { if (poolingSet == null) { return; } var objs = poolingSet.Objects; if (objs == null || objs.Count == 0) { return; } for (int i = poolingSet.Objects.Count; i >= 0; i--) { Destroy(objs[i]); } _poolingSets.Remove(poolingSet); }