An open API service indexing awesome lists of open source software.

https://github.com/ycarowr/unityhexagonlibrary2d

A library to manage 2D hexagonal tiles in Unity.
https://github.com/ycarowr/unityhexagonlibrary2d

board hexagon hexagonal hexagonal-board hexagonal-grid-library hexagonal-grids hexagonal-tiles hexagons tile tiled-map-editor tilemap tilemaps tiles unity unity-3d unity-asset unity-scripts unity2d unity3d unity3d-plugin

Last synced: 3 months ago
JSON representation

A library to manage 2D hexagonal tiles in Unity.

Awesome Lists containing this project

README

        

[![Unity Version](https://img.shields.io/badge/Unity-2019.2.7f2%2B-blue.svg)](https://unity3d.com/get-unity/download)
[![Twitter](https://img.shields.io/twitter/follow/ycarowr.svg?label=Follow@ycarowr&style=social)](https://twitter.com/intent/follow?screen_name=ycarowr)

# 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](https://docs.unity3d.com/Manual/class-Tilemap.html) and the math described by [redblob](https://www.redblobgames.com/grids/hexagons/) & 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](https://docs.unity3d.com/Manual/class-Tilemap.html) 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](https://ycarowr.itch.io/hexagonal-board)

## 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](/Assets/Scripts/BoardSystem/Board)
2. [Views](/Assets/Scripts/Ui)
3. [Controller](/Assets/Scripts/BoardSystem/BoardController.cs)

## Board
I split the board implementation in three distinct parts:
1. [Board](/Assets/Scripts/BoardSystem/Board/Board.cs) 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](/Assets/Scripts/BoardSystem/Board/BoardManipulationOddR.cs) is resposible to implement the operations such as diagonals, neighbours or anything else that could come up in the future;
3. [Position](/Assets/Scripts/BoardSystem/BoardController.cs) 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](/Assets/Scripts/BoardSystem/Board/Coordinates) to manage, the Hex and Offset.
1. [Hex](Assets/Scripts/BoardSystem/Board/Coordinates/Hex.cs) 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](/Assets/Scripts/BoardSystem/Board/Coordinates/OffsetCoord.cs) is used by Unity [TileMaps](https://docs.unity3d.com/Manual/class-Tilemap.html) native component, in other words, we can't change it;
3. [OffsetCoordHelper](Assets/Scripts/BoardSystem/Board/Coordinates/OffsetCoordHelper.cs) 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;
...