Working with grids in the editor

PHEditorTo set up a grid in the editor, follow the following steps.

[dropcap style=”dark”]1[/dropcap]Make a new cell prefab that is appropriate for your grid. Cells are the things inside grids – the tiles that make up the grid, usually the objects responsible for how the grid is rendered. You will need to attach a cell component:

  • SpriteCell: For cells that use Unity sprites.
  • Block: For simple 3D objects (such as cubes).
  • MeshTileCell: For polar grids.

We provide these cells as starting points – it is likely that you will want to make your own cells by extending from one of these that add functionality specific to your game. To see how to do this, read Making your own cells.

[dropcap style=”dark”]2[/dropcap]Add an empty game object to your scene, and call it Grid.

[dropcap style=”dark”]3[/dropcap]Add the appropriate grid builder for your grid. In this example, we will add a pointy hex tile builder. The builder is the component that builds the Grid, and instantiate the cells inside the grid. You can use the Grid Index to see which tile builder you will need to add when it’s not obvious from the name.

[dropcap style=”dark”]4[/dropcap]Drag the cell prefab you made into the Cell Prefab slot on your grid. Your grid should now appear in the scene (usually, it will only be a single cell until you adjust some settings).

[dropcap style=”dark”]5[/dropcap]Select the Update Type for your grid. This tells the builder when to re-build the grid, and is useful to prevent slow-downs in the editor when you are working on brig or complicated grids.

  • Editor Auto: this updates the grid every time you change a setting on the grid builder.
    • Cells are destroyed when the grid is resized.
    • This mode may be slow in certain situations. In this case, rather use one of the other modes.
  • Editor Manual: in this mode, a Build Grid button appears at the top of the grid builder inspector. The grid will only be rebuilt if you press this button.
  • Game Start:in this case, the grid will not be built in the editor at all. It will only be built once the game starts.

[dropcap style=”dark”]6[/dropcap]You can now change the other settings to your liking. Below is a description of what each of these do.

Is Interactive Whether or not the grid will receive mouse input notifications. (This is currently only useful for 2D grids). See Working with GridBehaviours for more information on how to use these events.

Shape The shape of the grid. Each grid type supports several shapes. Note that this shape has nothing to do with cell shape – it only describes the shape of the overall grid. Depending on the shape, you may have an additional Size or Dimension property appear, which you can use to adjust the size of the shape. Many grids support a Custom shape, that allows you to specify your own shape by making a special component. See Making your own grid shapes for information on how to do this.

Map Type Although most grid types support only one type of map, some support more. For example, hex grids support both hex maps and brick maps (the Grid Index also shows which grids need which maps). We may add more map types in the future. You can also specify your own map by choosing Custom. See Making your own maps for information on how to do this.

Plane This is the plane in which the grid sits – either XY or XZ. Make sure your tiles are rotated to match.

Alignment This specifies how the grid is aligned with respect to the anchor. This is especially convenient for aligning 2D grids within your game’s GUI.

Use Color Whether a grid coloring should be applied. This only works of the cell type supports being colored in some cases – depending on how the color adjustment has been implemented in the cell – this can lead to material leakage in the editor. This is not too serious of you are just playing around trying to find the ideal grid settings. (We are considering making grid coloring a separate GridBehaviour, since not all games use it. If you have opinions about this, please let us know!)

The list of colors will be used. The pattern depends on the Color Function, which is described by three integers: X0, X1, Y1. These numbers represent the parallelogram in the grid between these two vectors: (X0, 0) and (Y1, Y2).

This parallelogram is the repeating unit of the coloring. (Of course, provided you give enough colors in the color list).

[info]To use grid methods on grids made with grid builders, you have to add a GridBehaviour, and use them on the Grid property. See Working with GridBehaviours for more detail.[/info]

Also see What are grid colorings?

Leave a Reply

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

Scroll to Top