public static bool RecycleGO(GameObject prefab, GameObject instGO) { if (msPoolsDict == null) { msPoolsDict = new Dictionary <int, Pool_GameObj>(); } //找出对应的PoolGameObject if (prefab == null) { var poolObj = instGO.GetComponent(typeof(IPoolObj)) as IPoolObj; if (poolObj == null) { return(false); } prefab = poolObj.Prefab; if (prefab == null) { //Debug.LogWarning("noPrefab ="+instGO.name); return(false); } } Pool_GameObj poolGo = null; if (!msPoolsDict.TryGetValue(prefab.GetInstanceID(), out poolGo)) { poolGo = new Pool_GameObj(prefab); msPoolsDict.Add(prefab.GetInstanceID(), poolGo); } poolGo.RecycleGO(instGO); return(true); }
// Use this for initialization IEnumerator Start() { if (Prefab == null) { YxDebug.LogError("Prefab ²»ÄÜΪ ¿Õ!!"); yield break; } yield return(new WaitForSeconds(delay)); Pool_GameObj.RecycleGO(Prefab, gameObject); gameObject.SetActive(false); transform.position = new Vector3(1000F, 1000F, 0F); Destroy(this); }
public static GameObject GetObj(GameObject prefab) { if (msPoolsDict == null) { msPoolsDict = new Dictionary <int, Pool_GameObj>(); } //找出对应的PoolGameObject Pool_GameObj poolGo = null; if (!msPoolsDict.TryGetValue(prefab.GetInstanceID(), out poolGo)) { poolGo = new Pool_GameObj(prefab); msPoolsDict.Add(prefab.GetInstanceID(), poolGo); } return(poolGo.GetGO()); }
//设置池容量 public static void SetPoolVolume(GameObject prefab, int Volume) { if (msPoolsDict == null) { msPoolsDict = new Dictionary <int, Pool_GameObj>(); return; } //找出对应的PoolGameObject Pool_GameObj poolGo = null; if (!msPoolsDict.TryGetValue(prefab.GetInstanceID(), out poolGo)) { poolGo = new Pool_GameObj(prefab); msPoolsDict.Add(prefab.GetInstanceID(), poolGo); } poolGo.mVolume = Volume; }