Photon Unity Networking 2 2.30

Public Types | Public Member Functions | Static Public Attributes | List of all members
PunTeams Class Reference

Implements teams in a room/game with help of player properties. Access them by Player.GetTeam extension. More...

Inherits MonoBehaviourPunCallbacks.

Public Types

enum  Team : byte
 Enum defining the teams available. First team should be neutral (it's the default value any field of this enum gets). More...
 

Public Member Functions

void Start ()
 
override void OnDisable ()
 
override void OnJoinedRoom ()
 Needed to update the team lists when joining a room. More...
 
override void OnLeftRoom ()
 Called when the local user/client left a room, so the game's logic can clean up it's internal state. More...
 
override void OnPlayerPropertiesUpdate (Player targetPlayer, Hashtable changedProps)
 Refreshes the team lists. It could be a non-team related property change, too. More...
 
override void OnPlayerLeftRoom (Player otherPlayer)
 Called when a remote player left the room or became inactive. Check otherPlayer.IsInactive. More...
 
override void OnPlayerEnteredRoom (Player newPlayer)
 Called when a remote player entered the room. This Player is already added to the playerlist. More...
 
void UpdateTeams ()
 
- Public Member Functions inherited from MonoBehaviourPunCallbacks
virtual void OnEnable ()
 
virtual void OnConnected ()
 Called to signal that the raw connection got established but before the client can call operation on the server. More...
 
virtual void OnMasterClientSwitched (Player newMasterClient)
 Called after switching to a new MasterClient when the current one leaves. More...
 
virtual void OnCreateRoomFailed (short returnCode, string message)
 Called when the server couldn't create a room (OpCreateRoom failed). More...
 
virtual void OnJoinRoomFailed (short returnCode, string message)
 Called when a previous OpJoinRoom call failed on the server. More...
 
virtual void OnCreatedRoom ()
 Called when this client created a room and entered it. OnJoinedRoom() will be called as well. More...
 
virtual void OnJoinedLobby ()
 Called on entering a lobby on the Master Server. The actual room-list updates will call OnRoomListUpdate. More...
 
virtual void OnLeftLobby ()
 Called after leaving a lobby. More...
 
virtual void OnDisconnected (DisconnectCause cause)
 Called after disconnecting from the Photon server. It could be a failure or intentional More...
 
virtual void OnRegionListReceived (RegionHandler regionHandler)
 Called when the Name Server provided a list of regions for your title. More...
 
virtual void OnRoomListUpdate (List< RoomInfo > roomList)
 Called for any update of the room-listing while in a lobby (InLobby) on the Master Server. More...
 
virtual void OnJoinRandomFailed (short returnCode, string message)
 Called when a previous OpJoinRandom call failed on the server. More...
 
virtual void OnConnectedToMaster ()
 Called when the client is connected to the Master Server and ready for matchmaking and other tasks. More...
 
virtual void OnRoomPropertiesUpdate (Hashtable propertiesThatChanged)
 Called when a room's custom properties changed. The propertiesThatChanged contains all that was set via Room.SetCustomProperties. More...
 
virtual void OnFriendListUpdate (List< FriendInfo > friendList)
 Called when the server sent the response to a FindFriends request. More...
 
virtual void OnCustomAuthenticationResponse (Dictionary< string, object > data)
 Called when your Custom Authentication service responds with additional data. More...
 
virtual void OnCustomAuthenticationFailed (string debugMessage)
 Called when the custom authentication failed. Followed by disconnect! More...
 
virtual void OnWebRpcResponse (OperationResponse response)
 Called when the response to a WebRPC is available. See LoadBalancingClient.OpWebRpc. More...
 
virtual void OnLobbyStatisticsUpdate (List< TypedLobbyInfo > lobbyStatistics)
 Called when the Master Server sent an update for the Lobby Statistics. More...
 
virtual void OnErrorInfo (ErrorInfo errorInfo)
 Called when the client receives an event from the server indicating that an error happened there. More...
 

Static Public Attributes

static Dictionary< Team, List< Player > > PlayersPerTeam
 The main list of teams with their player-lists. Automatically kept up to date. More...
 
const string TeamPlayerProp = "team"
 Defines the player custom property name to use for team affinity of "this" player. More...
 

Additional Inherited Members

- Properties inherited from MonoBehaviourPun
PhotonView photonView [get]
 A cached reference to a PhotonView on this GameObject. More...
 

Detailed Description

Implements teams in a room/game with help of player properties. Access them by Player.GetTeam extension.

Teams are defined by enum Team. Change this to get more / different teams. There are no rules when / if you can join a team. You could add this in JoinTeam or something.

Member Enumeration Documentation

◆ Team

enum Team : byte
strong

Enum defining the teams available. First team should be neutral (it's the default value any field of this enum gets).

Member Function Documentation

◆ OnJoinedRoom()

override void OnJoinedRoom ( )
virtual

Needed to update the team lists when joining a room.

Called by PUN. See enum MonoBehaviourPunCallbacks for an explanation.

Reimplemented from MonoBehaviourPunCallbacks.

◆ OnLeftRoom()

override void OnLeftRoom ( )
virtual

Called when the local user/client left a room, so the game's logic can clean up it's internal state.

When leaving a room, the LoadBalancingClient will disconnect the Game Server and connect to the Master Server. This wraps up multiple internal actions.

Wait for the callback OnConnectedToMaster, before you use lobbies and join or create rooms.

Reimplemented from MonoBehaviourPunCallbacks.

◆ OnPlayerEnteredRoom()

override void OnPlayerEnteredRoom ( Player  newPlayer)
virtual

Called when a remote player entered the room. This Player is already added to the playerlist.

If your game starts with a certain number of players, this callback can be useful to check the Room.playerCount and find out if you can start.

Reimplemented from MonoBehaviourPunCallbacks.

◆ OnPlayerLeftRoom()

override void OnPlayerLeftRoom ( Player  otherPlayer)
virtual

Called when a remote player left the room or became inactive. Check otherPlayer.IsInactive.

If another player leaves the room or if the server detects a lost connection, this callback will be used to notify your game logic.

Depending on the room's setup, players may become inactive, which means they may return and retake their spot in the room. In such cases, the Player stays in the Room.Players dictionary.

If the player is not just inactive, it gets removed from the Room.Players dictionary, before the callback is called.

Reimplemented from MonoBehaviourPunCallbacks.

◆ OnPlayerPropertiesUpdate()

override void OnPlayerPropertiesUpdate ( Player  targetPlayer,
Hashtable  changedProps 
)
virtual

Refreshes the team lists. It could be a non-team related property change, too.

Called by PUN. See enum MonoBehaviourPunCallbacks for an explanation.

Reimplemented from MonoBehaviourPunCallbacks.

Member Data Documentation

◆ PlayersPerTeam

Dictionary<Team, List<Player> > PlayersPerTeam
static

The main list of teams with their player-lists. Automatically kept up to date.

Note that this is static. Can be accessed by PunTeam.PlayersPerTeam. You should not modify this.

◆ TeamPlayerProp

const string TeamPlayerProp = "team"
static

Defines the player custom property name to use for team affinity of "this" player.