BomberUnits
...a Unity learning project
NetAdapter Class Reference
+ Collaboration diagram for NetAdapter:

Static Public Member Functions

static void ActivateOfflineMode ()
 
static void ConnectToMasterServer ()
 Called by the NET management when a connection is requested by the user. More...
 
static void DisconnectFromMasterServer ()
 Called by the NET management when disconnection from join or host is requested by the user. More...
 
static void HostNewRoom (string name)
 Called immediately by the state logic after connecting to the master server to open up a new hosted room. More...
 
static void LeaveRoom ()
 Called after having connected the master server to switch from Hosting to Joining.
 
static void JoinRoom ()
 
static GameObject Instantiate (GameObject prefab, Vector3 spawnLoc, Quaternion rotation, object[] initData=null, bool isSceneObj=false)
 Spawns a clone of the given prefab and initializes it with the given data. More...
 
static bool IsConnected ()
 Returns true if this client is connected to the Master or in OfflineMode. Should always be true!
 
static bool IsMaster ()
 True if this client is the MasterClient or OfflineMode active.
 
static bool IsClientConnected (string clientID)
 
static bool IsInRoom ()
 
static string GetClientID ()
 Photon assigns IDs to players, which we call "Client" here. More...
 
static Client GetLocalClient ()
 
static int GetActorNr ()
 Returns the local client's actor number. -1 if not in a room.
 
static void Destroy (GameObject go)
 Offers destruction for networked and non-networked objects. More...
 
static bool HasClient (string clientId)
 Checks whether the requested client ID is known. More...
 
static System.Collections.Generic.IEnumerable< Client > GetAllClients ()
 
static Client GetClient (string clientId)
 Gets the Client object given a user id. More...
 
static byte GetNewEventCode ()
 
static Client GetMasterClient ()
 
static void DestroyFromMaster (GameObject go)
 Allows network-destruction of objects with PhotonView, if these have a Net::PhotonDestructor component. More...
 
static void LoadSceneForWholeRoom (string sceneName)
 Provides Scene loading for all clients in the room. More...
 
static object GetClientData (string key, string clientId="OfflineClient")
 
static Hashtable GetClientHashtable (string clientId="OfflineClient")
 
static void SendClientData (string key, object data)
 Version to support giving the key and data to be packed automatically.
 
static void SendClientData (Hashtable data)
 Uses Photon custom properties to save data per client. More...
 
static void RemoveClientData (string key)
 
static object GetRoomData (string key)
 
static Hashtable GetRoomHashtable ()
 
static void SetRoomData (string key, object data)
 
static int GetCommonTimeStamp ()
 Returns the common timebase of the Photon server as an overflowing int. More...
 

Static Private Attributes

static byte eventCodeCounter = 1
 Counter to give out new event codes on request.
 

Detailed Description

Definition at line 12 of file NetAdapter.cs.

Member Function Documentation

◆ ConnectToMasterServer()

static void ConnectToMasterServer ( )
inlinestatic

Called by the NET management when a connection is requested by the user.

Connects using standards settings and bases the party's name on the main player name.

Definition at line 32 of file NetAdapter.cs.

◆ Destroy()

static void Destroy ( GameObject  go)
inlinestatic

Offers destruction for networked and non-networked objects.

This client has to own the networked object!

Definition at line 149 of file NetAdapter.cs.

◆ DestroyFromMaster()

static void DestroyFromMaster ( GameObject  go)
inlinestatic

Allows network-destruction of objects with PhotonView, if these have a Net::PhotonDestructor component.

Destroys normally if not connected.

Definition at line 230 of file NetAdapter.cs.

◆ DisconnectFromMasterServer()

static void DisconnectFromMasterServer ( )
inlinestatic

Called by the NET management when disconnection from join or host is requested by the user.

Wrapper to call disconnect on Photon, leaving any room and the master server.

Definition at line 47 of file NetAdapter.cs.

◆ GetClient()

static Client GetClient ( string  clientId)
inlinestatic

Gets the Client object given a user id.

The User has to be in the same room. Will return null and log errors if the client is unknown. Photon calls clients "Players", but we change the terminology, as we want to enable multiple players per client.

Definition at line 197 of file NetAdapter.cs.

◆ GetClientID()

static string GetClientID ( )
inlinestatic

Photon assigns IDs to players, which we call "Client" here.

This can be used to identify each Player in the game via client and player UID. The client ID is only available after connecting.

Definition at line 125 of file NetAdapter.cs.

◆ GetCommonTimeStamp()

static int GetCommonTimeStamp ( )
inlinestatic

Returns the common timebase of the Photon server as an overflowing int.

Comparisons work fine as long as differences of timestamps are used because the overflows are negated if the time difference is within one full value range.

Definition at line 350 of file NetAdapter.cs.

◆ HasClient()

static bool HasClient ( string  clientId)
inlinestatic

Checks whether the requested client ID is known.

Will return true during offline mode or disconnected, as the local client should then have the virtual ID "OfflineClient".

Definition at line 169 of file NetAdapter.cs.

◆ HostNewRoom()

static void HostNewRoom ( string  name)
inlinestatic

Called immediately by the state logic after connecting to the master server to open up a new hosted room.

The room is automatically joined.

Todo:
: Check room list (PUN2 lobby callbacks) and create unique room name if already taken. Add all rooms to a lobby, join that and get the room list.

Definition at line 54 of file NetAdapter.cs.

◆ Instantiate()

static GameObject Instantiate ( GameObject  prefab,
Vector3  spawnLoc,
Quaternion  rotation,
object []  initData = null,
bool  isSceneObj = false 
)
inlinestatic

Spawns a clone of the given prefab and initializes it with the given data.

The prefab has to be within a 'Resources' folder.

Definition at line 84 of file NetAdapter.cs.

◆ JoinRoom()

static void JoinRoom ( )
inlinestatic
Todo:
This is for testing only, needs to be replaced by Lobby room list or so.

Definition at line 77 of file NetAdapter.cs.

◆ LoadSceneForWholeRoom()

static void LoadSceneForWholeRoom ( string  sceneName)
inlinestatic

Provides Scene loading for all clients in the room.

This works because AutomaticallySyncScene is set to true! Also works in Offline Mode (IsMaster is then always true).

Definition at line 249 of file NetAdapter.cs.

◆ SendClientData()

static void SendClientData ( Hashtable  data)
inlinestatic

Uses Photon custom properties to save data per client.

This data is maintained during (dis-)connecting and in offline mode. The used data types however need to be registered with Photon so they can be (de-)serialized.

Definition at line 293 of file NetAdapter.cs.


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