UnityHexagonLibrary2d Save

A library to manage 2D hexagonal tiles in Unity.

Project README

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
<!--- Hover

Shapes & Sizes

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; ...
Open Source Agenda is not affiliated with "UnityHexagonLibrary2d" Project. README Source: ycarowr/UnityHexagonLibrary2d

Open Source Agenda Badge

Open Source Agenda Rating