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.
- Host: GitHub
- URL: https://github.com/ycarowr/unityhexagonlibrary2d
- Owner: ycarowr
- License: mit
- Created: 2019-12-14T23:57:59.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2021-04-17T11:53:36.000Z (about 4 years ago)
- Last Synced: 2024-10-10T10:24:20.810Z (7 months ago)
- Topics: 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
- Language: C#
- Homepage:
- Size: 19.1 MB
- Stars: 72
- Watchers: 5
- Forks: 15
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://unity3d.com/get-unity/download)
[](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;
...