I would like to rely on the network.peertype variable to control whether to show the game selecting UI. If the UI goes unmanaged, the user might be able to connect to multiple games or cause all kinds of trouble for themselves.
Expected:
- As soon as I call Network.Connect, Network.peerType is set to NetworkPeerType.Connecting until the connection succeeds or fails
Actual:
- Network.peerType remains NetworkPeerType.Disconected until the connection succeeds or fails
Code:
void OnGUI () {
if (Network.peerType == NetworkPeerType.Disconnected) {
GUILayout.BeginHorizontal();
if(GUILayout.Button("Start New Game")) {
Network.InitializeServer(1, port, !Network.HavePublicAddress());
MasterServer.RegisterHost(gameType, gameName);
Application.LoadLevel("footballBoard");
}
gameName = GUILayout.TextField(gameName);
GUILayout.EndHorizontal();
HostData[] data = MasterServer.PollHostList();
// Go through all the hosts in the host list
foreach (var element in data)
{
GUILayout.BeginHorizontal();
var name = element.gameName + " " + element.connectedPlayers + " / " + element.playerLimit;
GUILayout.Label(name);
GUILayout.Space(5);
string hostInfo = "[";
foreach (var host in element.ip) {
hostInfo = hostInfo + host + ":" + element.port + " ";
}
hostInfo = hostInfo + "]";
GUILayout.Label(hostInfo);
GUILayout.Space(5);
GUILayout.Label(element.comment);
GUILayout.Space(5);
GUILayout.FlexibleSpace();
if (GUILayout.Button("Connect"))
{
clicks++;
// Connect to HostData struct, internally the correct method is used (GUID when using NAT).
Network.Connect(element);
}
GUILayout.EndHorizontal();
}
}
}
I can manage the state myself, but why doesn’t this work?