Class PlayerRoster

Namespace
Unity.Multiplayer.Core

The players in a session, by seat (UM-T55): the engine-free model behind the adapter's NetRoster. The server builds the whole list from its seats with Replace(IEnumerable<NetPlayer>), which raises the events and returns the RosterUpdate to send; each client Apply(RosterUpdate)s the updates it receives.

public sealed class PlayerRoster
Inheritance
PlayerRoster
Inherited Members

Remarks

Not thread-safe; the adapter uses it from Unity's main thread. Handlers run synchronously, in seat order.

Properties

Count

How many seats are taken (held seats of dropped players included).

public int Count { get; }

Property Value

int

Local

This peer's own player; null on a dedicated server, before the roster arrives, or after the session ends.

public NetPlayer Local { get; }

Property Value

NetPlayer

Players

Every player, by seat.

public IReadOnlyList<NetPlayer> Players { get; }

Property Value

IReadOnlyList<NetPlayer>

Methods

Apply(RosterUpdate)

Applies an update a server sent: a full one replaces the roster, an incremental one adds, changes and removes.

public void Apply(RosterUpdate update)

Parameters

update RosterUpdate

Exceptions

ArgumentNullException

update is null.

Clear()

Empties the roster (the session ended), raising Left for each player.

public void Clear()

Remove(int)

Removes the player in seat seat; true when there was one.

public bool Remove(int seat)

Parameters

seat int

Returns

bool

Replace(IEnumerable<NetPlayer>)

Makes the roster exactly players (one per seat), raising Left, Joined and Changed for the differences.

public RosterUpdate Replace(IEnumerable<NetPlayer> players)

Parameters

players IEnumerable<NetPlayer>

Returns

RosterUpdate

The differences, as an incremental update to send to peers that already have the old roster.

Exceptions

ArgumentNullException

players is null.

ArgumentException

Two players share a seat.

Set(NetPlayer)

Adds or changes one player; true when anything changed.

public bool Set(NetPlayer player)

Parameters

player NetPlayer

Returns

bool

Exceptions

ArgumentNullException

player is null.

TryGet(ulong, out NetPlayer)

The player on connection clientId (a connected one first, else a held seat last on it).

public bool TryGet(ulong clientId, out NetPlayer player)

Parameters

clientId ulong
player NetPlayer

Returns

bool

TryGetBySeat(int, out NetPlayer)

The player in seat seat.

public bool TryGetBySeat(int seat, out NetPlayer player)

Parameters

seat int
player NetPlayer

Returns

bool

Events

Changed

Something about a seated player changed: name, colour, connection (dropped, reconnected), host, ping.

public event Action<NetPlayerChange> Changed

Event Type

Action<NetPlayerChange>

Joined

A player took a seat (or this peer learned of one already seated).

public event Action<NetPlayer> Joined

Event Type

Action<NetPlayer>

Left

A player's seat was freed (they left for good, were kicked, their reconnect window ran out) or the session ended.

public event Action<NetPlayer> Left

Event Type

Action<NetPlayer>