OnTurnBasedMatchUpdateReceivedListener不会触发

时间:2014-07-21 15:59:14

标签: java android unity3d google-play-services google-play-games

我正在尝试触发OnTurnBasedMatchUpdateReceivedListener但它似乎不起作用。下面是我正在使用的代码示例。我获得了一个有效的GoogleApiClient并且已经登录(我还有其他听众会参与代码的其他部分)。

目标是让一个可以处理此事件的类,通过传递GoogleApiClient并在此处进行回调(我没有其他方法可以获取代码来触发,例如BaseGameActivity,因为代码在另一个LIB中并且我正在写其他代码。)

有关如何调试的建议吗?

package com.google.example.games.pluginsupport;

import android.util.Log;

import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.games.Games;
import com.google.android.gms.games.multiplayer.turnbased.OnTurnBasedMatchUpdateReceivedListener;
import com.google.android.gms.games.multiplayer.turnbased.TurnBasedMatch;

public class TurnBaseMatchHelper implements OnTurnBasedMatchUpdateReceivedListener {

    public interface TurnBasedMatchListener {
        void onTurnBasedMatchReceived(TurnBasedMatch match);
        void onTurnBasedMatchRemoved(String matchId);
    }

    private static TurnBaseMatchHelper turnbaseInterface = null;
    private TurnBasedMatchListener sTurnBasedMatchListener = null;

    public static void registerTurnBasedCallbacks(GoogleApiClient _googleApiClient, TurnBasedMatchListener sListener) {

        if (turnbaseInterface == null) {
            turnbaseInterface = new TurnBaseMatchHelper();
        }       
        turnbaseInterface.sTurnBasedMatchListener = sListener;

        Log.d("Unity", "registerTurnBasedCallbacks");

        Games.TurnBasedMultiplayer.registerMatchUpdateListener(_googleApiClient, turnbaseInterface);
    }

    @Override
    public void onTurnBasedMatchReceived(TurnBasedMatch match) {

        Log.d("Unity", "onTurnBasedMatchReceived");

        if (turnbaseInterface.sTurnBasedMatchListener != null) {
             sTurnBasedMatchListener.onTurnBasedMatchReceived(match);
        }
    }

    @Override
    public void onTurnBasedMatchRemoved(String matchId) {

        Log.d("Unity", "onTurnBasedMatchRemoved");

        if (turnbaseInterface.sTurnBasedMatchListener != null) {
             sTurnBasedMatchListener.onTurnBasedMatchRemoved(matchId);
        }
    }
}

1 个答案:

答案 0 :(得分:1)

这是我类似的问题答案。

From post: 转到设置 - >帐户和同步 - >打开自动同步复选框