Group Group Group Group Group Group Group Group Group

raywenderlich.com Forums

Creating a Cross-Platform Multiplayer Game in Unity — Part 1

Learn how to create a cross-platform multiplayer game in Unity in the first of a fourth part tutorial.


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/2015-creating-a-cross-platform-multiplayer-game-in-unity-part-1

This article is very helpful . Everything in the article is working perfectly. I added a feature
Invite friends for play .But , I found disconnection and reconnection problems in Google real time muliplayer.
My question is
How to reconnect to a room in Google real time muliplayer with Unity3D ?

I create a quick game multiplayer connection

const int MinOpponents = 1, MaxOpponents = 1;
const int GameVariant = 0;
PlayGamesPlatform.Instance.RealTime.CreateQuickGame(MinOpponents,MaxOpponent,GameVariant,listener);

and Create With Invitation Screen

 PlayGamesPlatform.Instance.RealTime.CreateWithInvitationScreen(
 minimumOpponents,maximumOpponents,gameVariation, listener);

Connected to a room with one opponent

I dissabled my Ethernet connection of one device

Control Panel > All Control Panel Items > Network and Sharing Center > Change Adapter Settings > Ethernet >Disable this network device

I Enabled my Ethernet connection by

Control Panel > All Control Panel Items > Network and Sharing Center > Change Adapter Settings > Ethernet >Enable this network device

In my game each player’s data is sending to each other .

PlayGamesPlatform.Instance.RealTime.SendMessageToAll (true, messageToSend);

Before Ethernet disconnect it works perfect . After ethernet reconnection data is not getting to each other , but if one device left the room , following event will call.

public void OnPeersDisconnected (string[] participantIds)
  {
      foreach (string participantID in participantIds) {
          ShowMPStatus ("Player " + participantID + " has left.");
          if (updateListener != null) {
              updateListener.PlayerLeftRoom (participantID);
          }
      }
  }

How to detect , player disconnected from net and how to reconnect to same room properly

Login Google Play Game

Login Game is required before call other API.Play Game Unity Plugin support google account ,not support google plus api now.

using google.service.game;

GoogleGame.Instance().login (true, false);
GoogleGame.Instance().gameEventHandler += onGameEvent;
void onGameEvent(int result_code,string eventName,string data){
Debug.Log (eventName + “-----------” + data);
if(result_code==-1&&eventName==GameEvent.onConnectSuccess){
//login success,you can do other now
}
}
You can get player infomation after login,the data is json format string

string json=GoogleGame.Instance().getCurrentUserInfo();
If you exit your game,you can login Out and disconnect

GoogleGame.Instance().loginOut();
Play Game Leaderboard

Display Leaderboard with default UI is very easy

GoogleGame.Instance().showLeaderboards();
Submit a leaderboard score,the first param is leaderboard id,the second param is score value.

GoogleGame.Instance().submitLeaderboardScore(“CgkItJ_UzNUHEAIQCQ”, 1000L);
if you want to define a ui for leaderboard,you can load data,and you will get data in event GameEvent.onLeaderboardMetadataResult

GoogleGame.Instance().loadLeaderboardsMetadata(false);
Play Game Achieve

Display Achievements with default UI is easy too

GoogleGame.Instance().showAchievements();
Unlock Achievement,the param is Achievement ID

GoogleGame.Instance().unlockAchievement(“CgkItJ_UzNUHEAIQBA”);
If you want to define ui for Achievement,you can load data ,and handle event GameEvent.onLoadAchievementsResult

GoogleGame.Instance().loadAchievements();
Game Event and Quest

Load Game Event List,and handle Event GameEvent.onLoadEventsResult

GoogleGame.Instance().loadEvents();
Change Event Data

GoogleGame.Instance().incrementEvent(“eventID”,102);
Load Quest ,and handle Event GameEvent.onLoadQuestsResult.selector is in GameConst such as SELECT_COMPLETED,sortOrder is SORT_ORDER_MOST_RECENT_FIRST or SORT_ORDER_SOCIAL_AGGREGATION

GoogleGame.Instance().loadQuests(int[] questSelectors, int sortOrder, bool forceReload);
accept Quest

GoogleGame.Instance().acceptQuest(string questid);
you can listener the state change of quest by handle event GameEvent.onQuestCompleted

My game crashes when I click on the multiplayer button.

I am at just before “Improving the Sign-In Process” in the tutorial. Are the updates to the plugin that require new code?

Hello, guys.

I still can’t manage to build my Google Play Games Services, using this method. This method ways too old, imho.

I did Cocopods install, various fix on github, etc. And still no luck!

Please kindly refer me, when there is any update for it?

I’ll be much appreciated!

Best Regards

I am making an app for android, and m prompted to write “Signing certificate fingerprint” in the google developer console. what should i fill in?

GPGS is since deprecated on iOS. Any other recommendations for cross-platform turn-based multiplayer services?

Well, Unity has their own multiplayer framework, although that seems to be geared more towards real-time games, and not so much for turn-based ones.

You might want to consider a service like Firebase for running a turn-based game. You can use the Realtime Database to store game state, Cloud Functions to perform server-side logic and gameplay, and Cloud Messaging to send notifications to let players know that it’s their turn.

I don’t have a tutorial on this available or anything, but there’s some documentation here that you could check out…

This tutorial is more than six months old so questions are no longer supported at the moment for it. We will update it as soon as possible. Thank you! :]