Repository navigation
Grid Manager
The Grid Manager stores all information about nodes in the map.
Access the Manager by accessing it's static instance variable
GridManager.instance
The Grid's size is determined by the groundTransform's scale.
The Grid is generated by a 2D for loop which will expand to the gridSize Vector2 and have a spacing of 1 unit between cells.
The availability of Cells is determined by the groundMask and obstacleMask LayerMasks. A ray is dropped downward on a Cell's position and the yPos of the Cell is the hit.point.y. The availability of the Cell is determined by whether or not a object with the obstacleMask was hit.
Cells are stored in a Dictionary with key types as a Vector2 which represent the X and Z value for the Cell and world position of the Cell, and a value type of a Cell
Dictionary<Vector2, Cell> grid = new Dictionary<Vector2, Cell>()
Modifying the value of Cells is prohibited.
Cell FindClosestCell(Vector2 position, bool availableOnly = false)
position will be the x and z position of a point.
Cell FindClosestCell(Vector3 position, bool availableOnly = false)
position will only take the x and z value to find a cell.
availableOnly determines if the Cell needs to be available otherwise it will look for the next closest available cell.
Returns the closest cell based on the position provided.
List<Cell> FindCellsInRegion(Vector2 position, Vector2 region)
This will return cells in the region provided except for the cell at the position.
region is the scale of the cells to find. A region of (1,1) will get cells to the left, right, bottom, and top, of the current cell.
List<Cell> FindCellsAround(Cell cell, bool availableOnly = true)
Returns a list of cells that are in the 8 directions of the Cell provided.
List<Cell> FindCellsAdjacent(Cell cell, bool availableOnly = true)
Returns a list of cells that are in the 4 directions of the cell provided.
static float GetDistance(Vector3 a, Cell b)
static float GetDistance(Cell a, Cell b)
Returns the distance between two points.
float GetHeight(int x, int y)
y is the z position of the cell.
Returns an updated yPosition of the cell at the provided coordinates.
bool CheckAvailability(Cell cell)
Returns an updated availability for the provided Cell.
static List<Cell> SetCosts(List<Cell> openList, Cell targetCell, Cell startCell)
Sets the gCost and hCost for the cells provided.
Used for an A* Algorithm.
static Cell FindLowestCostCell(List<Cell> list)
Returns the cell from the list with the lowest fCost.
Version 1.0