Making your own maps

CustomEditorMapsEditor 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.

See Working with Maps for more information on working with maps in code.

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:

public void RotatedMap
{
   public float angle;
   
   public override IGrid CreateWindowedMap()
   {
      if (typeof (TPoint) == typeof (PointyHexPoint))
      {
         Debug.LogError("You can only use this MapBuilder with pointy hex grids", this);
      }
	  
      return new PointyHexMap(new Vector(69, 80))
         .Rotate(angle)
         .WithWindow(new Rect(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.)

CustomMapsInTheEditor.unitypackage

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to Top