简体   繁体   中英

Unity Google Play Games IsConnectedToRoom Check

I'm having trouble to check if a participant is still connected to a room.

I wrote this:

bool status=GooglePlayGames.Native.PInvoke.MultiplayerParticipant.AutomatchingSentinel().IsConnectedToRoom();

if (status = true) 
{
    this.gameObject.GetComponent<Text> ().text = "participant is connected";
}

if (status = false) 
{
    this.gameObject.GetComponent<Text> ().text = "participant left";
}`

When players are connected, "participant is connected" is displayed.

But when a player press the home button, and go back to the screen, the participant had OnPeersDisconnected called and leave the room. But for the actual player, "participant is connected" is still displayed.

How can i know when the IsConnectedToRoom() is false?

This may still depend on how implementation is going to be. According to the document :

Make sure to construct your game logic carefully to take each participant's status and connectedness into account. For example, to determine if all racers have crossed the finish line, your game should only consider the participants who are connected; some may have left the room or never have accepted the invitation.

Detecting when a player is disconnected

Your player might be disconnected from the room due to network connectivity or server issues. To be notified when a player is disconnected from the room, implement the OnConnectedSetChanged method.

virtual void OnConnectedSetChanged(RealTimeRoom const &room) {
  // Check the room's participants to see who connected/disconnected.
}

Hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM