Photon Unity Networking v1.101

Public Member Functions | Static Public Member Functions | Public Attributes | Properties | List of all members
PhotonPlayer Class Reference

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.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

◆ CompareTo() [1/2]

int PhotonPlayer.CompareTo ( int  other)

◆ CompareTo() [2/2]

int PhotonPlayer.CompareTo ( PhotonPlayer  other)

◆ Equals() [1/3]

bool PhotonPlayer.Equals ( int  other)

◆ Equals() [2/3]

override bool PhotonPlayer.Equals ( object  p)

Makes PhotonPlayer comparable

◆ Equals() [3/3]

bool PhotonPlayer.Equals ( PhotonPlayer  other)

◆ Find()

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.

◆ Get()

PhotonPlayer PhotonPlayer.Get ( int  id)

◆ GetHashCode()

override int PhotonPlayer.GetHashCode ( )

◆ GetNext()

PhotonPlayer PhotonPlayer.GetNext ( )

◆ GetNextFor() [1/2]

PhotonPlayer PhotonPlayer.GetNextFor ( int  currentPlayerId)

◆ GetNextFor() [2/2]

PhotonPlayer PhotonPlayer.GetNextFor ( PhotonPlayer  currentPlayer)

◆ SetCustomProperties()

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.

◆ ToString()

override string PhotonPlayer.ToString ( )

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

◆ ToStringFull()

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

◆ IsLocal

readonly bool PhotonPlayer.IsLocal = false

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

◆ TagObject

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

◆ AllProperties

Hashtable PhotonPlayer.AllProperties
get

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

If used more often, this should be cached.

◆ allProperties

Hashtable PhotonPlayer.allProperties
get

◆ CustomProperties

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

◆ customProperties

Hashtable PhotonPlayer.customProperties
getset

◆ ID

int PhotonPlayer.ID
get

This player's actorID

◆ IsInactive

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.

◆ isInactive

bool PhotonPlayer.isInactive
getset

◆ isLocal

bool PhotonPlayer.isLocal
get

◆ IsMasterClient

bool PhotonPlayer.IsMasterClient
get

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

See also: PhotonNetwork.masterClient.

◆ isMasterClient

bool PhotonPlayer.isMasterClient
get

◆ name

string PhotonPlayer.name
getset

◆ NickName

string PhotonPlayer.NickName
getset

Nickname of this player.

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

◆ UserId

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).

◆ userId

string PhotonPlayer.userId
getset