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

playerToken string
displayName string
color PlayerColor

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

string

Properties

Color

The colour the player picked.

public PlayerColor Color { get; }

Property Value

PlayerColor

DisplayName

The name other players see.

public string DisplayName { get; }

Property Value

string

PlayerToken

The opaque, stable identifier for this player.

public string PlayerToken { get; }

Property Value

string

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

displayName string

The name other players see; DefaultDisplayName when null or blank.

color PlayerColor?

The colour; white when null.

Returns

PlayerIdentity

NewToken()

A fresh random player token: 32 lower-case hex digits.

public static string NewToken()

Returns

string

ToPayload(string, ProtocolHash)

The connection payload this player sends to a server of gameVersion.

public ConnectionPayload ToPayload(string gameVersion, ProtocolHash protocolHash)

Parameters

gameVersion string
protocolHash ProtocolHash

Returns

ConnectionPayload

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

gameVersion string

The client's game version.

protocolHash ProtocolHash

The client's protocol hash.

password string

The server password; null or empty for none.

Returns

ConnectionPayload

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

displayName string
color PlayerColor?

Returns

PlayerIdentity