Level Editor Sample
Introduction
A level editor in a game is a very valuable tool that can allow a player or the developer to create, modify and share levels, providing endless possibilities for gameplay and replayability. This sample provides a solid foundation for you to create your own level editor for your Quantum game.
Download
Version | Release Date | Download | |
---|---|---|---|
2.1.4 | Jun 22, 2023 | Quantum Level Editor 2.1.4 Build 259 |
Technical Info
The project has been developed with:
- Unity
2021.3.5f1
- Quantum
2.1.4
Static Colliders
While using pure entities with physics colliders to represent map objects would be convenient, their dynamic colliders would not be as efficient as using their static counterpart. Because of this, we opt to use static colliders and to modify the Map
asset at runtime.
Commands
The sample heavily relies on commands in order to edit the map. This is because edit commands do not occur every frame.
Command | Description |
---|---|
ChangePermissionCommand | Edits the permissions of a player. Only the leader can execute this. |
ChangeStateCommand | Toggles the editor between play and edit mode. |
UndoCommand | Reverts the previous user action. |
ResetPlayerCommand | Resets the player's character and camera to the center of the map. |
ClearMapCommand | Clears the map. |
NavMeshMoveCommand | Sets a new target for the pathfinding agent while in play mode. |
SpawnObjectCommand | Creates a new MapObject |
DeleteObjectCommand | Destroys a given MapObject |
MapObject
The MapObject
asset in this sample is the core asset that defines all editable objects in the game.
Field | Description |
---|---|
VisualPrototypeRef | The `EntityPrototype` asset ref to the visual entity. |
NavMeshSurface | Whether or not the object is traversible via pathfinding. |
StaticVertices | The vertices of this object's static mesh. |
Triangles | The triangle indices of this object's static mesh. |
The visual prototype is the entity that is spawned to represent the created static collider.
Baking Mesh into Collider
To bake a map object's mesh, populate the 'Source' field in the Unity inspector inside your map object, then hit the "Bake Mesh" button.
Navigation
This sample also includes pathfinding, via runtime NavMesh
creation. A navmesh is computed inside unity and sent via the asset injection addon. (see: Asset Injection)
Leader System
In a level editor setting, you may want certain players to only be able to view the map, but not modify it. The leader system allows the current leader to revoke and grant edit permissions at runtime. If the leader leaves, a new one is assigned. By default the leader is always the first client in the room.
Permissions
By default, for the sake of the sample, every client has full permissions. Full permissions means that the user can edit the map and change the game state as they please (enter, exit playmode etc).
Systems
- EditModeMoveSystem
- Handles movement while in edit mode.
- PlayModeMoveSystem
- Handles movement while in play mode.
- LevelEditorStateSystem
- Tracks the editor's state
- Disables and enables the right systems depending on state.
- MapLeaderSystem
- Tracks the current leader of the editor.
- Assigns a new leader if the current left.
- MapSpawningSystem
- Handles consuming the edit commands for the level editor.
- MapStaticMeshSystem
- Handles the generation of the Map's mesh at runtime.
- PlayerObjectSystem
- Handles the spawning and despawning of players.