in GameLiftExampleUnityProject/Assets/Scripts/Client/NetworkClient.cs [31:85]
public IEnumerator DoMatchMakingAndConnect(Dictionary<string,double> regionLatencies)
{
Debug.Log("Request matchmaking...");
GameObject.FindObjectOfType<UIManager>().SetTextBox("Requesting matchmaking...");
yield return null;
var matchMakingRequestInfo = this.matchmakingClient.RequestMatchMaking(regionLatencies);
Debug.Log("TicketId: " + matchMakingRequestInfo.TicketId);
if (matchMakingRequestInfo != null)
{
bool matchmakingDone = false;
int tries = 0;
while (!matchmakingDone)
{
Debug.Log("Checking match status...");
GameObject.FindObjectOfType<UIManager>().SetTextBox("Checking match status...");
yield return null;
this.matchStatusInfo = this.matchmakingClient.RequestMatchStatus(matchMakingRequestInfo.TicketId);
if (matchStatusInfo.PlayerSessionId.Equals("NotPlacedYet"))
{
Debug.Log("Still waiting for placement");
GameObject.FindObjectOfType<UIManager>().SetTextBox("Still waiting for placement...");
yield return new WaitForSeconds(1.0f);
}
else
{
Debug.Log("Matchmaking done!");
GameObject.FindObjectOfType<UIManager>().SetTextBox("Matchmaking done! Connecting to server...");
yield return null;
matchmakingDone = true;
// Matchmaking done, connect to the servers
Connect();
}
tries++;
// Return null if we failed after 20 tries
if (tries >= 20)
{
GameObject.FindObjectOfType<UIManager>().SetTextBox("Aborting matchmaking, no match done on 20 seconds");
Debug.Log("Aborting matchmaking, no match done on 20 seconds");
yield return null;
break;
}
yield return null;
}
}
else
{
GameObject.FindObjectOfType<UIManager>().SetTextBox("Matchmaking failed! Not connected.");
Debug.Log("Matchmaking request failed!");
}
yield return null;
}