Example #1
0
        public void CreatePool(GameObject prefab, int poolSize)
        {
            GameObject newObjectPool = new GameObject(prefab.name + " Pool");

            newObjectPool.transform.parent = transform;

            var poolKey = prefab.GetInstanceID();

            if (_poolDictionary.ContainsKey(poolKey))
            {
                return;
            }

            _poolDictionary.Add(poolKey, new Queue <ObjectInPool>());

            for (int i = 0; i < poolSize; i++)
            {
                ObjectInPool newObject = new ObjectInPool(Instantiate(prefab, newObjectPool.transform));
                _poolDictionary[poolKey].Enqueue(newObject);
            }
        }