我正在尝试触发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);
}
}
}