# Make It Tile

$75 on the Unity Asset Store | Discuss

Requires Unity 5.0.0 or higher.

*A serious tile and topology framework for serious engineers.*

Make It Tile is a framework for Unity to aid in the creation and usage of tile-based game worlds. Through its carefully engineered data structures, it is designed to be maximally flexible, applying just as easily to the simple 8x8 game world of chess as to a large hex grid in a strategy game or even an irregular arrangement of tiles on the surface of a sphere. It includes support for:

- completely custom attributes for tiles, edges, or vertices
- square, hex, and irregular grids
- planar and spherical surfaces
- world edge wrap-around
- mouse picking
- A* path finding
- dynamic mesh generation
- neighboring tile visitation

As a bonus, and in support of tiled world generation, Make It Tile includes the full Make It Random and Make It Colorful libraries.

In addition to the above features, the framework is very extensible, to support whatever tiling patterns, tile attributes, and algorithms you might need. Full source code is included.

*Scripting Note:* Although the framework does contain some experimental high-level tools usable directly within the editor,
it is not designed as a top-to-bottom solution, but is rather intended to be a foundation upon which many different game mechanics can be easily built.
Additional scripting will therefore be necessary in almost all cases.

## The Details

### Topologies

- A topology data structure representing the vertices, edges, and faces of a 2D graph.
- Easily enumerate the neighbors of a vertex or face.
- Efficiently store and access arbitrary custom data for each vertex, edge, or face.

### Grids

- Square, rectangular, and general parallelogram tiles.
- Regular and irregular hexagonal tiles, with support for pixel-perfect integral sizes.
- Spherical worlds based on subdivisions of the five Platonic solids.
- Irregular tile randomization for any grid, planar or spherical.

### Wrap-Around Worlds

- Data structures and algorithms that work naturally with wrap-around worlds.
- Wrap around either the horizontal or vertical axis, or both.
- Works for planar worlds with square, hexagonal, or even irregular tiles.

### Mouse Picking

- Data structure to efficiently look up tiles.
- Finds tile intersected by a ray.
- Finds tile nearest to a point.
- Works for any grid system regardless of world or tile shape.

### A* Path Finding

- Efficient path finding methods implemented using the A* algorithm.
- Can use custom tile or tile-to-tile path costs.
- Can path between tile corners along tile edges.

### Dynamic Mesh Generation

- Helper utility to construct a dynamic mesh for tiles in a game world.
- Custom tile triangulation techniques supported.
- Includes multiple tile triangulation techniques for common cases.
- Handles large vertex/triangle count and splitting into multiple meshes.

### Tile Visitation

- Easily implement searches and visitation over the tiles of a world.
- Fast arbitrary-order adjacency visitation starting from one or more root tiles.
- Breadth-first and depth-first searches, based on depth, world distance, or custom distance.
- Proper random order adjacency visitation, good for randomly generating groups of tiles.

## Samples

Here is a sample of creating a square grid and performing arbitrary operations over the elements of the resulting topology.

```
using UnityEngine;
using Experilous.MakeItTile;
// Create a square grid.
RectangularQuadGrid surface = var grid = RectangularQuadGrid.Create(
Vector2.right, Vector2.up, // 2D axes
Vector3.zero, Quaternion.identity, // origin and orientation
false, false, // axis wrap-around
new IntVector2(5, 3)); // grid size
Vector3[] vertexPositionsArray;
Topology topology = surface.CreateManifold(out vertexPositionArray);
var vertexPositions = vertexPositionsArray.AsVertexAttribute();
var faceColors = new FaceAttributeArrayWrapper<Color>(topology.internalFaces.Count);
var edgeCosts = new EdgeAttributeArrayWrapper<float>(new float[topology.halfEdges.Count]);
// Element collections can be enumerated using a foreach loop:
foreach (Topology.Vertex vertex in topology.vertices)
{
Debug.LogFormat("{0}", vertexPositions[vertex]); // Log out the position of each vertex.
}
// They can also be accessed by integer indices:
for (int i = 0; i < topology.faces.Count; ++i)
{
Topology.Face face = topology.faces[i];
faceColors[face] = Color.red;
}
// The two subsets of faces, internal and external, can also be enumerated:
foreach (Topology.Face face in topology.internalFaces)
{
// do something with the face
}
// The edges are accessible in three varieties, all representing
// the same set of edges, but producing different behavior in
// certain cases, as will be explained in other topics.
foreach (Topology.HalfEdge edge in topology.halfEdges)
{
edgeCosts = UnityEngine.Random.value + 1f;
}
// While accessing all the elements, the neighbors of each
// individual element can also be enumerated within inner loops.
foreach (Topology.Vertex vertex in topology.vertices)
{
// Automatic enumeration using the edges property
foreach (Topology.VertexEdge edge in vertex.edges)
{
Debug.LogFormat("From Vertex {0} to Vertex {1}, Edge Cost = {2}",
edge.nearVertex.index,
edge.farVertex.index,
edgeCosts[edge]);
}
// Manual enumeration using the firstEdge and next properties
var firstEdge = vertex.firstEdge;
var currentEdge = firstEdge;
do
{
// do something with currentEdge
currentEdge = currentEdge.next;
} while (currentEdge != firstEdge);
}
```

Purchase Make It Tile now from the Unity Asset Store