All objects spawned in a Unity scene are Behaviours. For local games we work with MonoBehaviours and for networking games Unity provides us NetworkBehaviours. Aside from those there aren't many abstractions where Unity supports us. I came to the conclusion that great gameplay support should be a feature that ships with the engine, finding myself abandoning projects because it doesn't.
I've worked with Unreal's Gameplay Framework which I really like and therefore want to improve Unity's gameplay layer by adding some of the things I have learned from UE4 (Unreal Engine 4). However, the existing Behaviour code base cannot be removed as it lies at the heart of the Unity Engine.
| Terminology | Description |
|---|---|
| Player | A player is a real human. Note that AIs (Bots) are not players. |
| Participant | Players and AIs can become participants when they request to join a game. Participants are taking part in the game and can interact with the world. They can have a huge imapact on the outcome of the game. A player spectator that is not able to interact with the world is not a participant for example. |
| Authority | The authority can either be a local client, a remote client (Host) or a server. A networking game has many actions that require to be authorized before they can happen. Win/Loose conditions are usually evaluated by the authority to prevent cheating for example. |
The Gameplay Framework consist of a few classes that help to structure gameplay logic.
The Game class is a Singleton that provides general interaction with the game. Controllers join the Game to become participants for example.
The GameMode only exists on the authority. The authority's Game instance contains the only GameMode across all participants. The GameMode constantly evaluates the GameState for new events that require authorization. It checks win/loose conditions as a common example.
All Games across all participants contain a single GameState that is synchronized over the network. As the name suggests, this class contains the state of the game. However, not all information about the game must be stored in this class. Only data that must be autorized is required to be available in the GameState.
The GameState contains a collection of ParticipantStates. They contain the information of a participant that requires to be authorized. All participants have a ParticipantState.
A Controller represents the will of a player or an AI. It can possess a single pawn at the time and/or become a participant by requesting a join.
A PlayerController is a controller that represents the will of a player.
An AIController is a controller that represent artificial intelligence.
An IPawn is an entity that can become possessed by a single Controller at a time. When possessed, a pawn follows the instructions of its Controller.
MonoPawns are IPawns that are used for local play. They inherit from MonoBehaviour.
NetworkPawns are IPawns that are used for network play. They inherit from NetworkBehaviour and are currently not implemented due to a focus on local play for a first version of the Gameplay Framework.
PlayerManagers are associated by PlayerControllers and handle the interaction between the game and the players. AIControllers do not require PlayerManagers because an AI doesn't require visual feedback.
A PlayerInputManager reads the input from the input devices of its player and prepares the information for its PlayerController. It does not interpret the input but is allowed to make device specific corrections such as applying a deadzone to an analogue stick.
PlayerCameraManagers are the cameramen in a game. Their main job is to position and rotate the camera correctly as well as performing any post-processing on the rendered image.
A PlayerHUDManager is responsible to display a player's HUD (Heads Up Display).
