private void Initialize(char key, GameObject obj) { //Initialize object and queue GameObjectQueue newQueue = new GameObjectQueue(obj); gameObjectMap.Add(key, newQueue); //Set initial capacity. Expand(key); }
//Expand capacity for the pool with the given key. private void Expand(char key) { GameObjectQueue pair = gameObjectMap[key]; GameObject original = pair._object; Queue <GameObject> queue = pair.queue; int i = multiplier; while (0 < i--) { GameObject newObject = GameObject.Instantiate(original, parent); newObject.SetActive(false); queue.Enqueue(newObject); } }
public GameObject GetObject(char key) { if (key == GameBoardCubeDictionary.OPEN_SPACE) { return(null); } GameObjectQueue pair = gameObjectMap[key]; if (pair == null) { return(null); } //If queue is empty expand pool if (pair.queue.Count == 0) { Expand(key); } return(pair.queue.Dequeue()); }