Level Editor Toolbar and Tools
Advanced25-35 minutesWindowsVisual Studio
The level editor provides six major tool categories, each managed by a dedicated MonoBehaviour on the editor camera GameObject. The toolbar — rendered by EditorDashboardUI and its companion panel UIs — switches between these categories, toggling the active state of each tool system. Tools operate through raycasting from the editor camera (EditorInteract) and modify the level world in real time.
Source code location: Unturned/Edit/EditorObjects.cs, EditorSpawns.cs, EditorNavigation.cs, UI/Edit/EditorLevelUI.cs, EditorTerrainUI.cs, EditorEnvironmentUI.cs, EditorDashboardUI.cs
Tool Mode Lifecycle
Each tool system follows a consistent pattern:
csharp
// Tool activation
public static bool isBuilding { get; set; }
// When deactivated:
set { _isBuilding = value; if (!isBuilding) clearSelection(); }When a tool is activated, its UI panel opens and the editor camera enters a mode-specific interaction state. When deactivated, selections are cleared and transient visual elements (spawn markers, navmesh gizmos) are hidden.
Terrain Heightmap Editing
EditorTerrainHeightUI provides heightmap manipulation. The terrain system uses Unity's TerrainData for height storage, with brush-based editing:
Height tools use EPaintMode for additive, subtractive, flatten, and smooth operations. Brush size and intensity are configurable through the UI. Height changes modify the terrain's heightmap array directly and trigger TerrainData.SyncHeightmap().
Material painting (EditorTerrainMaterialsUI) applies terrain textures (splatmaps) using an alpha-blend brush system. Each terrain layer (grass, dirt, sand, etc.) has an associated alpha map in the splatmap texture array.
Detail/foliage editing (EditorTerrainDetailsUI) places and removes detail meshes (grass, flowers, rocks) using the same brush paradigm. Detail density is controlled per-layer.
Tile editing (EditorTerrainTilesUI) manages terrain tile configuration, including tile material assignments and tile-based terrain generation.
Object Placement Tools
EditorObjects manages the object placement and manipulation system. It maintains:
- Selection set —
List<EditorSelection>tracking currently selected transforms - Asset selection —
selectedObjectAssetandselectedItemAssetfor placement - Transform handles —
TransformHandlesfor interactive move/rotate/scale
Selection and Manipulation
Objects can be selected by clicking (single) or dragging a selection rectangle. The selection rectangle is tracked through dragStartViewportPoint, dragEndViewportPoint and the DragStarted/DragStopped delegates:
csharp
public static DragStarted onDragStarted;
public static DragStopped onDragStopped;The selection supports multi-object operations via EnumerateSelectedGameObjects(). Snapping is configurable through snapTransform (position) and snapRotation (angle) static fields.
Drag and Coordinate Modes
EditorDrag handles the actual transform manipulation during mouse drag. The system supports:
- Drag modes (
EDragMode) — None, Translate, Rotate, Scale - Drag coordinates (
EDragCoordinate) — Global, Local, Pivot - Drag types (
EDragType) — bounding-box-based and pivot-based
EDragType controls whether transform handles operate on the selection's bounding box center or on individual pivot points.
Decal System
EditorObjects maintains a List<Decal> for temporary visual markers on placed or selected objects. Decals are projected onto surfaces using the EditorInteract.worldHit raycast result.
Spawn Point Tools
EditorSpawns manages spawn point placement for six categories:
| Category | Spawn Transform | UI Panel |
|---|---|---|
| Items | itemSpawn | EditorSpawnsItemsUI |
| Players | playerSpawn / playerSpawnAlt | EditorSpawnsPlayersUI |
| Zombies | zombieSpawn | EditorSpawnsZombiesUI |
| Vehicles | vehicleSpawn | EditorSpawnsVehiclesUI |
| Animals | animalSpawn | EditorSpawnsAnimalsUI |
| Remove | remove | (integrated removal tool) |
Spawn Modes
The ESpawnMode enum controls whether the tool is adding, removing, or selecting spawns. When isSpawning is true, the active spawn marker is visible and follows the cursor. The selectedAlt property toggles between primary and alternate player spawn visuals:
csharp
public static bool selectedAlt
{
set
{
_selectedAlt = value;
playerSpawn.gameObject.SetActive(spawnMode == ESpawnMode.ADD_PLAYER && isSpawning && !selectedAlt);
playerSpawnAlt.gameObject.SetActive(spawnMode == ESpawnMode.ADD_PLAYER && isSpawning && selectedAlt);
}
}Spawn points are stored by type (item, player, zombie, vehicle, animal) and sub-type (selectedItem, selectedZombie, selectedVehicle, selectedAnimal). The removal tool has configurable MIN_REMOVE_SIZE (2) and MAX_REMOVE_SIZE (30) for area-based removal.
Navmesh Tools
EditorNavigation provides pathfinding flag (navmesh control point) editing:
csharp
public static bool isPathfinding { get; set; }When active, a marker transform follows the cursor on terrain surfaces. Players can:
- Click to select a nearby flag (highlighted in red)
- Delete/Backspace to remove the selected flag
- Tool_2 key to add a new flag at the cursor position
csharp
if (InputEx.GetKeyDown(ControlsSettings.tool_2))
{
Transform newFlag = new GameObject("Flag").transform;
// Position and parent the new flag
LevelNavigation.addFlag(newFlag);
}The Flag object is retrieved through LevelNavigation.getFlag(selection) and passed to EditorEnvironmentNavigationUI.updateSelection(flag) for property editing.
Environment Tools
EditorEnvironmentUI groups four environment editing subsystems:
| Subsystem | Editor Script | Function |
|---|---|---|
| Lighting | EditorEnvironmentLightingUI | Time of day, fog, shadow, and weather settings |
| Navigation | EditorEnvironmentNavigationUI | Navmesh flag properties, connections |
| Roads | EditorEnvironmentRoadsUI | Road path editing, junction placement, material assignment |
| Nodes | EditorEnvironmentNodesUI | Location/devkit node placement and configuration |
The environment tools modify LevelLighting, LevelNavigation, LevelRoads, and LevelNodes respectively. Changes are applied through the respective manager singletons and are persisted through the level save system.
Editor Camera and Interaction
The editor camera (EditorInteract) provides the raycasting foundation for all tools:
EditorInteract.worldHit— the current world-space raycast hitEditorInteract.isFlying— whether the editor camera is in fly mode (during fly mode, tool input is suppressed)Glazier.Get().ShouldGameProcessInput— prevents tool interaction when the cursor is over UI elements
When a tool is active and the camera is not in fly mode, mouse clicks and key presses are translated into tool-specific operations through the active MonoBehaviour's Update() method.
