Photon Unity Networking: PhotonPlayer Class Reference

Photon Unity Networking

Summarizes a "player" within a room, identified (in that room) by actorID. More...

Inherits IComparable< PhotonPlayer >, IComparable< int >, IEquatable< PhotonPlayer >, and IEquatable< int >.

Public Member Functions

 PhotonPlayer (bool isLocal, int actorID, string name)
 Creates a PhotonPlayer instance. More...
 
override bool Equals (object p)
 Makes PhotonPlayer comparable More...
 
override int GetHashCode ()
 
void SetCustomProperties (Hashtable propertiesToSet, Hashtable expectedValues=null, bool webForward=false)
 Updates the this player's Custom Properties with new/updated key-values. More...
 
PhotonPlayer Get (int id)
 
PhotonPlayer GetNext ()
 
PhotonPlayer GetNextFor (PhotonPlayer currentPlayer)
 
PhotonPlayer GetNextFor (int currentPlayerId)
 
int CompareTo (PhotonPlayer other)
 
int CompareTo (int other)
 
bool Equals (PhotonPlayer other)
 
bool Equals (int other)
 
override string ToString ()
 Brief summary string of the PhotonPlayer. Includes name or player.ID and if it's the Master Client. More...
 
string ToStringFull ()
 String summary of the PhotonPlayer: player.ID, name and all custom properties of this user. More...
 

Static Public Member Functions

static PhotonPlayer Find (int ID)
 Try to get a specific player by id. More...
 

Public Attributes

readonly bool IsLocal = false
 Only one player is controlled by each client. Others are not local. More...
 
object TagObject
 Can be used to store a reference that's useful to know "by player". More...
 

Properties

int ID [get]
 This player's actorID More...
 
string NickName [get, set]
 Nickname of this player. More...
 
string UserId [get, set]
 UserId of the player, available when the room got created with RoomOptions.PublishUserId = true. More...
 
bool IsMasterClient [get]
 True if this player is the Master Client of the current room. More...
 
bool IsInactive [get, set]
 Players might be inactive in a room when PlayerTTL for a room is > 0. If true, the player is not getting events from this room (now) but can return later. More...
 
Hashtable CustomProperties [get, set]
 Read-only cache for custom properties of player. Set via PhotonPlayer.SetCustomProperties. More...
 
Hashtable AllProperties [get]
 Creates a Hashtable with all properties (custom and "well known" ones). More...
 
string name [get, set]
 
string userId [get, set]
 
bool isLocal [get]
 
bool isMasterClient [get]
 
bool isInactive [get, set]
 
Hashtable customProperties [get, set]
 
Hashtable allProperties [get]
 

Detailed Description

Summarizes a "player" within a room, identified (in that room) by actorID.

Each player has an actorId (or ID), valid for that room. It's -1 until it's assigned by server. Each client can set it's player's custom properties with SetCustomProperties, even before being in a room. They are synced when joining a room.

Constructor & Destructor Documentation

PhotonPlayer.PhotonPlayer ( bool  isLocal,
int  actorID,
string  name 
)

Creates a PhotonPlayer instance.

Parameters
isLocalIf this is the local peer's player (or a remote one).
actorIDID or ActorNumber of this player in the current room (a shortcut to identify each player in room)
nameName of the player (a "well known property").

Member Function Documentation

int PhotonPlayer.CompareTo ( PhotonPlayer  other)
int PhotonPlayer.CompareTo ( int  other)
override bool PhotonPlayer.Equals ( object  p)

Makes PhotonPlayer comparable

bool PhotonPlayer.Equals ( PhotonPlayer  other)
bool PhotonPlayer.Equals ( int  other)
static PhotonPlayer PhotonPlayer.Find ( int  ID)
static

Try to get a specific player by id.

Parameters
IDActorID
Returns
The player with matching actorID or null, if the actorID is not in use.
PhotonPlayer PhotonPlayer.Get ( int  id)
override int PhotonPlayer.GetHashCode ( )
PhotonPlayer PhotonPlayer.GetNext ( )
PhotonPlayer PhotonPlayer.GetNextFor ( PhotonPlayer  currentPlayer)
PhotonPlayer PhotonPlayer.GetNextFor ( int  currentPlayerId)
void PhotonPlayer.SetCustomProperties ( Hashtable  propertiesToSet,
Hashtable  expectedValues = null,
bool  webForward = false 
)

Updates the this player's Custom Properties with new/updated key-values.

Custom Properties are a key-value set (Hashtable) which is available to all players in a room. They can relate to the room or individual players and are useful when only the current value of something is of interest. For example: The map of a room. All keys must be strings.

The Room and the PhotonPlayer class both have SetCustomProperties methods. Also, both classes offer access to current key-values by: customProperties.

Always use SetCustomProperties to change values. To reduce network traffic, set only values that actually changed. New properties are added, existing values are updated. Other values will not be changed, so only provide values that changed or are new.

To delete a named (custom) property of this room, use null as value.

Locally, SetCustomProperties will update it's cache without delay. Other clients are updated through Photon (the server) with a fitting operation.

Check and Swap

SetCustomProperties have the option to do a server-side Check-And-Swap (CAS): Values only get updated if the expected values are correct. The expectedValues can be different key/values than the propertiesToSet. So you can check some key and set another key's value (if the check succeeds).

If the client's knowledge of properties is wrong or outdated, it can't set values with CAS. This can be useful to keep players from concurrently setting values. For example: If all players try to pickup some card or item, only one should get it. With CAS, only the first SetProperties gets executed server-side and any other (sent at the same time) fails.

The server will broadcast successfully changed values and the local "cache" of customProperties only gets updated after a roundtrip (if anything changed).

You can do a "webForward": Photon will send the changed properties to a WebHook defined for your application.

OfflineMode

While PhotonNetwork.offlineMode is true, the expectedValues and webForward parameters are ignored. In OfflineMode, the local customProperties values are immediately updated (without the roundtrip).

Parameters
propertiesToSetThe new properties to be set.
expectedValuesAt least one property key/value set to check server-side. Key and value must be correct. Ignored in OfflineMode.
webForwardSet to true, to forward the set properties to a WebHook, defined for this app (in Dashboard). Ignored in OfflineMode.
override string PhotonPlayer.ToString ( )

Brief summary string of the PhotonPlayer. Includes name or player.ID and if it's the Master Client.

string PhotonPlayer.ToStringFull ( )

String summary of the PhotonPlayer: player.ID, name and all custom properties of this user.

Use with care and not every frame! Converts the customProperties to a String on every single call.

Member Data Documentation

readonly bool PhotonPlayer.IsLocal = false

Only one player is controlled by each client. Others are not local.

object PhotonPlayer.TagObject

Can be used to store a reference that's useful to know "by player".

Example: Set a player's character as Tag by assigning the GameObject on Instantiate.

Property Documentation

Hashtable PhotonPlayer.AllProperties
get

Creates a Hashtable with all properties (custom and "well known" ones).

If used more often, this should be cached.

Hashtable PhotonPlayer.allProperties
get
Hashtable PhotonPlayer.CustomProperties
getset

Read-only cache for custom properties of player. Set via PhotonPlayer.SetCustomProperties.

Don't modify the content of this Hashtable. Use SetCustomProperties and the properties of this class to modify values. When you use those, the client will sync values with the server.

SetCustomProperties

Hashtable PhotonPlayer.customProperties
getset
int PhotonPlayer.ID
get

This player's actorID

bool PhotonPlayer.IsInactive
getset

Players might be inactive in a room when PlayerTTL for a room is > 0. If true, the player is not getting events from this room (now) but can return later.

bool PhotonPlayer.isInactive
getset
bool PhotonPlayer.isLocal
get
bool PhotonPlayer.IsMasterClient
get

True if this player is the Master Client of the current room.

See also: PhotonNetwork.masterClient.

bool PhotonPlayer.isMasterClient
get
string PhotonPlayer.name
getset
string PhotonPlayer.NickName
getset

Nickname of this player.

Set the PhotonNetwork.playerName to make the name synchronized in a room.

string PhotonPlayer.UserId
getset

UserId of the player, available when the room got created with RoomOptions.PublishUserId = true.

Useful for PhotonNetwork.FindFriends and blocking slots in a room for expected players (e.g. in PhotonNetwork.CreateRoom).

string PhotonPlayer.userId
getset
Online Documentation  -  Dashboard  -  Support Forum Exit Games GmbH