Exemplo n.º 1
0
        private static IEnumerator IsMatchReady(string matchId, int requiredPlayers, int waitTime, Action <bool> callback = null)
        {
            int     time             = 0;
            bool    IsMatchReady     = false;
            bool    IsMatchReadyDone = false;
            bool    IsGetMatchDone   = false;
            GDMatch retrievedMatch   = null;

            do
            {
                Debug.Log("Checking if Match [" + matchId + "] is ready");

                GamedoniaMatchMaking.GetMatch(matchId,
                                              delegate(bool success, GDMatch match, List <GDMatchEvent> matchEvents) {
                    IsGetMatchDone = true;
                    if (success)
                    {
                        retrievedMatch = match;
                    }
                }
                                              );


                while (!IsGetMatchDone)
                {
                    yield return(null);
                }

                //Check if match is ready
                if (retrievedMatch.users.Count >= requiredPlayers)
                {
                    IsMatchReady     = true;
                    IsMatchReadyDone = true;
                }
                else
                {
                    //Check if we are under total wait time
                    if (time < waitTime)
                    {
                        yield return(new WaitForSeconds(3));

                        time += 3;
                    }
                    else
                    {
                        IsMatchReadyDone = true;
                    }
                }
            }while(!IsMatchReadyDone);


            callback(IsMatchReady);
        }
Exemplo n.º 2
0
 /*
  * TODO Easy method for matchmaking
  */
 public static void QuickMatch(GDMatch match, string criteria, int requiredPlayers, int searchTime, Action <bool, GDMatch> callback = null)
 {
     GamedoniaMatchMaking.FindMatches(criteria, 0,
                                      delegate(bool success, List <GDMatch> foundMatches) {
         if (success)
         {
             if (foundMatches.Count > 0)
             {
                 //Join Match
                 GamedoniaMatchMaking.JoinMatch(foundMatches[0]._id,
                                                delegate(bool joinSuccess, GDMatch joinedMatch) {
                     if (success)
                     {
                         GamedoniaBackend.RunCoroutine(
                             GamedoniaMatchMaking.IsMatchReady(joinedMatch._id, requiredPlayers, searchTime,
                                                               delegate(bool isReady) {
                             if (isReady)
                             {
                                 GamedoniaMatchMaking.StartMatch(joinedMatch._id,
                                                                 delegate(bool startSucces, GDMatch startedMatch) {
                                     if (startSucces)
                                     {
                                         callback(true, startedMatch);
                                     }
                                     else
                                     {
                                         callback(false, null);
                                     }
                                 }
                                                                 );
                             }
                             else
                             {
                                 callback(false, null);
                             }
                         }
                                                               )
                             );
                     }
                 }
                                                );
             }
             else
             {
                 GamedoniaMatchMaking.CreateMatch(match, delegate(bool successCreate, GDMatch createdMatch) {
                     if (successCreate)
                     {
                         GamedoniaBackend.RunCoroutine(
                             GamedoniaMatchMaking.IsMatchReady(createdMatch._id, requiredPlayers, searchTime,
                                                               delegate(bool isReady) {
                             if (isReady)
                             {
                                 GamedoniaMatchMaking.StartMatch(createdMatch._id,
                                                                 delegate(bool startSucces, GDMatch startedMatch) {
                                     if (startSucces)
                                     {
                                         callback(true, startedMatch);
                                     }
                                     else
                                     {
                                         callback(false, null);
                                     }
                                 }
                                                                 );
                             }
                             else
                             {
                                 callback(false, null);
                             }
                         }
                                                               )
                             );
                     }
                 });
             }
         }
     }
                                      );
 }