Search code examples
androidiosunity-game-enginegame-centergoogle-play-games

Unity Social API


We are writing an application in Unity3D for both iOS and Android and we'd like to use the provided Social API to retrive and post the highScores on iOS (using GameCenter) and Android (using Google Play Game Services).

To keep the application simple, its weight low and to avoid cross-compilation extra setups we'd prefer not to use external plugins (unless point 4 is true).

I googled around for documentation and tutorials and I found THIS ONE. The implementation has been done in C#, but since the Unity guide also provides a c# version it went all straight forward.

However we couldn't manage to get this work, probably also because we don't understand well how this API really work.

First of all: the Unity guide states that "It [the api] provides a unified interface to different social back-ends, such as XBox Live or GameCenter", but in the implementation is not specified which social back-end is being used. How unity knows that? It switches depending on the platform?

Second: I understood in various guides that the GUI provided to show the leaderboard is directly provided by the host platform and from the console log i get these following success messages:

Authenticated, checking achievements

Error: no achievements found

Successfully reported achievement progress

but running the application in the editor, in a build made for windows or an apk used in BlueStacks, i get the same message when I call the function Social.ShowLeaderboardUI(); which is

ShowLeaderboardUI not implemented

I could expect it from the editor and the exe, but BlueStack emulates Android and i would be surprised if it doesn't provide the google play services. However i also read about a "sandbox mode" which is the one that should run in the editor and this leads to point three:

I can't find a way to set this sandbox mode, at least not from that guide.

Fourth point: Unity has a GameCenter class, but no classes for the Google Play Games Services, so: I can do what I want with iOS but I need an external plugin which implements the ISocial interface for Android?

Fifth point: How do i handle authentication in both sandbox and deploy mode?

As you can see I'm surely missing something on the coding side, conceptual side or both. Can you provide a step-by-step procedure on how to achieve what i need? I don't need to get pieces of source code, but if someone can explain me well how this API works it would be great.

Thanks in advance


Solution

  • For Android:

    To integrate Google Play Service into Unity, you need to use a plugin. You can find the Google supported plugin here. You can find information on how leaderboards work here. Essentially how it works is:

    1. You create the leaderboard in the Google Play Developer Console
    2. You submit scores to the leaderboard created (at whenever you determin is the appropriate time)
    3. Google Play Services sends a response back telling if it's a high score or not.

    I suggest you take a look at the Cubic Pilot_4.6 sample as that demonstrates how to implement leaderboards. Also, you really ought to test this on a physical device, due to how emulators may have trouble handling Google Play Services and account logins.

    As far as authentication goes, Google Play Services takes care of most of it for you. You can probably see more in the samples (Social.localUser.Authenticate).