Photon Unity Networking  v1.91
English | 日本語 | 한국
Public Member Functions | Properties | List of all members
Room Class Reference

This class resembles a room that PUN joins (or joined). The properties are settable as opposed to those of a RoomInfo and you can close or hide "your" room. More...

Inherits RoomInfo.

Public Member Functions

void SetCustomProperties (Hashtable propertiesToSet, Hashtable expectedValues=null, bool webForward=false)
 Updates the current room's Custom Properties with new/updated key-values. More...
 
void SetPropertiesListedInLobby (string[] propsListedInLobby)
 Enables you to define the properties available in the lobby if not all properties are needed to pick a room. More...
 
void ClearExpectedUsers ()
 Attempts to remove all current expected users from the server's Slot Reservation list. More...
 
void SetExpectedUsers (string[] expectedUsers)
 Attempts to set the current expected users list. More...
 
override string ToString ()
 Returns a summary of this Room instance as string. More...
 
new string ToStringFull ()
 Returns a summary of this Room instance as longer string, including Custom Properties. More...
 
- Public Member Functions inherited from RoomInfo
override bool Equals (object other)
 Makes RoomInfo comparable (by name). More...
 
override int GetHashCode ()
 Accompanies Equals, using the name's HashCode as return. More...
 
override string ToString ()
 Simple printingin method. More...
 
string ToStringFull ()
 Simple printingin method. More...
 

Properties

new string Name [get, set]
 The name of a room. Unique identifier (per Loadbalancing group) for a room/match. More...
 
new bool IsOpen [get, set]
 Defines if the room can be joined. This does not affect listing in a lobby but joining the room will fail if not open. If not open, the room is excluded from random matchmaking. Due to racing conditions, found matches might become closed before they are joined. Simply re-connect to master and find another. Use property "visible" to not list the room. More...
 
new bool IsVisible [get, set]
 Defines if the room is listed in its lobby. Rooms can be created invisible, or changed to invisible. To change if a room can be joined, use property: open. More...
 
string[] PropertiesListedInLobby [get, set]
 A list of custom properties that should be forwarded to the lobby and listed there. More...
 
bool AutoCleanUp [get]
 Gets if this room uses autoCleanUp to remove all (buffered) RPCs and instantiated GameObjects when a player leaves. More...
 
new int MaxPlayers [get, set]
 Sets a limit of players to this room. This property is shown in lobby, too. If the room is full (players count == maxplayers), joining this room will fail. More...
 
new int PlayerCount [get]
 Count of players in this room. More...
 
string[] ExpectedUsers [get]
 List of users who are expected to join this room. In matchmaking, Photon blocks a slot for each of these UserIDs out of the MaxPlayers. More...
 
int PlayerTtl [get, set]
 Player Time To Live. How long any player can be inactive (due to disconnect or leave) before the user gets removed from the playerlist (freeing a slot). More...
 
int EmptyRoomTtl [get, set]
 Room Time To Live. How long a room stays available (and in server-memory), after the last player becomes inactive. After this time, the room gets persisted or destroyed. More...
 
new string name [get, set]
 
new bool open [get, set]
 
new bool visible [get, set]
 
string[] propertiesListedInLobby [get, set]
 
bool autoCleanUp [get]
 
new int maxPlayers [get, set]
 
new int playerCount [get]
 
string[] expectedUsers [get]
 
- Properties inherited from RoomInfo
bool removedFromList [get, set]
 Used internally in lobby, to mark rooms that are no longer listed. More...
 
Hashtable CustomProperties [get]
 Read-only "cache" of custom properties of a room. Set via Room.SetCustomProperties (not available for RoomInfo class!). More...
 
string Name [get]
 The name of a room. Unique identifier (per Loadbalancing group) for a room/match. More...
 
int PlayerCount [get, set]
 Only used internally in lobby, to display number of players in room (while you're not in). More...
 
bool IsLocalClientInside [get, set]
 State if the local client is already in the game or still going to join it on gameserver (in lobby always false). More...
 
byte MaxPlayers [get]
 Sets a limit of players to this room. This property is shown in lobby, too. If the room is full (players count == maxplayers), joining this room will fail. More...
 
bool IsOpen [get]
 Defines if the room can be joined. This does not affect listing in a lobby but joining the room will fail if not open. If not open, the room is excluded from random matchmaking. Due to racing conditions, found matches might become closed before they are joined. Simply re-connect to master and find another. Use property "IsVisible" to not list the room. More...
 
bool IsVisible [get]
 Defines if the room is listed in its lobby. Rooms can be created invisible, or changed to invisible. To change if a room can be joined, use property: open. More...
 
Hashtable customProperties [get]
 
string name [get]
 
int playerCount [get, set]
 
bool isLocalClientInside [get, set]
 
byte maxPlayers [get]
 
bool open [get]
 
bool visible [get]
 

Additional Inherited Members

- Protected Attributes inherited from RoomInfo
byte maxPlayersField = 0
 Backing field for property. More...
 
int emptyRoomTtlField = 0
 Backing field for property. More...
 
int playerTtlField = 0
 Backing field for property. More...
 
string[] expectedUsersField
 Backing field for property. More...
 
bool openField = true
 Backing field for property. More...
 
bool visibleField = true
 Backing field for property. More...
 
bool autoCleanUpField = PhotonNetwork.autoCleanUpPlayerObjects
 Backing field for property. False unless the GameProperty is set to true (else it's not sent). More...
 
string nameField
 Backing field for property. More...
 

Detailed Description

This class resembles a room that PUN joins (or joined). The properties are settable as opposed to those of a RoomInfo and you can close or hide "your" room.

Member Function Documentation

void Room.ClearExpectedUsers ( )

Attempts to remove all current expected users from the server's Slot Reservation list.

Note that this operation can conflict with new/other users joining. They might be adding users to the list of expected users before or after this client called ClearExpectedUsers.

This room's expectedUsers value will update, when the server sends a successful update.

Internals: This methods wraps up setting the ExpectedUsers property of a room.

void Room.SetCustomProperties ( Hashtable  propertiesToSet,
Hashtable  expectedValues = null,
bool  webForward = false 
)

Updates the current room'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.
void Room.SetExpectedUsers ( string[]  expectedUsers)

Attempts to set the current expected users list.

Note that this operation can conflict with new/other users joining. They might be adding users to the list of expected users before or after this client called SetExpectedUsers. If the list changes before this operation arrives, the server will not modify the list and SetExpectedUsers() fails.

This room's expectedUsers value will be sent by the server.

Internals: This methods wraps up setting the ExpectedUsers property of a room.

void Room.SetPropertiesListedInLobby ( string[]  propsListedInLobby)

Enables you to define the properties available in the lobby if not all properties are needed to pick a room.

It makes sense to limit the amount of properties sent to users in the lobby as this improves speed and stability.

Parameters
propsListedInLobbyAn array of custom room property names to forward to the lobby.
override string Room.ToString ( )

Returns a summary of this Room instance as string.

Returns
Summary of this Room instance.
new string Room.ToStringFull ( )

Returns a summary of this Room instance as longer string, including Custom Properties.

Returns
Summary of this Room instance.

Property Documentation

bool Room.AutoCleanUp
get

Gets if this room uses autoCleanUp to remove all (buffered) RPCs and instantiated GameObjects when a player leaves.

bool Room.autoCleanUp
get
int Room.EmptyRoomTtl
getset

Room Time To Live. How long a room stays available (and in server-memory), after the last player becomes inactive. After this time, the room gets persisted or destroyed.

string [] Room.ExpectedUsers
get

List of users who are expected to join this room. In matchmaking, Photon blocks a slot for each of these UserIDs out of the MaxPlayers.

The corresponding feature in Photon is called "Slot Reservation" and can be found in the doc pages. Define expected players in the PhotonNetwork methods: CreateRoom, JoinRoom and JoinOrCreateRoom.

string [] Room.expectedUsers
get
new bool Room.IsOpen
getset

Defines if the room can be joined. This does not affect listing in a lobby but joining the room will fail if not open. If not open, the room is excluded from random matchmaking. Due to racing conditions, found matches might become closed before they are joined. Simply re-connect to master and find another. Use property "visible" to not list the room.

new bool Room.IsVisible
getset

Defines if the room is listed in its lobby. Rooms can be created invisible, or changed to invisible. To change if a room can be joined, use property: open.

new int Room.MaxPlayers
getset

Sets a limit of players to this room. This property is shown in lobby, too. If the room is full (players count == maxplayers), joining this room will fail.

new int Room.maxPlayers
getset
new string Room.Name
getset

The name of a room. Unique identifier (per Loadbalancing group) for a room/match.

new string Room.name
getset
new bool Room.open
getset
new int Room.PlayerCount
get

Count of players in this room.

new int Room.playerCount
get
int Room.PlayerTtl
getset

Player Time To Live. How long any player can be inactive (due to disconnect or leave) before the user gets removed from the playerlist (freeing a slot).

string [] Room.PropertiesListedInLobby
getset

A list of custom properties that should be forwarded to the lobby and listed there.

string [] Room.propertiesListedInLobby
getset
new bool Room.visible
getset