Awesome Open Source
Awesome Open Source

Unity Version Twitter

A hexagonal board implementation in Unity

The repository contains an API to create, find and store data inside a hexagonal board using Unity Tile Maps and the math described by redblob & references.

A few reasons why I made the project:

  1. I wanted a generic API that could be easily be extended or integrated into a secondary project;
  2. I wanted set of generic classes that manage hexagons and are able to store any kind of data. What I mean by data: creatures, pieces, itens or whatever a main project needs;
  3. I wanted to use the native Unity TileMaps components;

You can find below images that illustrate the functionalities and an overview of the system's implementation.

Feel free to use this tool. Any kind of feedback or credit is well appreciated.

Playable demo here

Functionalities

Diagonals Horizontal
Neighbours Tile Orientation
Add Objects Remove Objects

Shapes & Sizes

Menu & Interface

The interface menu to interact with the board data and test the operations.

Implementation

MVC

  1. Model
  2. Views
  3. Controller

Board

I split the board implementation in three distinct parts:

  1. Board has a data shape that determines it's layout. Also holds a list of Positions that store the data elements on the board;
  2. BoardManipulation is resposible to implement the operations such as diagonals, neighbours or anything else that could come up in the future;
  3. Position is the class that holds the elements placed in the board; Currently each position is able to hold one single object, however it can be extended to an array;

Coordinates

There are two different Coordinates to manage, the Hex and Offset.

  1. Hex is used internally by the Manipulation to figure out the necessary points to include in each operation. Operations using this type of coordinate system have simpler algorithms.
  2. Offset is used by Unity TileMaps native component, in other words, we can't change it;
  3. OffsetCoordHelper is the class that manages the convertion from Hex -> Offset or Offset -> Hex;

TODO

  1. How to use the tool;
  2. How to define your own data;
  3. How to change tiles; ...


Alternative Project Comparisons
Related Awesome Lists
Top Programming Languages
Top Projects

Get A Weekly Email With Trending Projects For These Topics
No Spam. Unsubscribe easily at any time.
Unity (18,433
Unity3d (5,612
Hex (4,512
Hexagonal (576
Hexagon (544
Unity2d (528
Tilemap (414
Unity3d Plugin (388
Unity Asset (260
Unity Scripts (245
Tiled Map Editor (75
Hexagonal Grids (25
Hexagonal Grid Library (5
Hexagonal Tiles (4