7.9 KiB
uid |
---|
input-system-player-input-manager |
The Player Input Manager component
NOTE: The Input System package comes with a sample called
Simple Multiplayer
which you can install from the package manager UI in the Unity editor. The sample demonstrates how to usePlayerInputManager
to set up a simple local multiplayer scenario.
The Player Input
system facilitates setting up local multiplayer games, where multiple players share a single screen and multiple controllers. You can set this up using the PlayerInputManager
component, which automatically manages the creation and lifetime of PlayerInput
instances as players join and leave the game.
Property | Description |
---|---|
Notification Behavior |
How the PlayerInputManager component notifies game code about changes to the connected players. This works the same way as for the PlayerInput component. |
Join Behavior |
Determines the mechanism by which players can join when joining is enabled. See documentation on join behaviors. |
Player Prefab |
A prefab that represents a player in the game. The PlayerInputManager component creates an instance of this prefab whenever a new player joins. This prefab must have one PlayerInput component in its hierarchy. |
Joining Enabled By Default |
While this is enabled, new players can join via the mechanism determined by Join Behavior . |
Limit Number of Players |
Enable this if you want to limit the number of players who can join the game. |
Max Player Count (Only shown when Limit number of Players is enabled.) |
The maximum number of players allowed to join the game. |
Enable Split-Screen |
If enabled, each player is automatically assigned a portion of the available screen area. See documentation on split-screen multiplayer. |
Join behaviors
You can use the Join Behavior
property in the Inspector to determine how a PlayerInputManager
component decides when to add new players to the game. The following options are available to choose the specific mechanism that PlayerInputManager
employs.
Behavior | Description |
---|---|
Join Players When Button IsPressed |
Listen for button presses on Devices that are not paired to any player. If a player presses a button and joining is allowed, join the new player using the Device they pressed the button on. |
Join Players When Join Action Is Triggered |
Similar to Join Players When Button IsPressed , but this only joins a player if the control they triggered matches a specific action you define. For example, you can set up players to join when pressing a specific gamepad button. |
Join Players Manually |
Don't join players automatically. Call JoinPlayer explicitly to join new players. Alternatively, create GameObjects with PlayerInput components directly and the Input System will automatically join them. |
Split-screen
If you enable the Split-Screen
option, the PlayerInputManager
automatically splits the available screen space between the active players. For this to work, you must set the Camera
property on the PlayerInput
prefab. The PlayerInputManager
then automatically resizes and repositions each camera instance to let each player have their own part of the screen.
If you enable the Split-Screen
option, you can configure the following additional properties in the Inspector:
Property | Description |
---|---|
Maintain Aspect Ratio |
A false value enables the game to produce screen areas that have an aspect ratio different from the screen resolution when subdividing the screen. |
Set Fixed Number |
If this value is greater than zero, the PlayerInputManager always splits the screen into a fixed number of rectangles, regardless of the actual number of players. |
Screen Rectangle |
The normalized screen rectangle available for allocating player split-screens into. |
By default, any player in the game can interact with any UI elements. However, in split-screen setups, your game can have screen-space UIs that are restricted to just one specific camera. See the UI Input section on the Player Input component page on how to set this up using the Player Input component, InputSystemUIInputModule
and MultiplayerEventSystem
components.
PlayerInputManager
notifications
PlayerInputManager
sends notifications when something notable happens with the current player setup. These notifications are delivered according to the Notification Behavior
property, in the same way as for PlayerInput
.
Your game can listen to the following notifications:
Notification | Description |
---|---|
PlayerJoinedMessage |
A new player joined the game. Passes the [PlayerInput ](PlayerInput.mdPlayerInputManager sends a Player Joined notification for each of these. |
PlayerLeftMessage |
A player left the game. Passes the PlayerInput instance of the player who left. |