private void BuildGrid() { const int width = 6; const int height = 9; grid = PointyHexGrid <SpriteCell> .FatRectangle(width, height); map = new PointyBrickMap(cellPrefab.Dimensions) .AnchorCellMiddleCenter() .WithWindow(ExampleUtils.ScreenRect) .AlignMiddleCenter(grid) .To3DXY() ; foreach (PointyHexPoint point in grid) { SpriteCell cell = Instantiate(cellPrefab); Vector2 worldPoint = map[point]; cell.transform.parent = root.transform; cell.transform.localScale = Vector3.one; cell.transform.localPosition = worldPoint; cell.Color = ExampleUtils.Colors[point.GetColor3_7()]; cell.name = point.ToString(); grid[point] = cell; } }
private void BuildGrid() { // Creates a grid in a rectangular shape. grid = PointyHexGrid <SpriteCell> .FatRectangle(7, 7); // Creates a map... map = new PointyHexMap(cellPrefab.Dimensions) // The cell dimensions usually correspond to the visual // part of the sprite in pixels. Here we use the actual // sprite size, which causes a border between cells. // .WithWindow(ExampleUtils.ScreenRect) // ...that is centered in the rectangle provided .AlignMiddleCenter(grid) // by this and the previous line. .To3DXY(); // This makes the 2D map returned by the last function into a 3D map // This map assumes the grid is in the XY plane. // To3DXZ assumes the grid is in the XZ plane (you have to make sure //your tiles are similarly aligned / rotated). foreach (PointyHexPoint point in grid) //Iterates over all points (coordinates) contained in the grid { SpriteCell cell = Instantiate(cellPrefab); // Instantiate a cell from the given prefab. //This generic version of Instantiate is defined in GLMonoBehaviour //If you don't want to use GLMonoBehvaiour, you have to cast the result of //Instantiate Vector3 worldPoint = map[point]; //Calculate the world point of the current grid point cell.transform.parent = root.transform; //Parent the cell to the root cell.transform.localScale = Vector3.one; //Readjust the scale - the re-parenting above may have changed it. cell.transform.localPosition = worldPoint; //Set the localPosition of the cell. cell.Color = ExampleUtils.Colors[point.GetColor2_4()]; //Sets the color of the cell //See http://gamelogic.co.za/2013/12/18/what-are-grid-colorings/ for more information on colorings. cell.name = point.ToString(); // Makes it easier to identify cells in the editor. grid[point] = cell; // Finally, put the cell in the grid. } }