Class PlayerIdentity
- Namespace
- Unity.Multiplayer.Core
Who this player is, as far as the server knows: the stable player token that gets a reconnecting player its seat back, plus the name and colour it plays as. A client sends it inside its ConnectionPayload.
public sealed class PlayerIdentity
- Inheritance
-
PlayerIdentity
- Inherited Members
Remarks
Immutable. Keep the token across launches (for example in local storage) so a player who drops, crashes or restarts the game gets the same seat back within the server's reconnect grace window.
Constructors
PlayerIdentity(string, string, PlayerColor)
Builds an identity; the fields follow ConnectionPayload's rules.
public PlayerIdentity(string playerToken, string displayName, PlayerColor color)
Parameters
playerTokenstringdisplayNamestringcolorPlayerColor
Exceptions
- ArgumentException
The token or display name is invalid (see Validate()).
Fields
DefaultDisplayName
The display name CreateNew(string, PlayerColor?) uses when none is given.
public const string DefaultDisplayName = "Player"
Field Value
Properties
Color
The colour the player picked.
public PlayerColor Color { get; }
Property Value
DisplayName
The name other players see.
public string DisplayName { get; }
Property Value
PlayerToken
The opaque, stable identifier for this player.
public string PlayerToken { get; }
Property Value
Methods
CreateNew(string, PlayerColor?)
A new identity with a fresh random token (32 hex digits).
public static PlayerIdentity CreateNew(string displayName = null, PlayerColor? color = null)
Parameters
displayNamestringThe name other players see; DefaultDisplayName when null or blank.
colorPlayerColor?The colour; white when null.
Returns
NewToken()
A fresh random player token: 32 lower-case hex digits.
public static string NewToken()
Returns
ToPayload(string, ProtocolHash)
The connection payload this player sends to a server of gameVersion.
public ConnectionPayload ToPayload(string gameVersion, ProtocolHash protocolHash)
Parameters
gameVersionstringprotocolHashProtocolHash
Returns
ToPayload(string, ProtocolHash, string)
This identity as the connection payload a client sends, with the server password it was given.
public ConnectionPayload ToPayload(string gameVersion, ProtocolHash protocolHash, string password)
Parameters
gameVersionstringThe client's game version.
protocolHashProtocolHashThe client's protocol hash.
passwordstringThe server password; null or empty for none.
Returns
ToString()
Returns a string that represents the current object.
public override string ToString()
Returns
- string
A string that represents the current object.
With(string, PlayerColor?)
The same player under another name or colour (the token is kept).
public PlayerIdentity With(string displayName = null, PlayerColor? color = null)
Parameters
displayNamestringcolorPlayerColor?