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
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
Players
Every player, by seat.
public IReadOnlyList<NetPlayer> Players { get; }
Property Value
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
updateRosterUpdate
Exceptions
- ArgumentNullException
updateis 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
seatint
Returns
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
playersIEnumerable<NetPlayer>
Returns
- RosterUpdate
The differences, as an incremental update to send to peers that already have the old roster.
Exceptions
- ArgumentNullException
playersis null.- ArgumentException
Two players share a seat.
Set(NetPlayer)
Adds or changes one player; true when anything changed.
public bool Set(NetPlayer player)
Parameters
playerNetPlayer
Returns
Exceptions
- ArgumentNullException
playeris 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
Returns
TryGetBySeat(int, out NetPlayer)
The player in seat seat.
public bool TryGetBySeat(int seat, out NetPlayer player)
Parameters
Returns
Events
Changed
Something about a seated player changed: name, colour, connection (dropped, reconnected), host, ping.
public event Action<NetPlayerChange> Changed
Event Type
Joined
A player took a seat (or this peer learned of one already seated).
public event Action<NetPlayer> Joined
Event Type
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