Hi,
I’m trying to make a custom GUI for the login scene for a game that uses the Networking API
One thing I’m trying to achieve is to display a “Connecting” message when I call StartClient() and if the connection attempt times out, I want to display a “Could not connect to the server” message.
But I have no idea how to do this. I see there are a lot of callbacks available, but I tried OnClientError, OnServerError, OnClientDisconnect, OnClientNotReady but apparently none of these callbacks are called here.
I’m pretty sure this should be possible because the NetworkManager’s default HUD does something like that, but I have no idea how, and the documentation is no help.
edit:
here is the code of my NetworkManager
using UnityEngine;
using System.Collections;
using UnityEngine.Networking;
public class CustomNetworkManager : NetworkManager {
void OnClientError(NetworkConnection conn, int errorCode) {
print ("ClientError");
print (conn);
print (errorCode);
}
void OnStopClient() {
print ("StopClient");
}
void OnClientDisconnect(NetworkConnection conn) {
print ("ClientDisconnect");
print (conn);
}
void OnClientNotReady(NetworkConnection conn) {
print ("ClientNotReady");
print (conn);
}
}
edit 2: I also tried to get the NetworkClient when I call StartClient and to register a handler for the Error MsgType… to no avail
public void StartClient() {
SetServerIp ();
NetworkClient client = NetworkManager.singleton.StartClient ();
client.RegisterHandler (MsgType.Error, ConnectionError);
}
public void ConnectionError(NetworkMessage netMsg) {
print ("connection error");
print (netMsg);
}