public void InitializeMap() { Map = new MapEditorGridElement[mapHeight, mapWidth]; for (int row = 0; row < mapHeight; ++row) { for (int column = 0; column < mapWidth; ++column) { SaveTileToMap(new IntVector2(column, row), TileType.Grass); } } }
public void LoadMap(string filePath) { List <string> lines = new List <string>(new StreamReader(filePath).ReadToEnd().Split('\n')); foreach (string line in lines) { string[] words = line.Split(' '); switch (words[0]) { case mapSizeFileKey: mapWidth = int.Parse(words[1]); mapHeight = int.Parse(words[2]); Map = new MapEditorGridElement[mapHeight, mapWidth]; break; case player1PositionKey: player1MarkerOnMapInstance = Instantiate(player1MarkerPrefab, MapGridded.MapToWorldPosition(new IntVector2(int.Parse(words[1]), int.Parse(words[2]))), Quaternion.identity); player1Position = MapGridded.WorldToMapPosition(player1MarkerOnMapInstance.transform.position); break; case player2PositionKey: player2MarkerOnMapInstance = Instantiate(player2MarkerPrefab, MapGridded.MapToWorldPosition(new IntVector2(int.Parse(words[1]), int.Parse(words[2]))), Quaternion.identity); player2Position = MapGridded.WorldToMapPosition(player2MarkerOnMapInstance.transform.position); break; case tileKey: SaveTileToMap(new IntVector2(int.Parse(words[1]), int.Parse(words[2])), (TileType)System.Enum.Parse(typeof(TileType), words[3])); break; case goldMineKey: SaveMineToMap(new IntVector2(int.Parse(words[1]), int.Parse(words[2]))); break; case lumberKey: SaveLumberToMap(new IntVector2(int.Parse(words[1]), int.Parse(words[2]))); break; } } }