// for illustration purposes and to keep things simple we will set the match whenever any event
 // that returns it fires
 private void currentMatchChanged(GKTurnBasedMatch match)
 {
     // probably not the most user friendly thing to do but we will just swap to whatever match just had an event
     _currentMatch = match;
     GameCenterTurnBasedBinding.changeCurrentMatch(match.matchId);
     Debug.Log("loaded match: " + match.matchId + ". The match data will be automatically fetched for us.");
 }
    void OnGUI()
    {
        beginColumn();

        if (GUILayout.Button("Find Match"))
        {
            matchDataStringAsBytes();
            GameCenterTurnBasedBinding.findMatch(2, 8, true);
        }


        if (GUILayout.Button("End Turn For Match"))
        {
            // we will just find any player that is not us to use as the next player
            var ourPlayerId  = GameCenterBinding.playerIdentifier();
            var nextPlayerId = string.Empty;

            foreach (var p in _currentMatch.participants)
            {
                if (p.playerId != ourPlayerId)
                {
                    nextPlayerId = p.playerId;
                    break;
                }
            }

            GameCenterTurnBasedBinding.endTurnWithNextParticipant(nextPlayerId, matchDataStringAsBytes());
        }


        if (GUILayout.Button("Is it my Turn?"))
        {
            Debug.Log("is it my turn? " + GameCenterTurnBasedBinding.isCurrentPlayersTurn());
        }


        GUILayout.Space(50);
        if (GUILayout.Button("End Match In Turn"))
        {
            // you cannot end a match without first setting the matchOutcome for all players in the match
            foreach (var p in _currentMatch.participants)
            {
                GameCenterTurnBasedBinding.setMatchOutcomeForParticipant(GKTurnBasedMatchOutcome.Tied, p.playerId);
            }

            GameCenterTurnBasedBinding.endMatchInTurnWithMatchData(matchDataStringAsBytes());
        }


        if (GUILayout.Button("Quit Out of Turn"))
        {
            GameCenterTurnBasedBinding.participantQuitOutOfTurnWithOutcome(GKTurnBasedMatchOutcome.Quit);
        }


        endColumn(true);


        if (GUILayout.Button("Load All Matches"))
        {
            GameCenterTurnBasedBinding.loadMatches();
        }


        if (GUILayout.Button("Remove Current Match"))
        {
            GameCenterTurnBasedBinding.removeCurrentMatch();
        }


        if (GUILayout.Button("Rematch Current Match"))
        {
            // this will only work for a completed match on iOS 6+
            GameCenterTurnBasedBinding.rematchCurrentMatch();
        }


        if (GUILayout.Button("Set Match Message"))
        {
            // this can only be set if it is the current player's turn
            GameCenterTurnBasedBinding.setMatchMessage("The match's message!");
        }

        endColumn();


        if (bottomLeftButton("Back to 1st Scene"))
        {
            Application.LoadLevel(0);
        }
    }