Class CustomNetworkManagerWithCallbacks
Inheritance
Inherited Members
Namespace: Global Namespace
Assembly: com.unity.multiplayer-hlapi.Tests.dll
Syntax
public class CustomNetworkManagerWithCallbacks : NetworkManager
Fields
actualListOfCallbacks
Declaration
public List<string> actualListOfCallbacks
Field Value
Type | Description |
---|---|
List<string> |
isStartHostPartDone
Declaration
public bool isStartHostPartDone
Field Value
Type | Description |
---|---|
bool |
isStopHostPartDone
Declaration
public bool isStopHostPartDone
Field Value
Type | Description |
---|---|
bool |
Methods
OnClientConnect(NetworkConnection)
Called on the client when connected to a server.
The default implementation of this function sets the client as ready and adds a player. Override the function to dictate what happens when the client connects.
//Attach this script to a GameObject
//Create a Text GameObject(Create>UI>Text) and attach it to the Text field in the Inspector window
//This script changes the Text depending on if a client connects or disconnects to the server
using UnityEngine;
using UnityEngine.Networking;
using UnityEngine.UI;
public class Example : NetworkManager
{
//Assign a Text component in the GameObject's Inspector
public Text m_ClientText;
//Detect when a client connects to the Server
public override void OnClientConnect(NetworkConnection connection)
{
//Change the text to show the connection on the client side
m_ClientText.text = " " + connection.connectionId + " Connected!";
}
//Detect when a client connects to the Server
public override void OnClientDisconnect(NetworkConnection connection)
{
//Change the text to show the connection loss on the client side
m_ClientText.text = "Connection" + connection.connectionId + " Lost!";
}
}</code></pre>
Declaration
public override void OnClientConnect(NetworkConnection conn)
Parameters
Type | Name | Description |
---|---|---|
NetworkConnection | conn | Connection to the server. |
Overrides
OnServerAddPlayer(NetworkConnection, short)
Declaration
public override void OnServerAddPlayer(NetworkConnection conn, short playerControllerId)
Parameters
Type | Name | Description |
---|---|---|
NetworkConnection | conn | |
short | playerControllerId |
Overrides
OnServerConnect(NetworkConnection)
Called on the server when a new client connects.
Unity calls this on the Server when a Client connects to the Server. Use an override to tell the NetworkManager what to do when a client connects to the server.
//Attach this script to a GameObject and add a NetworkHUD component to the GameObject.
//Create a Text GameObject (Create>UI>Text) and attach it in the Text field in the Inspector.
//This script changes Text on the screen when a client connects to the server
using UnityEngine;
using UnityEngine.Networking;
using UnityEngine.UI;
public class OnServerConnectExample : NetworkManager
{
//Assign a Text component in the GameObject's Inspector
public Text m_Text;
//Detect when a client connects to the Server
public override void OnServerConnect(NetworkConnection connection)
{
//Change the text to show the connection and the client's ID
m_Text.text = "Client " + connection.connectionId + " Connected!";
}
}</code></pre>
Declaration
public override void OnServerConnect(NetworkConnection conn)
Parameters
Type | Name | Description |
---|---|---|
NetworkConnection | conn | Connection from client. |
Overrides
OnServerReady(NetworkConnection)
Called on the server when a client is ready.
The default implementation of this function calls NetworkServer.SetClientReady() to continue the network setup process.
Declaration
public override void OnServerReady(NetworkConnection conn)
Parameters
Type | Name | Description |
---|---|---|
NetworkConnection | conn | Connection from client. |
Overrides
OnStartClient(NetworkClient)
This is a hook that is invoked when the client is started.
StartClient has multiple signatures, but they all cause this hook to be called.
Declaration
public override void OnStartClient(NetworkClient client)
Parameters
Type | Name | Description |
---|---|---|
NetworkClient | client | The NetworkClient object that was started. |
Overrides
OnStartHost()
This hook is invoked when a host is started.
StartHost has multiple signatures, but they all cause this hook to be called.
Declaration
public override void OnStartHost()
Overrides
OnStartServer()
This hook is invoked when a server is started - including when a host is started. StartServer has multiple signatures, but they all cause this hook to be called.
Declaration
public override void OnStartServer()
Overrides
OnStopClient()
This hook is called when a client is stopped.
Declaration
public override void OnStopClient()
Overrides
OnStopHost()
This hook is called when a host is stopped.
Declaration
public override void OnStopHost()
Overrides
OnStopServer()
This hook is called when a server is stopped - including when a host is stopped.
Declaration
public override void OnStopServer()