【问题标题】:How to abort room when there is no opponent player available in Google Play Games?Google Play 游戏中没有对手玩家时如何中止房间?
【发布时间】:2016-12-02 07:45:39
【问题描述】:

我正在 Unity 中创建多人游戏。

要创建一个房间,我正在使用:

PlayGamesPlatform.Instance.RealTime.CreateQuickGame(MinOpponents, MaxOpponents, GameVariant, listener);

为了获得房间创建的进度,我正在使用:

public void OnRoomSetupProgress(float progress) {
}

然而,上述函数只在progress = 20 调用一次,然后,如果没有其他可用的玩家,则不再调用。

由于最初我不会有很多玩家使用这个应用程序,我想等待 10 秒以连接到任何其他玩家,如果没有玩家,我想用内置的 AI 开始游戏。为此,我需要以干净的方式中止当前的房间设置进度。我不知道该怎么走。

如果您知道这种情况的解决方案,请告诉我。

【问题讨论】:

    标签: unity3d google-play-games multiplayer 2d-games


    【解决方案1】:

    关于 Unity 中的多人游戏,GitHub post 仅讨论了在游戏结束时离开房间,使用PlayGamesPlatform.Instance.RealTime.LeaveRoom(); 触发对听众的OnLeftRoom 的调用。

    您可能想尝试Adding Real-time Multiplayer Support to Your Android Game,特别是Adding a waiting room UI,它指出

    如果您使用等候室 UI,则无需实现额外的逻辑来决定何时开始或取消游戏,如前面在 shouldStartGame()shouldCancelGame() 中所见。当您获得Activity.RESULT_OK 结果时,您可以立即开始,因为已连接所需数量的参与者。同样,当您从候诊室 UI 中得到错误结果时,您可以直接离开候诊室。

    要离开房间,请致电leave()

    // leave room
    Games.RealTimeMultiplayer.leave(mGoogleApiClient, null, mRoomId);
    
    // remove the flag that keeps the screen on
    getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    

    【讨论】:

      猜你喜欢
      • 2016-07-10
      • 1970-01-01
      • 2015-10-03
      • 2018-11-13
      • 2022-01-10
      • 2015-10-25
      • 2016-09-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多