Creating a player rating for a mobile game (Unity + Google Play Game Services)

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

    image

    Section 1. CONSOLE OF THE DEVELOPER

    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. We go to the [Developer Console], on the left we open [Game Services]

    image

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

    4. Fill in [game information] - description and pictures

    5. In the [related applications] section, you can associate up to 20 applications with a game service. It can be android, iOS and web applications. Choose android. Next, you just need to enter the name of the application package from point 1

    image

    6. In the [achievements] section, you need to add achievements. For testing, you can skip the item, 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 clear here. As a result, we get a rating with some identifier, for example CgkI276nu8gCEAIQAA. Subsequently, we will need it and the game service identifier to configure the plug-in in Unity and access the service

    image

    8. In the [testing] section, you can add accounts for testing. Moreover, you can specify the mail accounts, and not the 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. That's all, we’ll no longer need the developer console

    Section 2. Unity

    1. Go to the project page play-games-plugin-for-unity 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 File / Play Games - Android setup menu and enter the identifier our service (see step 3 of 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 rating of players. The rating GUI is in the Android SDK, so we don’t have to spend time on it. At the same time, no customization of the UI is provided (except for the settings in the developer's console - rating icon and unit). On the plugin page (see point 1) there is enough background information, so without comment I will provide a code for making an entry in the rating of players with its subsequent display. I note that the process is asynchronous, and callback comes to each action. Because of this, it may be difficult to make entries in several ratings at once. As an option - implementation of chains from callback. Alternatively, you can call ReportScore in parallel and handle all callbacks in this way

    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 yet. Everything is completely sad there, you will find a low-level implementation of interaction with Azure and writing your own UI, and you could not find a ready-made and working solution.
    That's all for now, thanks for watching. In the future, if someone is interested, I can consider the process of creating a web application for moderating ratings (removing cheaters, for example), because in the developer console there is no means for this.

    Also popular now: