Level Editor Sample
- Technical Info
- Static Colliders
- Baking Mesh into Collider
- Leader System
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.
|2.1.4||Jun 22, 2023||Quantum Level Editor 2.1.4 Build 259|
The project has been developed with:
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.
The sample heavily relies on commands in order to edit the map. This is because edit commands do not occur every frame.
|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 asset in this sample is the core asset that defines all editable objects in the game.
|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.
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)
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.
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).
- Handles movement while in edit mode.
- Handles movement while in play mode.
- Tracks the editor's state
- Disables and enables the right systems depending on state.
- Tracks the current leader of the editor.
- Assigns a new leader if the current left.
- Handles consuming the edit commands for the level editor.
- Handles the generation of the Map's mesh at runtime.
- Handles the spawning and despawning of players.