Skip to content

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.

C#
public sealed class Players : IStateHashed

Inheritance

object ← Players

Implements

IStateHashed

Examples

C#
// 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.

C#
public Players(InputMap first)

Parameters

first InputMap

Properties

All

The players in order.

C#
public IReadOnlyList<PlayerInput> All { get; }

Property Value

IReadOnlyList<PlayerInput>

Count

The number of players (at least 1).

C#
public int Count { get; }

Property Value

int

this[int]

The player at index (0 is player 1).

C#
public PlayerInput this[int index] { get; }

Property Value

PlayerInput

Exceptions

ArgumentOutOfRangeException

There is no such player.

Methods

Add(InputMap)

Adds a player with map and no device yet (pair them with Pair).

C#
public PlayerInput Add(InputMap map)

Parameters

map InputMap

Returns

PlayerInput

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.

C#
public void HashState(StateHasher hash)

Parameters

hash StateHasher

IsPaired(DeviceId)

Whether device is paired with any player.

C#
public bool IsPaired(DeviceId device)

Parameters

device DeviceId

Returns

bool

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.

C#
public PlayerInput Join(DeviceId device, InputMap? map = null)

Parameters

device DeviceId

map InputMap?

Returns

PlayerInput

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.

C#
public PlayerInput? OwnerOf(DeviceId device)

Parameters

device DeviceId

Returns

PlayerInput?

Pair(PlayerInput, DeviceId)

Pairs device with player, taking it from whoever had it.

C#
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.

C#
public bool Remove(PlayerInput player)

Parameters

player PlayerInput

Returns

bool

Exceptions

ArgumentException

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.

C#
public event Action<DeviceId, InputEvent>? UnpairedPress

Event Type

Action<DeviceId, InputEvent>?