I’ve been working on an upcoming Tiled2Unity tutorial to help people that are trying to get information for a specific tile at a specific location at runtime.
For instance, say your working on a game like Advance Wars where the game logic has a dependency on the type of tiles that make up a level (grass, trees, mountains, etc.)
Achieving this with Tiled2Unity is done through having all the different tile types (with collisions) on separate Tile Layers and using a raycast against their generated
PolygonCollider2D objects. This gives you the ability to know which “type” of tile you are “using”. Further, I use Tiled’s Automapping capabilities so that I only manage one Tile Layer and let the Automapper take care of the rest. (More on that in the upcoming tutorial.)
The idea isn’t that difficult but the previewer in Tiled2Unity was a huge disappointment for a map with multiple collider layers. Here is a screenshot of it in action …
What a mess. There’s six different kinds of polygons in that picture (plus a bunch of rectangles to indicate sprite location) but it’s impossible to tell where they are.
So, the latest versions of Tiled2Unity has previewer options …
… that allow you to select which layers are being shown in the previewer. They also allow you to choose a color for the collision polygons on a per-layer basis:
(BTW, the color settings are saved to file so that you don’t have to reset them every time you use the previewer. Other maps that use similar layer names will inherit these colors while previewing.)
Now we can get a much better sense of how polygon colliders are going to be created in Unity.
We can take this one step further. The collision layers in this example (CollisionWood, CollisionMountain, etc.) make use of the
unity:collisionOnly custom property. This tells Tiled2Unity that we only want collision polygons for these layers and ignores the mesh that would normally go with them.
Given this we can preview only these layers and get an even better sense of the colliders that will be created by Tiled2Unity. Notice how the blue water polygon stands out. (And yes, that’s one polygon in Unity.)
What I like most about Tiled2Unity (and why I made it available to the public as a side-effect of my Mega Man game) is that all of this information for the map is going to be represented by just a few polygons – and not some O(N2) number of per-tile objects.
And now, it’s easier to see that in the previewer. Happy developing.