private void BuildPuzzle() { const int size = 5; tileGrid = RectGrid <SpriteCell> .Rectangle(size, size); blocksGrid = (RectGrid <Block>)tileGrid.CloneStructure <Block>(); map = new RectMap(new Vector2(200, 200)) .AnchorCellMiddleCenter() .WithWindow(ExampleUtils.ScreenRect) .AlignMiddleCenter(tileGrid) .To3DXY(); foreach (RectPoint point in tileGrid) { var cell = MakeCell(point); tileGrid[point] = cell; blocksGrid[point] = null; } blocks = new List <Block>(); AddFirstBlock(); AddOtherBlocks(); winPosition = new RectPoint(4, 2); }
private void BuildGrid() { // Creates a grid in a rectangular shape. grid = RectGrid <SpriteCell> .Rectangle(51, 111); // Creates a map... map = new RectMap(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 (RectPoint 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 = (point.Magnitude() % 2 == 0)? Color2 : Color2; if ((point.X == 3 || point.X == 47) && (point.Y > 2 && point.Y < 108)) { cell.Color = new Color(0.8f, 0.8f, 0.8f); } if ((point.Y == 3 || point.Y == 107 || point.Y == 55) && (point.X > 2 && point.X < 48)) { cell.Color = new Color(0.8f, 0.8f, 0.8f); } if ((point.X == 21 || point.X == 29) && (point.Y <= 2 || point.Y >= 108)) { cell.Color = new Color(0.8f, 0.8f, 0.8f); } if ((point.Y == 0 || point.Y == 110) && (point.X > 21 && point.X < 29)) { cell.Color = new Color(0.8f, 0.8f, 0.8f); } cell.name = point.ToString(); // Makes it easier to identify cells in the editor. grid[point] = cell; // Finally, put the cell in the grid. //if (point.X >= 3 && point.X <= 47 && point.Y >= 3 && point.Y <= 107) //{ rectPointArr[point.X, point.Y] = point; //} } }
public IEnumerator BuildGrid() { totalCellCount = 0; grid = RectGrid <TileCell> .Rectangle(width, height); map = new RectMap(new Vector2(80, 80) * 3) .To3DXY(); int cellCount = 0; foreach (var point in grid) { var cell = Instantiate(cellPrefab); var worldPoint = map[point]; cell.transform.localPosition = worldPoint; cellCount++; totalCellCount++; grid[point] = cell; if (cellCount >= cellsPerIteration) { cellCount = 0; yield return(null); } } }
private void BuildGrid() { // Creates a grid in a rectangular shape. grid = RectGrid <SpriteCell> .Rectangle(7, 7); // Creates a map... map = new RectMap(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 (RectPoint 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.GetColor4() % 4 * 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. } }
private void BuildGrid() { //ShipCell defaultCell = CreateDefaultShipCell(); // Creates a grid in a rectangular shape. grid = RectGrid <ShipCell> .Rectangle((int)gridSize.x, (int)gridSize.y); // Creates a map... map = new RectMap(cellSize).To3DXY(); foreach (RectPoint point in grid) //Iterates over all points (coordinates) contained in the grid { ShipCell cell = Instantiate(prefab); Vector3 worldPoint = map[point]; //Calculate the world point of the current grid point cell.transform.parent = 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.name = point.ToString(); // Makes it easier to identify cells in the editor. grid[point] = cell; // Finally, put the cell in the grid. } }