public void GenerateMap() { HexTile hexTilePrefab = mapData.hexTilePrefab; map = new HexTile[width, height]; for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { HexTile h = Instantiate(hexTilePrefab, this.transform); h.transform.name = "HexTile (" + i + ", " + j + ")"; map[i, j] = h; h.Create(i, j); } } }
public static void GenerateDefault(HexGrid grid, int width, int height) { // Create a throwaway tile so that we can get the dimensions of it. Vector2 spriteSize = GetTileSize(); // Z for (int x = 0; x < width; x++) { // X for (int z = 0; z < height; z++) { float mod = x % 2; Vector2 position = new Vector2((x * spriteSize.x) * 0.75f, (z * spriteSize.y) + ((spriteSize.y * 0.5f) * mod)); grid.Tiles.Add(HexTile.Create(grid, TileType.Empty, position, new Vector2(x, z))); } } }
/// <summary> /// Generate a HexGrid using a file that has already been read. /// </summary> /// <param name="grid"></param> /// <param name="file"></param> public static void GenerateFromFile(HexGrid grid, List <HexMapCsv> file) { // Create a throwaway tile so that we can get the dimensions of it. Vector2 spriteSize = GetTileSize(); foreach (HexMapCsv row in file) { int x = row.X; int z = row.Z; float mod = x % 2; Vector2 position = new Vector2((x * spriteSize.x) * 0.75f, (z * spriteSize.y) + ((spriteSize.y * 0.5f) * mod)); grid.Tiles.Add(HexTile.Create(grid, row.TileType, position, new Vector2(x, z))); } grid.StoreToArray(); SetNeighbours(grid); }
/// <summary> /// Generate a HexGrid by providing a filename to be read, and then generated from. /// </summary> /// <param name="grid"></param> /// <param name="filename"></param> public static void GenerateFromFile(HexGrid grid, string filename) { List <HexMapCsv> file = HexMapFileSaver.ReadFile(filename); // Create a throwaway tile so that we can get the dimensions of it. Vector2 spriteSize = GetTileSize(); foreach (HexMapCsv row in file) { if (row.TileType != TileType.Empty) { Debug.Log("HELLO"); } int x = row.X; int z = row.Z; float mod = z % 2; Vector2 position = new Vector2((x * spriteSize.x) + ((spriteSize.x * 0.5f) * mod), (z * spriteSize.y) * 0.75f); grid.Tiles.Add(HexTile.Create(grid, row.TileType, position, new Vector2(x, z))); } }