Coder Social home page Coder Social logo

ycarowr / unityhexagonlibrary2d Goto Github PK

View Code? Open in Web Editor NEW
67.0 5.0 15.0 19.54 MB

A library to manage 2D hexagonal tiles in Unity.

License: MIT License

C# 100.00%
hexagonal-board hexagon hexagonal-tiles hexagonal-grids unity3d unity2d unity tile hexagonal-grid-library hexagonal

unityhexagonlibrary2d's Introduction

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; ...

unityhexagonlibrary2d's People

Contributors

ycarowr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.