Making your own maps

Editor grids support 2D maps that are converted to 3D maps and lie in either the XY or XZ planes. You can provide a custom 2D map, but have to use either of the two provided conversions to 3D. (For custom 3D conversion, you have to build grids in code).

To make your own map:

Extend a new class from CustomMapBuilder.

Override the methods CreateMap, and return a new WindowedMap from it. You can use the map construction methods, or implement your own map from scratch.

Add the component to the same game object as the grid builder you want to use, and set the Map to property to Custom.

It’s a good idea to test that the point type is of the right type, and print an error message if the test fails. This will prevent someone from trying to use your map with the wrong type of grid.

Also note the cast before returning the grid. The cast is necessary because the point type of the map created in code is more specific than the one required, and C# cannot do the conversion automatically.

The following example rotates the grid (but not the cells themselves) by the amount specified in the inspector:

C#

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

publicvoidRotatedMap

{

publicfloatangle;

publicoverrideIGrid<TCell,TPoint>CreateWindowedMap()

{

if(typeof(TPoint)==typeof(PointyHexPoint))

{

Debug.LogError("You can only use this MapBuilder with pointy hex grids",this);

}

returnnewPointyHexMap(newVector(69,80))

.Rotate(angle)

.WithWindow(newRect(0,0,0,0));

}

}

Here is an example that shows how to set it up:

(Import Grids, import the package, and open the CustomShapesInTheEditor scene.)