Code Monkey home page Code Monkey logo

hextiles's Introduction

Unity hex tile editor

A hex-based tile editor for Unity. Built for Bees Won't Exist

Imgur

Check out my YouTube playlist for some examples of it in action.

To test the hex tile system without importing into your own project, just open this Unity project and load up Example Content/Example scene.unity.

If you're interested in getting involved feel free to check out the roadmap on Trello, or submit a pull request.

Contents

Getting started

Importing into your own project

To get started, simply copy the whole Assets/Code/HexTiles folder as well as Assets/Plugins/Fluent-State-Machine.dll into your Unity project. This requires Unity 5.3 or later and has been tested on up to Unity 2018.1.0. Note that Fluent-State-Machine is only required by the editor and does not need to be included in your builds.

Basic use

Creating a tile map

To create a new hex tile map, go to the GameObject menu or right click anywhere in the Hierarchy window in Unity and select Hex tile map from the list of types of objects to create. This will add a new object named "Hex tile map" to your scene. Select it and you will see the inspector for the tile editor which should look something like this:

Default inspector

The tile map editor works in a similar way to Unity's terrain editor - you have several different tools for interacting with the map, and these are accessible from the toolbar at the top of the editor. Click the plus icon to go into tile painting mode and create some tiles.

Tile painting

Tile paint mode

This is the main tool you will use to create tile maps. Moving the cursor over the scene view will show a blue outline where tiles will appear, and you can click and drag to place tiles.

Painting a tile

Adjusting the brush size allows you to paint over a wider area.

Brush size of 4

Adjusting the offset height allows you to click and have tiles appear at an offset to the mouse position. This can be useful when you want to create ledges between tiles at multiple levels. In offset painting mode, the paint height you selects represents the position in the hex map that should be selected by the mouse cursor and is highlighted in white. The position where a new tile will actually appear when you click is stil highlighted blue, but will be offset by the height offset value from the main paint height.

Offset height

In all these cases, you only ever need to paint the tops of tiles. Side pieces will be generated automatically when two tiles at different heights are placed next to each other.

Selecting and inspecting existing tiles

Once you have some tiles in your tile map, you can use the select mode to inspect their properties. This is accessible via the button that looks like a mouse cursor.

Select mode

Click on tiles to inspect their properties. This is useful for checking the elevation of an existing tile before painting other tiles next to it, and you can individually change materials on tiles by selecting them and choosing a different material as well.

Painting materials on existing tiles

Material paint mode can be used to easily and quickly paint different materials onto existing tiles without having to place new tiles over them. Click or drag on an existing tile in the scene view to change its material.

Material paint

Clicking Apply to all tiles will apply the currently selected material to all tiles in the tile map.

Erasing tiles

Erase mode can be used to delete existing tiles. This works in a similar way to Material paint and Paint tiles modes, as you click or drag the cursor on existing tiles to remove them. Like Material paint and Paint tiles, Erase also supports multiple brush sizes for quickly removing large areas of tiles.

Erase mode

Settings and other options

More options are available in the Settings tab, accessible via the cog icon.

Settings

  • Show tile positions draws text in the scene view above each tile with its position. This was originally intended as a debugging feature but can be useful when setting up more complex tile maps. Not recommended for large maps as it kills performance in the Unity Editor.
  • Tile size sets how wide each tile should be. It is recommended to change this rather than just scaling the transform of the object containing the whole map.
  • Chunk size sets how many tiles should be combined into each mesh for performance. This can be tweaked to work out the best value for your project. Note that this does not update until you click Apply.
  • Re-generate all tile geometry deletes all tile meshes and re-generates them using saved information about their positions. This can be useful to undo changes that have been manually applied to the generated chunk objects, or reset the scene if something breaks due to an error.
  • Clear all tiles deletes all tiles in the current tile map. This is a destructive operation and should be used with caution.

Setting up materials for use with hex tile maps.

See Assets/Example Content/Textures for some examples for how to set up a texture for use with a tile map. Tops of tiles and side pieces are stored on the same texture atlas so that a map can be drawn in a single batch, with the top pieces taking up the top half of the texture and the side pieces taking up the lower half. See the Test tileset image for reference:

Test tileset

The area for the top pieces contains 4x3 tiles, which are numbered in the test tileset. Note that these are slightly stretched vertically, which is necessary to make them fit into a square texture.

The area for the side pieces is split into an upper and a lower half. The top half is only used once and the lower half is looped forever. This is useful for times when you might want the texture from the top to spill over onto the sides for a short while (for example, the grass texture in OutDoorTileset.png). Each hex has 6 sides and these are split up evenly across the texture.

Tips and best practices

  • Selecting a tile map overrides the default Unity left-click behaviour so you won't be able to click on other objects to select them after selecting a hex tile map. This is intentional, and you can go back to selecting objects normally by clicking on something else in the scene hierarchy window.
  • In some cases you may want to modify the tiles that have been generated by this plugin. In those cases it is best to remove the HexTileMap script from the parent object so that no one later on accidentally paints more tiles and causes that chunk to be re-generated, removing any changes that may have been made since then.
  • It is often useful to have several different hex tile maps in the same scene for tiles that are meant to be independent.

hextiles's People

Contributors

harrisonshort avatar rorydungan avatar supcher 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  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

hextiles's Issues

Sides of Tiles appear as if they are shadowed regardless of lighting settings

I have a Hex Tiles map set up in my project running an out of the box URP shader for its rendering settings. Regardless of what material I place on the tiles themselves, the sides appear as if they are always shadowed. I have tried baking lighting with the global lighting settings and if I set a high enough intensity it's clear that the textures themselves are mapped correctly, they're just... very dark. At a global intensity of 1 they are too dark to see.
sideways light

If I turn off "Scene Lighting" the problem "fixes" itself, but inside the game that uses a "sun" (aka a directional light that rotates around the map and not baked skybox/environment lighting) the sides go back to being almost entirely matte black regardless.

no scene light

Even if I turn off the directional light and used baked in lighting, it's still very very dark.
shadow

HexTileData reinstantiated for every Tile each time HexTileMap.TryGetTile() is called.

Hi Rory, your editor was so far very usefull for me, thanks!

However, I wanted to have some additional meta data stored within each tile, so I added new attribute to HexTileData class, let's call it Model. Now, in my GameScript, I want to be able to read the Model info for any particular tile. So I call the HexTileMap.TryGetTile() with some HexCoords and I see, that the HexTileData is being instantiated for each call to TryGetTile(), and internaly to HexTileMap.Tiles.get().

Before I dig deeper and try to solve this on my own, is this an intention, should I be using the HexTileData in different way or could you please recommend me a better way to store the tile meta data?

Can you use this in a strategy world map?

Hello,

Now I already saw in the other issue how you can put sprites and other game objects onto another tile with HexTileMap.QuantizePositionToHexGrid so that certainly answers one of my needs but I am creating a game like NEO Scavenger but any of the maps in the Civ games work pretty much in the same way.
My question is would I be able to use this if my player needs to move with mouse/touch events? Would i need to add something myself in order for the hex grid map to work with a mouse/touch?
Is there an implementation for obstacles already?
And my last question: How easy would be to add special case models for the map i.e. if I want to create a coastline near bodies of water(This can be seen in the modern Civ games too)?

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.