InputAPI reference
Class Players
Namespace: MicroEngine.Input
Assembly: MicroEngine.Input.dll
Guide: Input
The local players. With no setup there is one player who owns every device, so a single-player game never deals
with players at all (Game.Input is player 1’s map). For local multiplayer, pair devices explicitly: a
device paired with a player is heard only by that player, and once player 1 has a device of their own they stop
hearing the devices nobody was given.
public sealed class Players : IStateHashedInheritance
Implements
Examples
// Player 1 plays on the keyboard; anyone pressing a button on a free pad joins as the next player.Players[0].Pair(keyboard);Players.UnpairedPress += (device, e) => { if (Players.Count < 4) Players.Join(device); };var p2 = Players[1].Map.Vector("left", "right", "up", "down");Remarks
Who hears a device (OwnerOf): the player it is paired with; else player 1, while player 1 has no device of their own; else nobody (it is free to join: UnpairedPress). So keyboard and gamepad never cancel each other across players, and a pad that was never assigned does not drive anyone by accident.
Constructors
Players(InputMap)
Creates the players with player 1 using first.
public Players(InputMap first)Parameters
first InputMap
Properties
All
The players in order.
public IReadOnlyList<PlayerInput> All { get; }Property Value
Count
The number of players (at least 1).
public int Count { get; }Property Value
this[int]
The player at index (0 is player 1).
public PlayerInput this[int index] { get; }Property Value
Exceptions
There is no such player.
Methods
Add(InputMap)
Adds a player with map and no device yet (pair them with Pair).
public PlayerInput Add(InputMap map)Parameters
map InputMap
Returns
HashState(StateHasher)
Adds the players beyond player 1 (their sampled actions) and every pairing to the state hash; with one player who has no pairing it adds nothing, so a single-player game’s hash is player 1’s map alone.
public void HashState(StateHasher hash)Parameters
hash StateHasher
IsPaired(DeviceId)
Whether device is paired with any player.
public bool IsPaired(DeviceId device)Parameters
device DeviceId
Returns
Join(DeviceId, InputMap?)
Adds a player paired with device (taken from whoever had it), with their own actions:
map, or a copy of player 1’s bindings.
public PlayerInput Join(DeviceId device, InputMap? map = null)Parameters
device DeviceId
map InputMap?
Returns
OwnerOf(DeviceId)
The player who hears device: the one it is paired with; else player 1 while player 1 has no
device of their own; else null.
public PlayerInput? OwnerOf(DeviceId device)Parameters
device DeviceId
Returns
Pair(PlayerInput, DeviceId)
Pairs device with player, taking it from whoever had it.
public void Pair(PlayerInput player, DeviceId device)Parameters
player PlayerInput
device DeviceId
Remove(PlayerInput)
Removes a player other than player 1 (the next ones move up); their devices become free.
public bool Remove(PlayerInput player)Parameters
player PlayerInput
Returns
Exceptions
player is player 1.
UnpairedPress
Raised when a device nobody hears presses something (a key, a gamepad button, a touch): the moment to let that device join (Join). Raised during the frame’s input routing.
public event Action<DeviceId, InputEvent>? UnpairedPress