Exemple #1
0
        /// <summary>
        /// Loads all the turn-based matches involving the local player and calls the callback on completion.
        /// </summary>
        /// <param name="callback">Callback.</param>
        public static void LoadAllMyMatches(Action <TurnBasedMatch[], NSError> callback)
        {
            GKTurnBasedMatch.LoadMatches(delegate(object[] gkmatches, NSError error) {
                if ((gkmatches == null) || (gkmatches.Length == 0))
                {
                    callback(null, error);
                    callback = null;
                }
                else
                {
                    var matches     = new TurnBasedMatch[gkmatches.Length];
                    int totalLoaded = 0;
                    for (int i = 0; i < gkmatches.Length; i++)
                    {
                        var gkmatch = gkmatches[i] as GKTurnBasedMatch;
                        matches[i]  = NSObjectWrapper.CreateWrapper(typeof(TurnBasedMatch), gkmatch) as TurnBasedMatch;
                        gkmatch     = null;

                        matches[i].ReloadPlayers(delegate() {
                            totalLoaded++;
                            if (totalLoaded == matches.Length)
                            {
                                callback(matches, error);
                                callback = null;
                                matches  = null;
                                error    = null;
                            }
                        });
                    }
                }

                gkmatches = null;
            });
        }
Exemple #2
0
        public void GetAllMatches(Action <TurnBasedMatch[]> callback)
        {
            Util.NullArgumentTest(callback);

            GKTurnBasedMatch.LoadMatches(
                (gkMatches, nsError) =>
            {
                TurnBasedMatch[] matches = gkMatches != null ?
                                           gkMatches.Select(gkm => TurnBasedMatch.FromGKTurnBasedMatch(gkm)).ToArray() : null;

                callback(matches);
            });
        }
Exemple #3
0
        /// <summary>
        /// List matches with friends
        /// </summary>
        /// <param name="listLoaded">List loaded.</param>
        public static void GetFriendsPuzzles(Action <List <PuzzleData> > listLoaded)
        {
            Logger.I("Game center: requesting turn based matches...");

            GKTurnBasedMatch.LoadMatches((matches, error) => {
                if (error != null)
                {
                    Logger.E("Game Center: match list failed... ", error);
                }
                else
                {
                    Logger.I("Game center: " + matches.Length + " turn based matches found.");

                    List <PuzzleData> puzzles = new List <PuzzleData> ();

                    foreach (GKTurnBasedMatch match in matches)
                    {
                        // Deserialize data
                        TransferablePuzzleData tp = GetPuzzleFromMatch(match);

                        if (tp != null)
                        {
                            tp.Puzzle.MatchId = match.MatchID;
                            tp.Puzzle.Match   = match;

                            puzzles.Add(tp.Puzzle);
                        }
                    }

                    if (listLoaded != null)
                    {
                        listLoaded(puzzles);
                    }
                }
            });
        }
Exemple #4
0
 /// <summary>
 /// A helper function to end and remove all turn-based matches that this player is participating in.
 /// This should be used for testing only.
 /// </summary>
 public static void RemoveAllMyMatches()
 {
     GKTurnBasedMatch.LoadMatches(_FoundMyMatches);
 }