// Start is called before the first frame update void Start() { // Room template 1 Room.CellType[,] CT = new Room.CellType[width, height] { //Bottom left //Top Left { CellType.tg, CellType.e, CellType.e, CellType.e, CellType.e, CellType.e, CellType.e, CellType.e, CellType.e, CellType.e }, { CellType.tg, CellType.e, CellType.e, CellType.rg, CellType.rg, CellType.rg, CellType.rg, CellType.rg, CellType.rg, CellType.e }, { CellType.tg, CellType.e, CellType.e, CellType.rg, CellType.rg, CellType.rg, CellType.rg, CellType.rg, CellType.rg, CellType.e }, { CellType.tg, CellType.e, CellType.e, CellType.rg, CellType.rg, CellType.rg, CellType.rg, CellType.rg, CellType.rg, CellType.e }, { CellType.tg, CellType.e, CellType.e, CellType.rg, CellType.rg, CellType.rg, CellType.rg, CellType.rg, CellType.rg, CellType.e }, { CellType.tg, CellType.e, CellType.e, CellType.rg, CellType.rg, CellType.rg, CellType.rg, CellType.rg, CellType.rg, CellType.e }, { CellType.tg, CellType.e, CellType.e, CellType.rg, CellType.rg, CellType.rg, CellType.rg, CellType.rg, CellType.rg, CellType.e }, { CellType.tg, CellType.e, CellType.e, CellType.e, CellType.e, CellType.e, CellType.e, CellType.e, CellType.e, CellType.e }, //Bottom right //Top right }; cellSize = 5.0f; grid = new Grid <Cell>(width, height, cellSize, originPosition, () => new Cell()); Cell[,] cells = grid.GetGrid(); // Loop throught the grid of cells and determine which cells get ground tiles. for (int i = 0; i < cells.GetLength(0); i++) { for (int j = 0; j < cells.GetLength(1); j++) { // Current cell Cell cell = (Cell)cells.GetValue(i, j); cell.cellType = CT[i, j]; // Set room types to the template if (cell.cellType == CellType.tg) // Place template ground tiles { cell.PlaceTile(grid.GetWorldPosition(i, j), cellSize); } // If the cell is a random cell. Generate a random number between 0-2 (actual values would be 0 and 1 bc of how the range function works) else if (cell.cellType == CellType.rg) { int number = Random.Range(0, 2); Debug.Log(number); if (number == 1) { cell.PlaceTile(grid.GetWorldPosition(i, j), cellSize); } } // Debug draw room types // grid.SetDebugTextValue(i,j, RG.Utils.Utils.CreateWorldText( // cells[i,j].GetCellType().ToString(), // null, // grid.GetWorldPosition(i,j) + new Vector3(cellSize, cellSize) *0.5f, // 20, // Color.white, // TextAnchor.MiddleCenter // ) // ); } } }
// Method to get a specific cell that exists 'below' the GUI public SpreadsheetCell GetCell(int row, int column) { if (((row >= 0) & (row < Rows)) & ((column >= 0) & (column < Columns))) { return((SpreadsheetCell)array.GetValue(row, column)); } else { return(null); } }
public Cell this[int y, int x] { get { try { cells.GetValue(y, x); } catch { return(null); } return((Cell)cells.GetValue(y, x)); } set { cells[y, x] = value; } }
private Location[] GetNeighbours(Location loc) { List <Location> result = new List <Location>(); if (loc.X > 0) { result.Add(сells[loc.X - 1, loc.Y]); } if (loc.X < сells.GetUpperBound(0)) { result.Add(сells[loc.X + 1, loc.Y]); } if (loc.Y > 0) { result.Add(сells[loc.X, loc.Y - 1]); } if (loc.Y < (сells.GetValue(сells.GetUpperBound(сells.Rank - 2), сells.GetUpperBound(сells.Rank - 1)) as Location).Y) { result.Add(сells[loc.X, loc.Y + 1]); } return(result.Where(l => сells[l.X, l.Y].Passability > 0).ToArray()); }