public static bool RecycleGO(GameObject prefab, GameObject instGO) { if (msPoolsDict == null) { msPoolsDict = new Dictionary <int, Pool_GameObj>(); } //????????PoolGameObject if (prefab == null) { IPoolObj poolObj = instGO.GetComponent(typeof(IPoolObj)) as IPoolObj; 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); }
public GameObject SpawnFromPool(string etiqueta, Vector3 position, Quaternion rotation) { if (!poolDictionary.ContainsKey(etiqueta)) { Debug.LogError("Esta estiqueta " + etiqueta + " no se encuentra en el diccionario"); } GameObject objectToSpawn = poolDictionary[etiqueta].Dequeue(); objectToSpawn.SetActive(true); objectToSpawn.transform.position = position; objectToSpawn.transform.rotation = rotation; IPoolObj pooledObject = objectToSpawn.GetComponent <IPoolObj>(); if (pooledObject != null) { pooledObject.OnObjectSpawn(); } poolDictionary[etiqueta].Enqueue(objectToSpawn); return(objectToSpawn); }