on my server creator i set up a match like so:
void Awake() {
nManager = GetComponent<NetworkManager> ();
networkMatch = gameObject.AddComponent<NetworkMatch>();
t_serverCurrentPlayers.text = "0";
}
//press UI button to trigger this method..
public void CreateServer() {
if (serverName.text.Length >= 1 && serverMaxPlayers.text.Length >= 1) {
CreateMatchRequest newServer = new CreateMatchRequest ();
newServer.name = serverName.text;
newServer.size = uint.Parse(serverMaxPlayers.text); //100
newServer.advertise = true;
networkMatch.CreateMatch (newServer, OnServerCreate);
} else {
Debug.Log("Please fill in all the required fields!");
}
}
public void OnServerCreate(CreateMatchResponse createdServer) {
if (createdServer.success) {
serverCreated = true;
Utility.SetAccessTokenForNetwork(createdServer.networkId, new NetworkAccessToken(createdServer.accessTokenString));
NetworkServer.Listen(new MatchInfo(createdServer), 9000);
t_serverCurrentPlayers.text = "0";
btn_serverStart.gameObject.SetActive(false);
btn_serverStop.gameObject.SetActive(true);
serverName.interactable = false;
serverMaxPlayers.interactable = false;
serverPassword.interactable = false;
} else {
Debug.Log("Unable to create the server! Please try again!");
}
}
and on my client i look for matches and display them like so:
void Awake() {
nManager = GetComponent<NetworkManager> ();
if(showDialogBox == null) {
showDialogBox = GetComponent<ShowDialogBox>();
}
networkMatch = gameObject.AddComponent<NetworkMatch>();
}
//UI button refreshes the match list here...
public void ListServers() {
networkMatch.ListMatches (0, 20, "", OnServerListed);
Debug.Log("list");
Debug.Log(serverList.Count);
if (serverList.Count > 0) {
Debug.Log(serverList.Count);
}
networkMatch.ListMatches (0, 20, "", OnServerListed);
foreach (var server in nManager.matches) {
Debug.Log("foreach");
GameObject entry = (GameObject)Instantiate (serverEntry);
entry.gameObject.transform.FindChild("txt_serverName").GetComponent<Text>().text = server.name;
entry.gameObject.transform.FindChild("txt_serverCurrPlayers").GetComponent<Text>().text = server.currentSize.ToString();
entry.gameObject.transform.FindChild("txt_serverMaxPlayers").GetComponent<Text>().text = server.maxSize.ToString();
entry.gameObject.transform.FindChild("txt_performance").GetComponent<Text>().text = server.averageEloScore.ToString();
if (server.isPrivate) {
entry.gameObject.transform.FindChild("img_password").GetComponent<Image>().sprite = privateServer;
} else {
entry.gameObject.transform.FindChild("img_password").GetComponent<Image>().sprite = publicServer;
}
entry.transform.SetParent (pnl_serverList);
Debug.Log("after entry");
Debug.Log(serverList.Count);
}
}
public void OnServerListed(ListMatchResponse serverListResponse) {
if (serverListResponse.success && serverListResponse.matches != null) {
networkMatch.JoinMatch(serverListResponse.matches[0].networkId, "", OnServerJoined);
}
}
public void OnServerJoined(JoinMatchResponse serverJoin) {
if (serverJoin.success) {
showDialogBox.Show("woo!", "JOINED SERVER!");
} else {
showDialogBox.Show("Uh-oh!", "Failed to connect to this server! Please try again!");
}
}
UNET makes a msg in the console saying “match.Count == 1” so i assume its finding the match but then it does not display the match (the foreach lines)