Search code examples
androidxamarinxamarin.androidgoogle-play-servicesgoogle-play-games

How to get the current player's participant id in Xamarin


Using google games services, how do I get the participant id of the 'current player' using Xamarin? In Java, it's simply

room.getParticipantId(Games.Players.getCurrentPlayerId(mGoogleApiClient));

But I can't find the equivalent in C# with the Xamarin google games component.


Solution

  • Where client is a GoogleApiClient that has the GamesClass.API added and the GamesClass.ScopeGames added to it:

    if (client.IsConnected)
    {
        var player = GamesClass.Players.GetCurrentPlayer(client);
        Console.WriteLine(player.PlayerId);
        Console.WriteLine(player.DisplayName);
    }