BomberUnits
...a Unity learning project
NetManager Class Reference

Manages all Network related topics, is persistent across scenes, just as the game manager. More...

+ Inheritance diagram for NetManager:
+ Collaboration diagram for NetManager:

Public Member Functions

void Awake ()
 
void Start ()
 
bool IsMaster ()
 Returns whether this client is currently a master. True while Hosting or in OfflineMode.
 
void Connect ()
 Main connection function from outside the NET layer. More...
 
void Join ()
 
void Destroy (GameObject obj, float delay)
 
NetStateMachine GetStateMachine ()
 
override void OnConnectedToMaster ()
 This is called once we completely joined the master server and can create rooms.
 
override void OnJoinedRoom ()
 Called after joining your own or other player's room.
 
override void OnCreateRoomFailed (short returnCode, string message)
 
override void OnCreatedRoom ()
 
override void OnJoinRoomFailed (short returnCode, string message)
 
override void OnJoinRandomFailed (short returnCode, string message)
 
override void OnLeftRoom ()
 
override void OnDisconnected (Photon.Realtime.DisconnectCause cause)
 A Disconnect can be intentional or unintentional. More...
 
override void OnPlayerEnteredRoom (Client newClient)
 This callback is only called for other clients joining, not for this client.
 
override void OnPlayerLeftRoom (Client client)
 
override void OnPlayerPropertiesUpdate (Client target, ExitGames.Client.Photon.Hashtable changedProps)
 Is called whenever the custom data for any client changes. More...
 
override void OnRoomPropertiesUpdate (ExitGames.Client.Photon.Hashtable changedProps)
 

Static Public Member Functions

static NetManager Get ()
 
static State GetCurState ()
 

Public Attributes

bool logEnabled
 

Static Public Attributes

static UnityEvent connectedToMasterEvent
 
static UnityEvent hostingEvent
 
static UnityEvent hostingFailedEvent
 
static UnityEvent joinedRoomEvent
 
static UnityEvent joinRoomFailedEvent
 
static UnityEvent leftRoomEvent
 
static UnityEvent disconnectEvent
 
static UnityStringEvent clientLeftRoomEvent
 
static UnityStringEvent clientEnteredRoomEvent
 
static UnityClientPropertiesUpdateEvent clientPropertiesUpdateEvent
 The client ID will be 'OfflineClient' in OfflineMode!
 
static UnityRoomPropertiesUpdateEvent roomPropertiesUpdateEvent
 
static NetEvent< PlayerIdNetDataplayerDeathNetEvent
 Sent upon player death in-game. More...
 
static NetEvent< PlayerSpawnNetDataplayerSpawnInfoNetEvent
 
static NetEvent< TypeOnlyEventNetDatabackToMainMenuNetEvent
 

Private Member Functions

void Init ()
 

Private Attributes

string curRoomName = ""
 Current room name this game instance has joined to.
 
bool offlineMode
 Current Whether OfflineMode is active or not.
 
NetStateMachine netSM = null
 

Static Private Attributes

static NetManager instance
 Singleton pattern instance.
 

Detailed Description

Manages all Network related topics, is persistent across scenes, just as the game manager.

Todo:
: Use Photon "Custom Properties" to sync client info, such as player info and infrequent stuff

Definition at line 30 of file NetManager.cs.

Member Function Documentation

◆ Connect()

void Connect ( )
inline

Main connection function from outside the NET layer.

Moves the Net State Machine to the "Connecting" state if plausible to do so. The detour over 'instance' allows a call of this funcion from an event.

Definition at line 127 of file NetManager.cs.

◆ OnDisconnected()

override void OnDisconnected ( Photon.Realtime.DisconnectCause  cause)
inline

A Disconnect can be intentional or unintentional.

Intentional: Triggered by any of the menus. Unintentional: Can happen at any time!

Definition at line 208 of file NetManager.cs.

◆ OnPlayerLeftRoom()

override void OnPlayerLeftRoom ( Client  client)
inline
Todo:
: We have to take over hosting or something!

Definition at line 232 of file NetManager.cs.

◆ OnPlayerPropertiesUpdate()

override void OnPlayerPropertiesUpdate ( Client  target,
ExitGames.Client.Photon.Hashtable  changedProps 
)
inline

Is called whenever the custom data for any client changes.

Is also called for the local client if connected or in active Offline Mode. In order to decouple the net management from the specifics of the game, no assumptions are made at this point on the content. Also an event with the data is raised so users of the NET layer subscribe to it, rather than being pushed.

Definition at line 246 of file NetManager.cs.

Member Data Documentation

◆ playerDeathNetEvent

NetEvent<PlayerIdNetData> playerDeathNetEvent
static

Sent upon player death in-game.

Todo:
: Communicate via custom property 'state' (alive, dead, not playing)

Definition at line 57 of file NetManager.cs.


The documentation for this class was generated from the following file: