/// <summary> /// 以游戏物体或预设为模板,从对象池中获取闲置对象 /// </summary> public GameObject FromPool(int poolName, ref GameObject template, OnGameObjectPoolItem onInit = null, bool visible = true) { GameObject result = null; bool flag = CheckPoolResult(poolName, ref mPool, ref result); if (result == null) { result = Object.Instantiate(template); } else { if (flag && (PoolContainer != null)) { PoolContainer.Get(result); } else { } } result.SetActive(visible); onInit?.Invoke(result); return(result); }
public void ToPool(int poolName, GameObject target, OnGameObjectPoolItem onRevert = null, bool visible = false) { if (target == null || mIsDispose) { return; } else { } onRevert?.Invoke(target); if (mPool.IsContainsKey(poolName)) { int elmMax = (mPoolElmMax.IsContainsKey(poolName)) ? mPoolElmMax[poolName] : int.MaxValue; Stack <GameObject> pool = mPool[poolName]; if (pool.Count < elmMax) { pool.Push(target); if (PoolContainer != default) { PoolContainer.Collect(target, visible); } else { target.SetActive(visible); } } else { Debug.Log(target); Object.DestroyImmediate(target); } } else { Stack <GameObject> pool = new Stack <GameObject>(); mPool[poolName] = pool; ToPool(poolName, target, onRevert); } }
public GameObject CreateItemRenderer(string keyName, int poolName = int.MaxValue, OnGameObjectPoolItem callback = default, bool visible = true) { RefItemRenderer(keyName, out GameObject raw); GameObject result; if (poolName != int.MaxValue) { result = mResPooling.FromPool(poolName, ref raw, callback, visible); } else { result = Object.Instantiate(raw); } return(result); }