📜 ⬆️ ⬇️

Creating a rating of players for the mobile game (Unity + Google Play Game Services)

Player rating (leaderboard, scores) for a mobile game is an interesting and sometimes necessary thing. In this article I will talk about how to add a player rating to an application created in Unity, because There is not much information about it in runet. In addition, the rating will be cross-platform (android + iOS), but without the support of Windows Phone.

image

Section 1. DEVELOPER CONSOL

1. We believe that the application has already been published on Google Play, i.e. we have a package name, for example com.AnonymousInteractives.NakedSnake
')
2. Go to [developer console] (Developer Console), on the left open [game services] (Game Services)

image

3. Click "Add a new game" and specify the name of the game and category. There may be some confusion. The term "game" here means gaming service. The name may not coincide with the real name of your application. The game service has a unique identifier, for example 88171208539
image

4. Fill [game info] - description and pictures

5. In the [Related Applications] section, you can associate up to 20 applications with the gaming service. It can be android, iOS and web applications. Choose android. Then you just need to enter the name of the application package from item 1

image

6. In the [achievements] section you need to add achievements. You can skip this item for testing, but for publication you need to add at least 5 achievements. If we have no achievements in the game, then simply create fake achievements 1, 2, 3, 4, 5 and forget about them.

7. Finally, we go to the [Player Rating] section. We create the ratings we need, everything is obvious. As a result, we get a rating with some identifier, for example, CgkI276nu8gCEAIQAA. Subsequently, he and the gaming service ID will be needed for us to configure the plug-in in Unity and access the service

image

8. In the [testing] section, you can add accounts for testing. And you can specify exactly email accounts, not a Google+ group, as when testing the game itself

9. In the [publication] section, you can publish the game, although this is not necessary for testing. All, the developer console, we no longer need

Section 2. Unity

1. Go to the play-games-plugin-for-unity project page and download the project (link “Download ZIP”). In the archive we find the file GooglePlayGamesPlugin-0.9.02.unitypackage

2. Open the application project in Unity

3. Double click on GooglePlayGamesPlugin-0.9.02.unitypackage and import the package into the project.

image

4. Go to the menu File / Play Games - Android setup and enter the ID of our service (see step 3 from the previous section). That's it, the setup is complete!

image

5. Now it remains to add a couple of lines of code and we will have a player rating. The graphical user interface is in the Android SDK, so we don’t have to spend time on it. At the same time, there is no customization of the UI (except for the settings in the developer console, the rating icon and the unit of measurement). On the page of the plug-in (see point 1) there is enough background information, so I will give a commentary code without making a comment on the entry in the rating of players and its subsequent display. I note that the process is asynchronous, and callback comes to every action. Because of this, it may be difficult to make entries in several ratings at once. As an option - the implementation of chains from callback. Alternatively, you can call ReportScore in parallel and handle all callbacks so that only the last one opens the rating with a ShowAchievementsUI call.

PlayGamesPlatform.DebugLogEnabled = true; PlayGamesPlatform.Activate(); Social.localUser.Authenticate(authenticated => { if (!authenticated || !Social.localUser.authenticated) { throw new Exception(); } Social.ReportScore(1000, "CgkI276nu8gCEAIQAA", (bool success) => { if (success) { Social.ShowAchievementsUI(); } else { throw new Exception(); } }); }); 


Section 3. Conclusion

Unfortunately, there is no support for Windows Phone. Everything is very sad there, you will find a low-level implementation of interaction with Azure and writing your own UI, but you could not find a ready-made and working solution.
That's all for now, thank you for your attention. In the future, if someone is interested, I can consider the process of creating a web application for moderating ratings (deleting cheaters, for example), because There are no tools for this in the developer console.

Source: https://habr.com/ru/post/227361/


All Articles