public void ReturnTower(TowerType type, GameObject tower) { tower.SetActive(false); if (towerPool.TryGetValue(type.GetHashCode(), out Queue <GameObject> pool)) { pool.Enqueue(tower); } else { towerPool[type.GetHashCode()] = new Queue <GameObject>(); towerPool[type.GetHashCode()].Enqueue(tower); } }
private GameObject Create(TowerType type) { towers.TryGetValue(type.GetHashCode(), out Object res); if (res == null) { return(null); } return(Instantiate(res as GameObject, Container)); }
public GameObject GetTower(TowerType type) { if (towerPool.TryGetValue(type.GetHashCode(), out Queue <GameObject> pool)) { if (pool.Count > 0) { return(pool.Dequeue()); } else { return(Create(type)); } } else { towerPool[type.GetHashCode()] = new Queue <GameObject>(); return(Create(type)); } }