Class NetPlayer
- Namespace
- Unity.Multiplayer.Core
One player in a session, as every peer sees them (UM-T55): the seat they sit in (stable across a reconnect), the
connection they are on now, their name and colour, whether they host, their round-trip time to the server, and
whether they are this peer's own player. The server fills it from the connection approval payload and keeps every
peer's NetRoster in step.
public sealed class NetPlayer : IEquatable<NetPlayer>
- Inheritance
-
NetPlayer
- Implements
- Inherited Members
Remarks
Immutable: the roster hands out a new record whenever something about the player changes. Compare records by Seat, which identifies a player for as long as their seat lives; ClientId changes when they reconnect.
Constructors
NetPlayer(int, ulong, string, PlayerColor, bool, bool, int, bool)
Builds a record.
public NetPlayer(int seat, ulong clientId, string displayName, PlayerColor color, bool isHost, bool isConnected, int pingMs, bool isLocal = false)
Parameters
seatintThe seat index, 0 or more.
clientIdulongThe connection's client id now (the last one while
isConnectedis false).displayNamestringThe name everyone sees; null is stored as empty.
colorPlayerColorThe colour everyone draws the player in (already resolved: see Resolve(PlayerColor, int)).
isHostboolTrue for a listen server's own player.
isConnectedboolFalse while the player has dropped and their seat is held for a reconnect.
pingMsintRound-trip time to the server in milliseconds; UnknownPing when not measured.
isLocalboolTrue on the peer whose own player this is.
Exceptions
- ArgumentOutOfRangeException
seatis negative.
Fields
UnknownPing
PingMs before the server has measured it (and always for a dedicated server's own view of nobody).
public const int UnknownPing = -1
Field Value
Properties
ClientId
The client id of the player's connection now (of the last one while IsConnected is false).
public ulong ClientId { get; }
Property Value
Color
The colour everyone draws the player in: their own, or their seat's palette colour when they never picked one.
public PlayerColor Color { get; }
Property Value
DisplayName
The name everyone sees.
public string DisplayName { get; }
Property Value
IsConnected
False while the player has dropped and their seat is held for them to reconnect.
public bool IsConnected { get; }
Property Value
IsHost
True for a listen server's own player (the host).
public bool IsHost { get; }
Property Value
IsLocal
True on the peer whose own player this is.
public bool IsLocal { get; }
Property Value
PingMs
Round-trip time between the player and the server in milliseconds (0 for the host); UnknownPing until measured.
public int PingMs { get; }
Property Value
Seat
The seat index: who this player is for as long as their seat lives, across reconnects.
public int Seat { get; }
Property Value
Methods
Equals(object)
Determines whether the specified object is equal to the current object.
public override bool Equals(object obj)
Parameters
objobjectThe object to compare with the current object.
Returns
Equals(NetPlayer)
Indicates whether the current object is equal to another object of the same type.
public bool Equals(NetPlayer other)
Parameters
otherNetPlayerAn object to compare with this object.
Returns
FromSeat(Seat, bool, int, ulong?)
The record a server keeps for seat: the name as Clean(string, string) makes it, the
colour Resolve(PlayerColor, int)d for the seat, the host flag for a listen server's own seat (client 0),
and connected while the seat is occupied.
public static NetPlayer FromSeat(Seat seat, bool listenServer, int pingMs, ulong? localClientId)
Parameters
seatSeatThe server's seat.
listenServerboolTrue when the server is a Host (its own player sits in a seat).
pingMsintThe connection's measured round-trip time; ignored (unknown) while the seat is held.
localClientIdulong?The server's own client id when it plays (a Host), else null.
Returns
Exceptions
- ArgumentNullException
seatis null.
GetHashCode()
Serves as the default hash function.
public override int GetHashCode()
Returns
- int
A hash code for the current object.
ToString()
Returns a string that represents the current object.
public override string ToString()
Returns
- string
A string that represents the current object.
WithIdentity(string, PlayerColor)
This record with a new name and colour.
public NetPlayer WithIdentity(string displayName, PlayerColor color)
Parameters
displayNamestringcolorPlayerColor
Returns
WithLocal(bool)
This record with IsLocal set to isLocal.
public NetPlayer WithLocal(bool isLocal)
Parameters
isLocalbool