Skip to content

GridCells

namespace Griff.Scenes;
public struct GridCells

The cells grid movers step between: a tilemap’s (its transform and tile size), or with none, world units centered on whole numbers. Rows count down either way, so a way (x right, y up) changes the cell by Offset(way), except on a hex map, where a way up or down goes to one of the two hexagons above or below (see Step).

public bool IsHex { get; }

Whether its cells are a hex map’s hexagons.

public bool IsIsometric { get; }

Whether its cells are an isometric map’s diamonds.

public Tilemap? Map { get; init; }
public Matrix4x4 ToLocal { get; init; }
public Matrix4x4 World { get; init; }
public bool AreNeighbours(ValueTuple<int, int> a, ValueTuple<int, int> b)

Whether one cell is next to another (see Neighbours; on a square map, diagonally too).

public ValueTuple<int, int> CellAt(Vector2 world)

The cell a world position is in.

public Vector2 Center(ValueTuple<int, int> cell)

The world position of the middle of a cell.

public Vector2[] Corners(ValueTuple<int, int> cell, float scale)

A cell’s corners in the world, round its edge, shrunk to scale of it round its middle.

public void Deconstruct(out Tilemap? Map, out Matrix4x4 World, out Matrix4x4 ToLocal)
public override bool Equals(object obj)
public bool Equals(GridCells other)
public override int GetHashCode()
public Vector2 InWorld(Vector2 way)

A way along the grid (x right, y up, a step’s worth) as it looks in the world: on an isometric map, (0, 1) is up to the right; on a hex map, (1, 1) is up to the right, to the hexagon half a tile across in the row above.

public ValueTuple<int, int>[] Neighbours(ValueTuple<int, int> cell, bool diagonal)

The cells next to one, as changes of cell (column, then row down): the six hexagons round it on a hex map, else the four beside it, or eight with the diagonals.

public static GridCells Of(Tilemap? map)

The cells of map, or of world units when it is null or has no entity.

public static ValueTuple<int, int> Offset(ValueTuple<int, int> way)

The change of cell for a way (x right, y up): rows count down, so y is negated.

public ValueTuple<int, int> Resolve(ValueTuple<int, int> cell, ValueTuple<int, int> way)

A way to step from a cell, as one of the grid’s own: on a hex map, straight up or down (0, ±1) is to the hexagon above or below on the right from an even row and on the left from an odd one, so holding it zigzags straight up the screen; every other way, and every way on other maps, is itself.

public IEnumerable<Matrix4x4> Shape(ValueTuple<int, int> cell, float scale)

What covers a cell’s shape in the world, shrunk to scale of it round its middle, as transforms of the unit quad: a square, a diamond or a hexagon (see CellShape).

public ValueTuple<int, int> Step(ValueTuple<int, int> cell, ValueTuple<int, int> way)

The cell a step (x right, y up) from a cell goes into: on a hex map, the hexagon that way (see Resolve).

public int Steps(ValueTuple<int, int> a, ValueTuple<int, int> b, bool diagonal)

The fewest steps from one cell to another with nothing in the way: across and down, or with diagonal steps the longer of the two, and on a hex map the hexagons between them, whichever way they lie.

public override string ToString()
public Vector2 Toward(Vector2 offset, bool diagonal)

The way (x right, y up) to face to look along a world offset: on a hex map, the one of its six ways nearest the offset’s direction; on others, along the grid’s longer axis, or both if it steps diagonally. Down, for none.

public ValueTuple<int, int> WayBetween(ValueTuple<int, int> from, ValueTuple<int, int> to)

The way (x right, y up) a step from one cell into a neighbouring one goes: the other way from Step.

public Vector2 WayOf(Vector2 offset)

A world offset as a way along the grid (x right, y up, in cells): the other way from InWorld.