Wiki

Clone wiki

X-UniTMX / Guide

Guide

Here is a small guide on how to use X-UniTMX.

Videos

Here you can watch a playlist with all videos created to explain X-UniTMX features

Using TiledMapComponent

Using TiledMapComponent is the visual way to load a tiled map, and allow you to import the map and see how it will be on screen before running your game.

To use it, create a Tiled Game Map GameObject:

Create GameObject

Remember that its position will be the anchor point of the whole map, so position it where you want your map to be. The map is generated on -Y axis, so that Unity's (0,0) will also be the map's (0,0).

You will see a new component:

Create GameObject

Drag and drop your map asset in the object field, or select it by clicking in the field, and new options will appear:

Create GameObject

Load this on awake? when checked, runs the importer when the game is run, so you can access its TiledMap variable in runtime.

Make unique Tiles? when checked, makes the importer generate unique Tiles, even when they share common properties. (Not really useful yet)

Default Sorting Order indicates on what sorting order each tile on each layer will be by default.

Default material tile defines the default material to be used for each tile sprite. You can use one if the included materials, the default sprite material or create one.

The Import button will only show after you select a default material for the Tiles. You can use any material you want, be it a custom one or the build-in Sprite Material:

Create GameObject

Import as static Tile Map will import the map with desired configurations into Unity. This automatically clears any map already imported by this component.

Clear Tile Map excludes the imported map from the scene.

You can see above the buttons that the component will list all Layers that are on this map. You can also see all objects inside an Object Layer:

Create GameObject

You can check the Generate Colliders/Prefabs on each Object Layer to let the component automatically generate colliders from the selected layer when you hit the Import button. When enabled, a new set of options will appear:

Create GameObject

Add tile name to collider is used for Prefab loading, and adds the object name to the prefab name.

Create 2D Colliders for this layer? when checked makes the importer generate 2D colliders.

Set this layer as a trigger layer? when checked generates colliders with the Trigger attribute set.

For 3D configuration: only shows if Create 2D Colliders for this layer? is not checked.

This layer width defines the width of the 3D colliders.

This layer Z depth defines the z position of the 3D colliders.

Set this layer with inner collision? defines whether to generate polygon and polyline 3D colliders with faces facing inwards for inside collisions or outside collisions.

Back

Code only

Loading through code is really easy, and allows you to decide what to do with each object layer you've created inside Tiled. You can take a look at the MapLoader.cs or MapLoaderStreamed.cs script inside X-UniTMX Examples/OtherExampleScenes/Scripts for a simple example.

Please check the Documentation for a complete reference.

Back

Mixed

Mixing TiledMapComponent with code is also useful, as the component can easily generate for you any collider you need.

Add an component as explained above, checking the Load this on awake?. Then create a script with a TiledMapComponent public variable and reference the created component to it in the Editor.

Now, when you run the game, the map will be loaded by the component, and the TiledMap variable from the component will contain the loaded map properties and information.

Here is a small script example:

#!cs
using UnityEngine;
using System.Collections;
using X_UniTMX;

public class TestScript : MonoBehaviour {
    public TiledMapComponent TMComponent;

    void Start()
    {
        Debug.Log(TMComponent.TiledMap.ToString());
    }
}

Back

Updated