google玩游戏:通过邀请id获取请求玩家总数

google play games: get the total amount of requested players from an invitation id

我正在尝试使用 Google Play Games 在 Android 中编写多人游戏。一切都适用于自动匹配,但我不知道如何决定何时开始邀请游戏。

我的网络管理员有一个 shouldStartGame() 函数,如下所示:

boolean shouldStartGame(Room room) 
{
    int connectedPlayers = 0;
    for (Participant p : room.getParticipants()) {
        if (p.isConnectedToRoom()) ++connectedPlayers;
    }
    return connectedPlayers >= this.totalRequestedPlayers;
}

当游戏是自动匹配游戏时,这很好 - 当 Select 玩家对话框 returns

时,totalRequestedPlayers 会填充到 onActivityResult 中
public void onActivityResult(int request, int response, Intent data) {
if (request == NetworkManager.RC_SELECT_PLAYERS)
{
final ArrayList<String> invitees = data.getStringArrayListExtra(Games.EXTRA_PLAYER_IDS);

// get auto-match criteria
Bundle autoMatchCriteria = null;
int minAutoMatchPlayers = data.getIntExtra(Multiplayer.EXTRA_MIN_AUTOMATCH_PLAYERS, 0);
int maxAutoMatchPlayers = data.getIntExtra(Multiplayer.EXTRA_MAX_AUTOMATCH_PLAYERS, 0);

if (minAutoMatchPlayers > 0) 
{
    autoMatchCriteria = RoomConfig.createAutoMatchCriteria(
            minAutoMatchPlayers, maxAutoMatchPlayers, 0);
} 
else 
{
    autoMatchCriteria = null;
}

this.oNetwork.setTotalRequestedPlayers(invitees.size() + minAutoMatchPlayers);
RoomConfig roomConfig = roomConfigBuilder.build();
Games.RealTimeMultiplayer.create(getApiClient(), roomConfig);

// prevent screen from sleeping during handshake
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
}

但是,当响应其他玩家的邀请开始比赛时,我找不到任何方法来询问房间或 configBuilder 以找出需要多少玩家...

protected void onCreate(Bundle _savedState)
{   
String invitationID=this.getIntent().getExtras().getString(NetworkManager.EXTRA_ROOM_ID);
if(invitationID.equals(""))
{
    //invite some people
    this.oNetwork.beginInviteFriends(); 
}
else
{
//we have been invited to a room
    RoomConfig.Builder roomConfigBuilder =
            this.oNetwork.makeStandardRoomConfigForGameType(this);
    roomConfigBuilder.setInvitationIdToAccept(invitationID);

    RoomConfig c = roomConfigBuilder.build();

    this.oNetwork.setTotalRequestedPlayers(999);  // <-  need to figure out how to get this info
    Games.RealTimeMultiplayer.join(getApiClient(), c);

    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
}
}

我需要从原始邀请中找出 'named' 玩家的总数,加上自动匹配请求的数量

函数

@Override
public void onRoomConnected(int arg0, Room _room)
{

}

当所有用户(无论是受邀用户还是自动匹配用户)都已连接到聊天室时通知您。