public void Initialize(PoolingList cachedList = null) { if (initialized) { return; } tr = transform; PoolingList cachePL = (cachedList != null) ? cachedList : (PoolingList)Resources.Load("Static Prefabs/PoolingList", typeof(PoolingList)); poolPrefabs = cachePL.poolPrefabs; poolParticlesPrefabs = cachePL.poolParticles; pooledObjects = new List <GameObject> [poolPrefabs.Length]; pooledParticles = new ParticleManager[poolParticlesPrefabs.Length]; for (int i = 0; i < poolPrefabs.Length; i++) { pooledObjects[i] = new List <GameObject>(); GameObject initObj = (GameObject)Instantiate(poolPrefabs[i]); initObj.name = poolPrefabs[i].name; PoolItem objPI = initObj.GetComponent <PoolItem>(); objPI.prefabIndex = i; objPI.AddToPool(); } for (int j = 0; j < poolParticlesPrefabs.Length; j++) { ParticleManager pm = (ParticleManager)Instantiate(poolParticlesPrefabs[j]); pm.transform.parent = tr; pooledParticles[j] = pm; } initialized = true; }
protected virtual void AddToPool() { PoolItem obj = Instantiate(_prefab, transform); obj.AddToPool(OnRemoveCallback); }