The HexGrid Simplified Library allows you to create games which use a hexagonal grid easily and for most things  you do not need to worry about any math at all. 

It is written in C# and aside from the Vector2Int and Vector3Int structs and using the Mathf. functions of Unity instead of System.Math it does not use anything Unity specific so can easily be adapted for non-unity usage. All the examples however make heavy use of unity.

It probably is most useful for Turnbased Strategy or RPG games but everything would also work for real time games. 

It includes a lot of examples, in fact the examples are like 80% of the package and a lot more complex than the actual Library. Those examples (which you can also test here directly in the browser) shall give you an idea what you can do and how to do it. However those examples were written to be as self-contained and easy to understand as possible and have no resemblance of well organized code in a real project. So look at those to understand how to work with the library and to get inspired but absolutely do not just copy them or you will cause yourself trouble further down the line.

It supports bound checks and horizontal wrap (cylindrical) for hexagon maps with a rectangular layout , the most common layout in Civ-Style games.

 It supports multiple maps with different sizes - although the example scenes just use one map.

To keep it as simple as possible there are few restrictions which kept the code smaller and simpler than a solution which covers absolutely everything:

1) It only supports "Pointy-Top Hexes" (hexagons with a corner on top/bottom)
2) the hexagons have a radius of 1 (there is no real good reason to use another radius)
3) odd rows are shoved to the  right
4) bound checking and world-wrap logic only supports maps with a rectangular layout 

For the vast majority of projects those limitations are meaningless and if you plan to build something super odd you can still use this here as a starting point. 

I tried to keep the code as simple and easy to understand as possible and did not focus on what would be in most cases premature Optimization. If you encounter a performance issue with one the methods in this library, the most likely solution will be to cache the results as offsets from origin and look them up instead of recalculating them everytime.

better Code comments and Documentation are still a work in progress.

Special thanks to Amit Patel and his great website on game programming! ( redblobgames.com )

More information

Published 7 days ago
StatusIn development
CategoryTool
PlatformsHTML5
AuthorAurelWu
Tagshexagon, sourcecode, Turn-based

Download

Download NowName your own price

Click download now to get access to the following files:

HexGridSimplified_1_0_2.unitypackage 748 kB
HexGridSimplified_1_0_1.unitypackage 746 kB
HexGridSimplified_1_0_0.unitypackage 741 kB

Development log