Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- public class BaseGrid : MonoBehaviour {
- // This is where the grid is instantiated and other scripts can access it
- public CellPoint[,] grid;
- [SerializeField]
- private int width, height;
- [SerializeField] private float distanceBetweenCells = 10f;
- [SerializeField] private GameObject cell;
- public Transform GetCellTransform(int x, int z) {
- return grid[x, z].transform;
- }
- private void Awake() {
- grid = new CellPoint[width, height];
- float xPos = 0, zPos = 0;
- for(int i = 0; i < width; i++) {
- for(int j = 0; j < height; j++) {
- GameObject newCell = Instantiate(cell, new Vector3(xPos, 0, zPos), Quaternion.identity, transform);
- newCell.GetComponent<CellPoint>().SetCellCords(i,j); // TODO
- grid[i, j] = newCell.GetComponent<CellPoint>();
- zPos += distanceBetweenCells;
- }
- xPos += distanceBetweenCells;
- zPos = 0;
- }
- }
- public CellType[] GetCellNeighbourTypes(int cellX, int cellZ) {
- // 0 up, 1 right, 2 down, 3 left
- CellType[] returnCells = { CellType.None, CellType.None, CellType.None, CellType.None};
- // TODO add if's to remove errors
- returnCells[0] = grid[cellX, cellZ + 1].GetCurrentCellType();
- returnCells[1] = grid[cellX, cellZ - 1 ].GetCurrentCellType();
- returnCells[2] = grid[cellX - 1, cellZ].GetCurrentCellType();
- returnCells[3] = grid[cellX + 1, cellZ].GetCurrentCellType();
- return returnCells;
- }
- public CellType[] GetCellNeighbourTypes(CellPoint cellPoint) {
- // 0 up, 1 right, 2 down, 3 left
- CellType[] returnCells = { CellType.None, CellType.None, CellType.None, CellType.None};
- // TODO add if's to remove errors
- int cellX = cellPoint.GetCellX();
- int cellZ = cellPoint.GetCellZ();
- returnCells[0] = grid[cellX, cellZ + 1].GetCurrentCellType();
- returnCells[1] = grid[cellX, cellZ - 1 ].GetCurrentCellType();
- returnCells[2] = grid[cellX - 1, cellZ].GetCurrentCellType();
- returnCells[3] = grid[cellX + 1, cellZ].GetCurrentCellType();
- return returnCells;
- }
- public CellPoint[] GetCellNeighbours(int cellX, int cellZ) {
- // 0 up, 1 right, 2 down, 3 left
- CellPoint[] returnCells = { null, null, null, null };
- // TODO add if's to remove errors
- returnCells[0] = grid[cellX, cellZ + 1];
- returnCells[1] = grid[cellX, cellZ - 1];
- returnCells[2] = grid[cellX - 1, cellZ];
- returnCells[3] = grid[cellX + 1, cellZ];
- return returnCells;
- }
- public CellPoint[] GetCellNeighbours(CellPoint cellPoint) {
- // 0 up, 1 right, 2 down, 3 left
- CellPoint[] returnCells = { null, null, null, null };
- int cellX = cellPoint.GetCellX();
- int cellZ = cellPoint.GetCellZ();
- // TODO add if's to remove errors
- returnCells[0] = grid[cellX, cellZ + 1];
- returnCells[1] = grid[cellX, cellZ - 1];
- returnCells[2] = grid[cellX - 1, cellZ];
- returnCells[3] = grid[cellX + 1, cellZ];
- return returnCells;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement