Struct Int2Grid
A 2D-grid where each cell is defined as an int2 Travelling one cell along the map has a cost of 1 + destination cell cost. Travelling diagonally has a cost of sqrt(2) + destination cell cost. Unset cells have a default cost of zero. To make a cell unwalkable, assign it a cost of infinity. This means that every location is walkable by default.
Namespace: AnyPath.Graphs.Int2Grid
Assembly: Assembly-CSharp.dll
Syntax
public struct Int2Grid : IGraph<Int2GridCell>, IGraph, INativeDisposable, IDisposable
Constructors
| Improve this Doc View SourceInt2Grid(int2, int2, Int2GridType, IReadOnlyList<HexGridCell>, Allocator)
Constructs a new grid
Declaration
public Int2Grid(int2 min, int2 max, Int2GridType neighbourMode, IReadOnlyList<HexGridCell> cells, Allocator allocator)
Parameters
Type | Name | Description |
---|---|---|
Unity.Mathematics.int2 | min | Boundary min |
Unity.Mathematics.int2 | max | Boundary max |
Int2GridType | neighbourMode | Should cells have four or eight neighbours? |
System.Collections.Generic.IReadOnlyList<HexGridCell> | cells | Array containing the cells to set initially |
Unity.Collections.Allocator | allocator | Allocator to use |
Int2Grid(int2, int2, Int2GridType, Int32, Allocator)
Constructs a new grid
Declaration
public Int2Grid(int2 min, int2 max, Int2GridType neighbourMode, int capacity, Allocator allocator)
Parameters
Type | Name | Description |
---|---|---|
Unity.Mathematics.int2 | min | Boundary min |
Unity.Mathematics.int2 | max | Boundary max |
Int2GridType | neighbourMode | Should cells have four or eight neighbours? |
System.Int32 | capacity | Initial capacity of the internal hashmap |
Unity.Collections.Allocator | allocator | Allocator to use |
Fields
| Improve this Doc View Sourcemax
The boundary -max- position
Declaration
public readonly int2 max
Field Value
Type | Description |
---|---|
Unity.Mathematics.int2 |
min
The boundary -min- position
Declaration
public readonly int2 min
Field Value
Type | Description |
---|---|
Unity.Mathematics.int2 |
neighbourMode
Type of grid, 4 our 8 neighbours
Declaration
public readonly Int2GridType neighbourMode
Field Value
Type | Description |
---|---|
Int2GridType |
Methods
| Improve this Doc View SourceCollect(Int2GridCell, ref NativeList<Edge<Int2GridCell>>)
Collects all neighbouring cells from a given location
Declaration
public void Collect(Int2GridCell node, ref NativeList<Edge<Int2GridCell>> edgeBuffer)
Parameters
Type | Name | Description |
---|---|---|
Int2GridCell | node | The location to find the neighbours for |
Unity.Collections.NativeList<Edge<Int2GridCell>> | edgeBuffer |
GetCell(int2)
Returns the cell at a given position.
Declaration
public Int2GridCell GetCell(int2 position)
Parameters
Type | Name | Description |
---|---|---|
Unity.Mathematics.int2 | position |
Returns
Type | Description |
---|---|
Int2GridCell |
GetCost(int2)
Returns the enter cost of a given position. Note that unset cells are considered open and have an entering cost of zero.
Declaration
public float GetCost(int2 position)
Parameters
Type | Name | Description |
---|---|---|
Unity.Mathematics.int2 | position |
Returns
Type | Description |
---|---|
System.Single |
GetEnumerator()
Enumerates all of the cells in the grid, including unset ones. This can be used for constructing ALT<TNode> heuristics.
Declaration
public Int2Grid.Enumerator GetEnumerator()
Returns
Type | Description |
---|---|
Int2Grid.Enumerator |
GetSetCells(Allocator)
Allocates an array containing all of the cells that are set on this grid.
Declaration
public NativeArray<Int2GridCell> GetSetCells(Allocator allocator)
Parameters
Type | Name | Description |
---|---|---|
Unity.Collections.Allocator | allocator |
Returns
Type | Description |
---|---|
Unity.Collections.NativeArray<Int2GridCell> |
InBounds(int2)
Returns wether a certain position is within the bounds of the grid
Declaration
public bool InBounds(int2 position)
Parameters
Type | Name | Description |
---|---|---|
Unity.Mathematics.int2 | position |
Returns
Type | Description |
---|---|
System.Boolean |
IsOpen(int2)
Returns wether a cell at a position is open/walkable.
Declaration
public bool IsOpen(int2 position)
Parameters
Type | Name | Description |
---|---|---|
Unity.Mathematics.int2 | position |
Returns
Type | Description |
---|---|
System.Boolean |
SetCell(int2, Single, Int32)
Sets the cost for a cell.
Declaration
public void SetCell(int2 position, float enterCost, int flags = 0)
Parameters
Type | Name | Description |
---|---|---|
Unity.Mathematics.int2 | position | Position to set |
System.Single | enterCost | Additional cost for walking this cell. Use float.PositiveInfinity to make this cell unwalkable |
System.Int32 | flags | Flags for this cell, this can be used in conjunction with FlagBitmask<TNode> to exclude certain areas. |
Remarks
No bounds checking is done on the position