Class NetworkManager
The main component of the library
Implements
Inherited Members
Namespace: MLAPI
Assembly: Unity.Multiplayer.MLAPI.Runtime.dll
Syntax
[AddComponentMenu("MLAPI/NetworkManager", -100)]
public class NetworkManager : MonoBehaviour, INetworkUpdateSystem
Fields
ConnectedClients
Gets a dictionary of connected clients and their clientId keys. This is only populated on the server.
Declaration
public readonly Dictionary<ulong, NetworkClient> ConnectedClients
Field Value
Type | Description |
---|---|
Dictionary<ulong, NetworkClient> |
ConnectedClientsList
Gets a list of connected clients. This is only populated on the server.
Declaration
public readonly List<NetworkClient> ConnectedClientsList
Field Value
Type | Description |
---|---|
List<NetworkClient> |
DontDestroy
Gets or sets if the NetworkManager should be marked as DontDestroyOnLoad
Declaration
[HideInInspector]
public bool DontDestroy
Field Value
Type | Description |
---|---|
bool |
LogLevel
The log level to use
Declaration
[HideInInspector]
public LogLevel LogLevel
Field Value
Type | Description |
---|---|
LogLevel |
NetworkConfig
The current NetworkConfig
Declaration
[HideInInspector]
public NetworkConfig NetworkConfig
Field Value
Type | Description |
---|---|
NetworkConfig |
PendingClients
Gets a dictionary of the clients that have been accepted by the transport but are still pending by the MLAPI. This is only populated on the server.
Declaration
public readonly Dictionary<ulong, PendingClient> PendingClients
Field Value
Type | Description |
---|---|
Dictionary<ulong, PendingClient> |
RunInBackground
Gets or sets if the application should be set to run in background
Declaration
[HideInInspector]
public bool RunInBackground
Field Value
Type | Description |
---|---|
bool |
Properties
ConnectedHostname
The current hostname we are connected to, used to validate certificate
Declaration
public string ConnectedHostname { get; }
Property Value
Type | Description |
---|---|
string |
IsClient
Gets Whether or not a client is running
Declaration
public bool IsClient { get; }
Property Value
Type | Description |
---|---|
bool |
IsConnectedClient
Gets if we are connected as a client
Declaration
public bool IsConnectedClient { get; }
Property Value
Type | Description |
---|---|
bool |
IsHost
Gets if we are running as host
Declaration
public bool IsHost { get; }
Property Value
Type | Description |
---|---|
bool |
IsListening
Gets Whether or not we are listening for connections
Declaration
public bool IsListening { get; }
Property Value
Type | Description |
---|---|
bool |
IsServer
Gets Whether or not a server is running
Declaration
public bool IsServer { get; }
Property Value
Type | Description |
---|---|
bool |
LocalClientId
The clientId the server calls the local client by, only valid for clients
Declaration
public ulong LocalClientId { get; }
Property Value
Type | Description |
---|---|
ulong |
NetworkTime
A synchronized time, represents the time in seconds since the server application started. Is replicated across all clients
Declaration
public float NetworkTime { get; }
Property Value
Type | Description |
---|---|
float |
ServerClientId
Gets the networkId of the server
Declaration
public ulong ServerClientId { get; }
Property Value
Type | Description |
---|---|
ulong |
Singleton
The singleton instance of the NetworkManager
Declaration
public static NetworkManager Singleton { get; }
Property Value
Type | Description |
---|---|
NetworkManager |
Methods
DisconnectClient(ulong)
Disconnects the remote client.
Declaration
public void DisconnectClient(ulong clientId)
Parameters
Type | Name | Description |
---|---|---|
ulong | clientId | The ClientId to disconnect |
NetworkUpdate(NetworkUpdateStage)
Declaration
public void NetworkUpdate(NetworkUpdateStage updateStage)
Parameters
Type | Name | Description |
---|---|---|
NetworkUpdateStage | updateStage |
SetSingleton()
Declaration
public void SetSingleton()
Shutdown()
Declaration
public void Shutdown()
StartClient()
Starts a client
Declaration
public SocketTasks StartClient()
Returns
Type | Description |
---|---|
SocketTasks |
StartHost(Vector3?, Quaternion?, bool?, ulong?, Stream)
Starts a Host
Declaration
public SocketTasks StartHost(Vector3? position = null, Quaternion? rotation = null, bool? createPlayerObject = null, ulong? prefabHash = null, Stream payloadStream = null)
Parameters
Type | Name | Description |
---|---|---|
Vector3? | position | |
Quaternion? | rotation | |
bool? | createPlayerObject | |
ulong? | prefabHash | |
Stream | payloadStream |
Returns
Type | Description |
---|---|
SocketTasks |
StartServer()
Starts a server
Declaration
public SocketTasks StartServer()
Returns
Type | Description |
---|---|
SocketTasks |
StopClient()
Stops the running client
Declaration
public void StopClient()
StopHost()
Stops the running host
Declaration
public void StopHost()
StopServer()
Stops the running server
Declaration
public void StopServer()
Events
ConnectionApprovalCallback
The callback to invoke during connection approval
Declaration
public event Action<byte[], ulong, NetworkManager.ConnectionApprovedDelegate> ConnectionApprovalCallback
Event Type
Type | Description |
---|---|
Action<byte[], ulong, NetworkManager.ConnectionApprovedDelegate> |
OnClientConnectedCallback
The callback to invoke once a client connects. This callback is only ran on the server and on the local client that connects.
Declaration
public event Action<ulong> OnClientConnectedCallback
Event Type
Type | Description |
---|---|
Action<ulong> |
OnClientDisconnectCallback
The callback to invoke when a client disconnects. This callback is only ran on the server and on the local client that disconnects.
Declaration
public event Action<ulong> OnClientDisconnectCallback
Event Type
Type | Description |
---|---|
Action<ulong> |
OnPerformanceDataEvent
Declaration
public static event NetworkManager.PerformanceDataEventHandler OnPerformanceDataEvent
Event Type
Type | Description |
---|---|
NetworkManager.PerformanceDataEventHandler |
OnServerStarted
The callback to invoke once the server is ready
Declaration
public event Action OnServerStarted
Event Type
Type | Description |
---|---|
Action |