Working with GridBehaviours

GridBehaviours* are what you use to add more behavior to your grid. With GridBehaviours, you can

get access the grid (as a data structure) and the associated map

hook in your own grid initialization code that also runs in the editor

get notified of mouse events

(* We follow Unity in using the British spelling despite American spellings for everything else.)

To use a GridBehaviour, you must extend from this class. GridBehaviour takes a type parameter denoting the point type of the grid. (Use the Grid Index if you are unsure which points to use).

For example, here is an empty implementation of a GridBehaviour for a PointyHexGrid:

C#

1

2

3

publicclassMyGrid:GridBehaviour<PointyHexPoint>

{

}

Accessing the Grid and Map

GridBehaviour provides properties with which you can access the grid and map.

Grid of type
IGrid<TileCell,TPoint>

Map of type
IMap3D<TPoint>

where TPoint is whatever the type parameter is of the GridBehaviour you extend from

These are the generic interfaces. They support all the common functionality, but at times, you may need to cast them to a specific grid or map. You may also need to cast them in the cell type to get more specific cell operations.

For example, if you implement a rectangular grid, your GridBehaviour will extend from
GridBehaviour<RectPoint>. You can then cast the grid and maps as follows: