Beispiel #1
0
        public void LeaveMatch(TurnBasedMatch match, Action <bool> callback)
        {
            Util.NullArgumentTest(match);

            // Set the match outcome as Quit.
            var matchOutcome = new GKTBMOutcome()
            {
                outcome = GKTBMOutcome.Outcome.Quit
            };

            // Quitting match out of turn.
            match.GC_TurnBasedMatch.ParticipantQuitOutOfTurn(
                matchOutcome,
                error =>
            {
                if (error != null)
                {
                    Debug.Log("Failed to leave match with error " + error.LocalizedDescription);
                }

                if (callback != null)
                {
                    callback(error == null);
                }
            });
        }
Beispiel #2
0
        public void LeaveMatchInTurn(TurnBasedMatch match, string nextParticipantId, Action <bool> callback)
        {
            Util.NullArgumentTest(match);

            // Find the next GKTurnBasedParticipant with the given ID.
            var participants = match.GC_TurnBasedMatch.Participants.ToArray(
                ptr => InteropObjectFactory <GKTurnBasedParticipant> .FromPointer(ptr, p => new GKTurnBasedParticipant(p)));

            GKTurnBasedParticipant nextGKParticipant;

            if (string.IsNullOrEmpty(nextParticipantId))
            {
                // No specific next player, choosing the the next vacant slot.
                nextGKParticipant = participants.FirstOrDefault(p => p.Player == null);
            }
            else
            {
                // Find the specified next player.
                nextGKParticipant = participants.FirstOrDefault(p =>
                {
                    var gkPlayer = p.Player;
                    return(gkPlayer != null && gkPlayer.PlayerID.Equals(nextParticipantId));
                });
            }

            if (nextGKParticipant == default(GKTurnBasedParticipant))
            {
                Debug.LogErrorFormat("Not found next participant for ID {0}. Aborting LeaveMatchInTurn...", string.IsNullOrEmpty(nextParticipantId) ? "[NullOrEmpty]" : nextParticipantId);

                if (callback != null)
                {
                    callback(false);
                }

                return;
            }

            // Set the match outcome as Quit.
            var matchOutcome = new GKTBMOutcome()
            {
                outcome = GKTBMOutcome.Outcome.Quit
            };

            // Quitting match in turn.
            match.GC_TurnBasedMatch.ParticipantQuitInTurn(
                matchOutcome,
                new GKTurnBasedParticipant[] { nextGKParticipant },
                GKTurnBasedMatch.GKTurnTimeoutDefault,
                match.Data ?? new byte[0],  // allow leaving a newly created match (whose Data == null)
                error =>
            {
                if (error != null)
                {
                    Debug.Log("Failed to leave match in turn with error " + error.LocalizedDescription);
                }

                if (callback != null)
                {
                    callback(error == null);
                }
            });
        }