/// <summary> /// Creates a new TileMap /// </summary> /// <param name="mapType"></param> /// <returns></returns> public bool CreateNewMap(MapDataBase.MAPS mapType) { // Create new Tilemap, parented under and positioned at m_GridGO GameObject mapObject = MapDataBase.GetInstance().GetMapGO(mapType); mapObject = Instantiate(mapObject, m_GridGO.transform.position, Quaternion.identity, m_GridGO.transform); m_currentMap = mapObject.GetComponent <BaseMapClass>(); // Resize the layout Array int totalSize = m_currentMap.GetTileMapSize().x *m_currentMap.GetTileMapSize().y; m_GridTakenArray.Clear(); m_GridTakenArray.Capacity = totalSize; // Set the capactiy to prevent calling Array.Resize() multiple times for (int i = 0; i < totalSize; ++i) { m_GridTakenArray.Add(false); } // Center the Camera to the map Vector3 centerMapWorldPos = m_GridGO.CellToWorld((Vector3Int)m_currentMap.GetTileMapSize() / 2); centerMapWorldPos += m_GridGO.cellSize * 0.5f; centerMapWorldPos.z = -10.0f; Camera.main.transform.position = centerMapWorldPos; // Fire the Map Generated Event OnMapGenerated(); //Get starting route from one of the routes build at spawn List <MapStartingBuildings> startingBuildingsList = m_currentMap.GetStartingBuildings(); Vector2Int mainRoadPos = Vector2Int.zero; foreach (MapStartingBuildings startingbuild in startingBuildingsList) { if (startingbuild.buildingID == BuildingDataBase.BUILDINGS.B_ROAD) { mainRoadPos = startingbuild.spawnGridPositions[0]; break; } } m_RoadManager.Init(m_currentMap.GetTileMapSize(), mainRoadPos); return(true); }
public BaseMapClass GetMapCom(MapDataBase.MAPS mapType) { return(dictOfMaps[mapType]); }
public GameObject GetMapGO(MapDataBase.MAPS mapType) { return(dictOfMaps[mapType].gameObject); }