// On remplie la piscine => Populate Pool private void Populate(int nbrPooledElement) { for (int i = 0; i < nbrPooledElement; i++) { GameObject newInstantiate = GameObject.Instantiate(m_PrefabPool, m_Container.transform); // Verification du set de Poolable et de la clef pooling poolable = newInstantiate.GetComponent <pooling>(); if (!poolable) { poolable = newInstantiate.AddComponent <pooling>(); } poolable.keyPrefab = m_PrefabPool; m_AvailableElements.Add(newInstantiate); newInstantiate.SetActive(false); } }
// Start is called before the first frame update void Start() { if(instance == null) { instance = this; } poolObj = new List<GameObject>(); foreach (ObjectPooling item in itemsToPool) { for(int i = 0; i < item.poolAmount; i++) { GameObject obj = Instantiate(item.poolObject); obj.name = item.name; obj.transform.parent = this.transform; obj.SetActive(false); poolObj.Add(obj); } } }
public void PoolElement(GameObject toPool) { pooling poolable = toPool.GetComponent <pooling>(); if (poolable != null) { if (m_AllPools.ContainsKey(poolable.keyPrefab)) { m_AllPools[poolable.keyPrefab].SetAvailable(toPool); } else { Debug.LogWarning("Try To Pool No Prefab Key available => Destroy !"); Destroy(toPool); } } else { Debug.LogWarning("Try To Pool but no Poolable !"); Destroy(toPool); } }
private void Awake() { inst = this; }