NetworkManager
public class NetworkManager
{
//singleton yeeaaaaaaaaah
public static NetworkManager Network_Manager = null;
//...
//client or server
public GameConnection gameConnection;
//master server or master servers client
public GameConnection masterConnection;
//...
This class is used to manage whatever the current GameConnection is, whether it be a ClientConnection, ServerConnection, MasterServerConnection or MasterServerClientConnection. It offers an update function which helps push each connection type to check for incoming packets, send info or respond to other network related events. Also includes a number of helper functions.
This class is a singleton to help for access through-out the project.
Methods
public static void BuildNetworkManagerIfNull()
If there is no NetworkManager, lets build one
public static ConnectionType GetConnectionType()
Gets the connection type of the gameConnection attribute, which can be client or server or none
public static ConnectionType GetMasterServerConnectionType()
Gets the connection type of the masterConnection attribute, which can be masterServer or MasterServerClient or none
public static void NetworkUpdate()
A static call that can be called from anywhere which will call the Update function of the static Network_Manager
public static void EndSceneCleanUp()
Cleans up globals between scenes, add your own cleanup here if you need to
public static ServerConnection GetServerConnectionFromNetworkManager()
if gameConnection is server type, this function will retrieve it or else return null
public static ClientConnection GetClientConnectionFromNetworkManager()
if gameConnection is client type, this function will retrieve it or else return null
public static MasterServerClientConnection GetMasterServerClientConnectionFromNetworkManager()
if masterConnection is masterServerClient type, this function will retrieve it or else return null
public static PlayerConnection GetPlayerConnectionByID(int playerID)
Gets a PlayerConnection matching playerID IF gameConnection is server type and it can find it, else return null
public static void SetPlayerConnectionToOnboarded(int playerID)
Sets a PlayerConnection matching playerID to be onboarded IF gameConnection is server type
public static float GetLatency()
Get current gameConnection’s latency value
public static int GetLatencyFrames()
Get current gameConnection’s latency frames value
public static void CleanUpBeforeSceneChange()
Calls gameConnection’s CleanUpBeforeSceneChange method if we gameConnection not null
public static void DisconnectFromAll()
Call stop on gameConnection and masterConnection if they are not null
public NetworkManager()
Constructor that sets static Network_Manager to this NetworkManager
public void Update()
Calls the Update functions on gameConnection and masterConnection if they are not null
public void StopConnection()
Stops gameConnection