0
\$\begingroup\$

I took a closer look at Google Play games services Turn based multiplayer, and I cannot find out if I am somehow able to just get a list of all open matches, so that I can implement my own GUI. It seems really weird to me that they would not let you do such a simple task. Is this just a problem with the Unity implementation or is it a general problem? Using the Google UI would make a clunky feel which I would like to avoid.

\$\endgroup\$
1
  • \$\begingroup\$ I can't say for sure but the last time I worked with google play game services (for save management) you did have to use their built in activities. You could try to poll the API yourself but I don't know if you'd have access to your OAuth session keys. Check out the API definition here: developers.google.com/games/services/web/api/turnBasedMatches If the Unity plugin doesn't let you make your own calls you could write your own plugin... \$\endgroup\$
    – Honeybunch
    Jul 14 '15 at 18:49
0
\$\begingroup\$

I finally found a solution.

First of all i added a issue in the github issue tracker. They told me they already had a issue like that. From that on i was able to find a solution for now (before they implement this stuff).

The fix i found there:

https://github.com/playgameservices/play-games-plugin-for-unity/issues/414

I will use the following code:

public void GetAllTBMatches(Action<TurnBasedMatch, TurnBasedMatch.MatchTurnStatus> callback)
{
    mTurnBasedManager.GetAllTurnbasedMatches(allMatches =>
                                             {

            foreach (var match in allMatches.MatchesMyTurn())
            {
                var converted = match.AsTurnBasedMatch(mNativeClient.GetUserId());
                callback(converted, TurnBasedMatch.MatchTurnStatus.MyTurn);
            }
            foreach (var match in allMatches.MatchesTheirTurn())
            {
                var converted = match.AsTurnBasedMatch(mNativeClient.GetUserId());
                callback(converted, TurnBasedMatch.MatchTurnStatus.TheirTurn);
            }
            foreach (var match in allMatches.MatchesCompleted())
            {
                var converted = match.AsTurnBasedMatch(mNativeClient.GetUserId());
                callback(converted, TurnBasedMatch.MatchTurnStatus.Complete);
            }


    });
}

public void GetAllTBInvitations(Action<Invitation> callback)
{
    mTurnBasedManager.GetAllTurnbasedMatches(allMatches =>
                                             {
        foreach (var invitation in allMatches.Invitations())
        {
            var converted = invitation.AsInvitation();
            callback(converted);
        }
    });
}

together with:

internal class TurnBasedMatchesResponse : BaseReferenceHolder {
internal TurnBasedMatchesResponse(IntPtr selfPointer) : base(selfPointer) {
}

protected override void CallDispose(HandleRef selfPointer) {
    C.TurnBasedMultiplayerManager_TurnBasedMatchesResponse_Dispose(SelfPtr());
}

internal CommonErrorStatus.MultiplayerStatus Status() {
    return C.TurnBasedMultiplayerManager_TurnBasedMatchesResponse_GetStatus(SelfPtr());
}

internal IEnumerable<MultiplayerInvitation> Invitations()
{
    return PInvokeUtilities.ToEnumerable(
        C.TurnBasedMultiplayerManager_TurnBasedMatchesResponse_GetInvitations_Length(SelfPtr()),
        index => new MultiplayerInvitation(C.TurnBasedMultiplayerManager_TurnBasedMatchesResponse_GetInvitations_GetElement(SelfPtr(), index)));
}

internal IEnumerable<NativeTurnBasedMatch> MatchesMyTurn()
{
    return PInvokeUtilities.ToEnumerable(
        C.TurnBasedMultiplayerManager_TurnBasedMatchesResponse_GetMyTurnMatches_Length(SelfPtr()),
        index => new NativeTurnBasedMatch(C.TurnBasedMultiplayerManager_TurnBasedMatchesResponse_GetMyTurnMatches_GetElement(SelfPtr(), index)));
}

internal IEnumerable<NativeTurnBasedMatch> MatchesTheirTurn()
{
    return PInvokeUtilities.ToEnumerable(
        C.TurnBasedMultiplayerManager_TurnBasedMatchesResponse_GetTheirTurnMatches_Length(SelfPtr()),
        index => new NativeTurnBasedMatch(C.TurnBasedMultiplayerManager_TurnBasedMatchesResponse_GetTheirTurnMatches_GetElement(SelfPtr(), index)));
}

internal IEnumerable<NativeTurnBasedMatch> MatchesCompleted()
{
    return PInvokeUtilities.ToEnumerable(
        C.TurnBasedMultiplayerManager_TurnBasedMatchesResponse_GetCompletedMatches_Length(SelfPtr()),
        index => new NativeTurnBasedMatch(C.TurnBasedMultiplayerManager_TurnBasedMatchesResponse_GetCompletedMatches_GetElement(SelfPtr(), index)));
}

internal static TurnBasedMatchesResponse FromPointer(IntPtr pointer)
{
    if (PInvokeUtilities.IsNull(pointer)) {
        return null;
    }

    return new TurnBasedMatchesResponse(pointer);
}

}

The answer is just copied from the link copied above, i still have to test this in the end product.

I hope this helps someone having the same problems.

Nikolas

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .