In-Game Map Editor¶
The asset includes a map editor that runs inside the game, drawn over the Game view in play mode and in player builds. This page covers turning it on and off, its controls, and what it saves.
Concept¶
Every AutoTileMap carries an Auto Tile Map Gui component. It is the in-game editor, and the map requires it, so you cannot remove it. When the component is enabled, play mode shows a palette on the left of the Game view, and you can paint on the map with the mouse much as you do in the Scene view.
Use it to try a change without leaving play mode, or as a starting point if you want players to build their own maps. The demo scenes have it on.
Warning
The in-game editor also shows in player builds, where anyone playing can edit the map. A new AutoTileMap has it switched on. Turn it off before you build your game.
Turning it on and off¶
In the map inspector, open the Settings tab and use Show Map Editor On Play. The toggle is the same thing as the enabled checkbox of the Auto Tile Map Gui component, and Unity's Undo covers it.
While it is on, the Settings tab reminds you:
The in-game map editor also shows in player builds, where anyone playing can edit the map. Turn this off before building your game.
From a script, enable or disable the component:
using UnityEngine;
using CreativeSpore.RpgMapEditor;
public class MapEditorSwitch : MonoBehaviour
{
void Update()
{
// F2 shows or hides the in-game map editor.
if (RpgInput.GetKeyDown(KeyCode.F2))
{
AutoTileMapGui mapGui = AutoTileMap.Instance.GetComponent<AutoTileMapGui>();
mapGui.enabled = !mapGui.enabled;
}
}
}
The example reads the key through RpgInput, which works with both of Unity's input systems. See Input.
Disabling the component hides the palette, stops painting and hides the brush. The pathfinding demo, demo5 - PathFinding, turns the editor off on start and draws an Enable Edit Map button to bring it back.
The editor panel¶
The panel fills the left side of the Game view. From the top:
| Control | What it does |
|---|---|
Show Collisions (C) / Hide Collisions (C) |
Tints the parts of tiles that block movement red, around the camera. |
Show Minimap (M) / Hide Minimap (M) |
Shows a minimap in the bottom right corner of the Game view. |
Save |
Saves the map. See What gets saved. |
Load |
Loads a saved map. |
< |
Collapses the panel to a > button. Press > to open it again. |
L |
Opens or closes the layers menu. |
| Palette | The tiles of the chosen sub-tileset. |
| Sub-tileset buttons | Along the bottom of the panel, five to a row. Pick which sub-tileset the palette shows. |
The layers menu, under L, has two controls:
Smart Brush Enabled/Smart Brush Disabledswitches the smart brush, the same setting as theSmart Brushtoggle in thePainttab.Layer: <name>is a drop-down that picks the layer the brush paints on.
Painting and the keys keep working while the panel is collapsed.
The editor draws through the map's View Camera, from the Settings tab. If that field is empty, it uses the Main Camera and logs a warning. It adds a Camera2DController to the camera if there is none, for panning and zoom. See Camera.
Mouse and keys¶
Where the Scene view uses Shift, the in-game editor uses a modifier key that depends on where it runs:
- in the editor's play mode, the modifier is Shift,
- in a player build, it is Ctrl or Shift.
"Modifier" in the tables below means that key.
On the map¶
| Action | How |
|---|---|
| Paint | Left click, or left drag. |
| Paint one layer up | Modifier + left click or drag. |
| Scroll the view while painting | Left drag close to an edge of the map area. |
| Copy one cell | Right click. |
| Copy a rectangle | Right drag, then release. |
| Copy only the layers above the selected one | Modifier + right click or drag. |
| Pan | Middle mouse drag. |
| Zoom | Mouse wheel over the map, with no button held. |
| Undo a brush action | Modifier + Z. Hold it to keep undoing. |
| Redo a brush action | Modifier + Y. Hold it to keep redoing. |
| Select the eraser | Delete. |
| Show or hide the minimap | M |
| Show or hide collisions | C |
Painting follows the same layer rules as the Scene view, with the modifier in place of Shift. Layers explains them.
The eraser you get with Delete clears every Ground and Overlay layer of the cell you click. Hold the modifier and it clears only the layer above the selected one. Pick a tile in the palette to go back to painting.
M, C and the undo keys are read on every frame while the editor is enabled, including while your game uses those keys for something else.
In the palette¶
| Action | How |
|---|---|
| Select a tile | Left click. |
| Select a rectangle of tiles | Right drag, then release. |
| Change a tile's collision | Modifier + left click for the next type, modifier + right click for the previous one. |
While the modifier is held, the palette shows each tile's collision symbol. Collision changes go into the tileset asset, and in the editor they are still there after you stop playing. Tile Collisions lists the types.
On the minimap¶
Left click or drag on the minimap to move the camera there. A white frame marks what the camera sees. When the camera follows a character, a small yellow square marks it.
What gets saved¶
Painting with the in-game editor changes the map only while the game runs. What happens to it afterwards depends on where you are.
In the editor's play mode:
- With
Save Changes After Playingoff, which is the default, your in-game painting is gone when you stop playing. - With it on, the map is written into its Map Data asset when you stop. See Saving and Loading.
Saveasks for an XML file. If you pick one, the map is written into the Map Data asset first and then into the file. That write to the asset is permanent, whateverSave Changes After Playingsays.Loadasks for an XML file and replaces the map with it. The file's map also replaces what the Map Data asset holds in memory. It is still there after you stop playing, and the next save of the map writes it to disk, so only load files you mean to keep.
In a player build:
Savestores the map as XML inPlayerPrefs, under the keyXmlMapData. There is only one slot, so every save replaces the previous one.Loadreads that key back. If nothing was saved yet, it does nothing.- Nothing is written to the Map Data asset on disk. A build cannot change its assets.
To give players more than one save, or to store maps somewhere else, read and write the XML yourself. AutoTileMapSerializeData has GetXmlString and LoadFromXmlString, and Scripting covers the map API.