Game On! – Google Play Games Plugin for Unity

welcome to today’s episode of Game On! I am Bruno Oliveira, and work in
the Android Developer Relations Team. DAN GALPIN: And I’m
Dan Galpin and I also work on the Developer
Relations Team. BRUNO OLIVEIRA:
And so today we’re going to talk about the
Play Games plugin for Unity. So Unity, as you know, is one
of the most popular game engines out there. And the good news is that we
now have an official plugin that allows game developers
who are writing a Unity game to integrate that with
Google Play game services. So what is it? So if you’re writing
your game in Unity, you probably have your C#
code sitting there on one side and you want to access
the Google Play Games API. However, between you and
the API there is a gap. Notice the very
advanced water effect. DAN GALPIN: Oh, very nice. BRUNO OLIVEIRA:
In this gap there are some sharks like threading. You have to deal with threading
because Unity runs on a thread and then Google Play
Games API expects you to make calls
on the UI thread. Then there’s the
whole thing about JNI. Of course, Unity has some
pretty interesting [INAUDIBLE] to deal with it. But we still have to be careful
with return values and so on. And then there’s also some
platform-specific code that you would have to write
to access the Play Games API on Android and iOS
and so on and so forth. DAN GALPIN: I think this
is fairly harsh on sharks, really, this slide. Yes. BRUNO OLIVEIRA: Exactly. So the plugin is a way to
bridge that gap– see, bridge? As a way to bridge that gap
and get your game safely across to use the Google
Play games services. So this is why we
developed the plugin. So you can just write your game
code in C# and then not have to worry about all
of these details. So Dan, one of things that
I see in a lot of plugins is that they end up forcing you
to override your Unity Player activity and they force you
to use a particular one that’s adapted to their plugin. So if you are using a different
player activity because of some other plugin
then you’re in trouble or you have to do
horrible hacks. DAN GALPIN: So I’m glad
you asked about this. So the Google Play
games plugin does not require that you override
your base activities. Your game can use Unity’s
standard player activity or whatever other activity
class you’re already using. BRUNO OLIVEIRA: So
that’s very good news because this is
one less thing you have to do to get
this integrated. So where can I get this plugin? Well, you can download
it from our repository, and that’s the URL. So as you can see, you can
either type the full thing or this very easy to
memorize shortened version, which is– you can
memorize it like bring your own zebra. DAN GALPIN: No,
just bookmark it. BRUNO OLIVEIRA:
Just bookmark it. DAN GALPIN: But
the real question is can they get the source code? BRUNO OLIVEIRA: Oh,
the source code. So you can get the source code
in this completely different URL. Yes, it’s open-source so now you
can look to see how it works, you can break it if you want,
you can extend or customize it however you want. So it’s open source. And make sure to check
the Getting Started Guide. It’s also on that URL. DAN GALPIN: Yeah, you
might be able to use it as a reference for developing
your own implementation of Play games services on something
else outside of Unity. BRUNO OLIVEIRA: Exactly. So what exactly can
do with this plugin? Well right now you can
do sign in, of course. Otherwise it can’t
do anything else. You can get the user to sign in
to Google Play Games Services. Then you can unlock
achievements, reveal achievements,
increment achievements. You have leaderboards
so you can post the scores to leaderboards. You can to Cloud Save, which
means loading from the cloud, saving to the cloud. And you can also show
the built-in achievement and leaderboard UIs. DAN GALPIN: So
according to our docs, to use the Games API you have
to add a library project, set up your Android manifests
and a few other things, right? So how do I do
that with a plugin? BRUNO OLIVEIRA: Exactly. So the good news is
that the plugin actually does all of that for you. All you have to do is go
into the setup wizard, if you will, and fill
in your app ID there. So as soon as you fill in your
app ID, in the case of Android, it’s going to automatically
important everything they think you need for you. And this includes generating
your Android manifest, this includes importing
the Google Play services library project and
everything else you need. So for iOS, all
you have to do is enter your client ID, your
app ID, and your bundle ID and it’s going to
do the same thing. So all that boring
setup of making sure that you have the library
projects in the right place, this is all done
automatically by the plugin. So hopefully that’s going to
be much easier than having to do all of this manually. DAN GALPIN: You know, it’s
possible we made it too easy. BRUNO OLIVEIRA: Too easy? DAN GALPIN: Too easy. BRUNO OLIVEIRA: DAN
OLIVEIRA: So Unity already has a built-in social API. BRUNO OLIVEIRA: That’s true. Unity already has a
built-in social API called ISocialPlatform. So it’s actually an
abstract interface that defines a few
classes and methods. So for things like
authentication, unlocking achievements, and
posting scores to leaderboards. So the Google Play
Games plugin, rather than inventing a whole
new API, what it does is it implements
to that interface so that developers can
actually use existing code and just simply switch
it to Play Games by picking a different
implementation of that interface. So we hope that’s going
to be pretty convenient. So this is how you would
initialize a plugin. DAN GALPIN: Now that’s
not Android or iOS code. BRUNO OLIVEIRA:
That’s actually C#. But that’s the beauty
of, now that you ask. You don’t have to
know whether or not this is Android or iOS because
all the code works regardless of the platform. So the plugin takes care of
translating the ISocialPlatform calls into the
corresponding Play Games SDK in Java or Objective-C
into the corresponding platform-based SDKs
as appropriate. So you as the a
game developer don’t have to worry about
whether or not the game is running
on iOS or Android. After we’ve done
the setup for you, you have the setup wizard
for Android or iOS, that’s the last time you have
to worry about the platform differences as far as Google
Play Games is concerned. So this is pretty convenient. DAN GALPIN: That’s why classes
that start with I are cool. BRUNO OLIVEIRA: That’s true. Classes that start
with I are very cool. So this is what you have to do
to get people to authenticate. So this is the first step. You have to get people to get
authenticated with the game with Google Play Games services. So this is typically
what you would do when somebody will click
the sign-in button, right? DAN GALPIN: Yeah, but,
you know, you can also call that on startup. And this is really, really cool. We find that when you actually
pop that dialogue on startup more people are
likely to sign in. And that’s better for you,
it’s better for users, makes the users happy. So definitely
consider doing that. BRUNO OLIVEIRA:
Just make sure not to be to annoying to the user. So if the user cancels the
flow a few times that’s probably because they
don’t really want to do it. So you’re probably better off
not trying to push it too much. You don’t have a sign-in button. DAN GALPIN: Yeah. Leave a button
there in all cases. BRUNO OLIVEIRA: Exactly. Just in case they change
their minds one day. DAN GALPIN: Exactly. Their friends
might say, hey, you should be you
should be competing with me on the leaderboards,
or something like that. So make it available. BRUNO OLIVEIRA: Yes. So how do you unlock an
achievement using plugin? All they have to do is
call Social.ReportProgress. Again, this is not a
method that we made up. This is a method that is part of
the ISocialPlatform interface. So all they have to do
is call ReportProgress, then your pass in
the achievement ID. So that’s the same thing you
get from the developer console. And then you pass your callback. That’s going to
determine as a callback if there’s success or failure. Next how do you think
increment the achievement? Incrementing
achievements, you can also do it through
ReportProgress, but we do have an extension method
called IncrementAchievement, which works more
like our platform. So just pass in the
achievement ID, the number of steps you want to
increment it by, and then again a callback that
indicates success or failure. Reporting a score
is equally easy. You just call ReportScore,
conveniently enough, and you pass in the ID
of the more leaderboard that you’re going to report
it to and the score that you want to report. Again, success or failure
is in the callback. And then we also have
the built in UIs. So that you don’t have to
create the UIs yourself, we have some built
in UIs that can show using just
one line of code. So if you just want to show
the standard achievements UI, you can just call
ShowAchievementsUI, and then if you want
to show the standard leaderboard UI, same thing. Just ShowLeaderboardUI. This is what it looks
like on Android. So this is the standard
achievements UI for a game that we made called
Nostalgic Racer. So notice that I can see the
achievements that I’ve unlocked and I also see the achievements
that I have not unlocked. The corresponding screen
on iOS is like this. So same functionality
except it looks more compatible
with the platform. And we also have the
corresponding one for leaderboard. So this is an example of
leaderboard screen on Android. So it shows my friends, and
then the public leaderboards and what scores people have. And we also have
cloud save right? So Cloud Save is one of my
favorite features in games. And I think to few games
implement it nowadays. I wish all games
would implement that. DAN GALPIN: I mean,
for us we basically won’t play games unless they
have some sort of cloud save. BRUNO OLIVEIRA: Exactly. Because right now I think
more and more people live in the cloud. You’re not married
to a specific device. People change
devices all the time. I mean, devices
fall into the water and then you replace them. So all sorts of things happen
to devices, including upgrades. So when that happens
you don’t want to lose your game progress
just because of that. So Cloud Save is a pretty
important feature there, which is why we wanted to
be in the plugin as well. So the plugin, of course,
allows you to save straight into the cloud, load
saves from the cloud, and of course, you can also
handle cloud save conflicts. DAN GALPIN: Nice
icon there, yeah. Well done. BRUNO OLIVEIRA: So
loading from the cloud. So how do you go ahead and
load data from the cloud? To do that all you have
to do is call LoadState and then you pass
in– as you know, our Cloud Save
service has slots. So we currently have
four slots, so it can to have different types
of data in each of the slots. In this example we’re just
using slot zero for simplicity. Just call LoadState,
pass in the slot number, and then you pass
in a listener that’s going to be called whenever
that load operation completes. So it’s asynchronous. Saving to the cloud
is very similar. Just call UpdateState, pass
in the slot number, the data, and the listener. Notice that the data is
just a binary, so to us it is completely opaque. We have no idea what’s
inside that binary. So is your game’s responsibility
to encode the data into a binary and
then decode it later. And be careful about
different platforms and all the usual caveats about dealing
with the serialization of data. Again this is the
OnStateLoadedListener that’s going to
be called whenever the game is to be saved. So this is what the
OnStateLoadedListener looks like. Notice that there’s one
additional method there that’s called OnStateConflict. And OnStateConflict
is going to be called whenever
there’s a conflict. And a conflict happens when,
for instance, one device tries to save one state
and then a different device tried to save a different state. So this is where you want
to merge the two states and return the combined
progress to the user so the user doesn’t
lose any progress. So if they unlocked one
level, level A on one device and then level B on
different device, the result you want to
have is that the user has a unlocked levels A and
B and not one or the other. DAN GALPIN: So what happens if
you are trying to Cloud Save and you are not
connected to the net? BRUNO OLIVEIRA: So
one of the advantages of our cloud save API is that
it actually works offline. So you can have cloud save
even though there’s no cloud. Because what
happens is that when you try to save to
the cloud and you’re offline that state
that you’re saving is going to get stored
in a local cache. Then that’s going to get
synchronized to the cloud as soon as connectivity
comes back. So same thing with
loading from the cloud. So the device going to
have a cache of the last known state of the
cloud, which means that even if the
user doesn’t have an internet connection at
the moment, when you ask the device to load
from the cloud it’s going to return the last
known state that the device has cached. So this is very convenient
because, after all, mobile users are not always
connected to the internet. In the real world there are
things like parking lots and tunnels and so on. And even foreign countries
where roaming charges are very expensive. DAN GALPIN: The real
world is overrated. BRUNO OLIVEIRA: Yes, exactly. So we also have a sample
for you to play with. So if you download our source
code from the Git repository, you can also see this
Cubic Pilot sample. It’s a very simple game that
shows all of my artistic skill in creating graphics,
which essentially is just creating cubes. So as you can see, essentially
every enemy and everything in the game is just a cube
or combinations thereof. DAN GALPIN: But it’s
surprisingly fun to destroy geometry. BRUNO OLIVEIRA: Yes. Destroying geometry is a
very interesting pastime. So if you want to
destroy some geometry, definitely download that
sample and you can play it. If you want to try the Google
Play games services on it, all you have to do,
it has placeholders where you can drop in your
leaderboard IDs and achievement IDs. And so you can
actually use it to try unlocking achievements,
and posting to leaderboards and so on and so forth. And I guess that’s pretty
much all there is to it. So again where can
they get all of this? Again on this website that
we have not mentioned before. DAN GALPIN: No, not at all. BRUNO OLIVEIRA: Not at all. So bring your own
zebra– oh no, bookmark. DAN GALPIN: Yes, bookmark. BRUNO OLIVEIRA: Yes. So be sure to download
it from there. We have source code,
we have samples, we have a pretty
complete Getting Started Guide that
explains everything. We also have a zip file
with all the API docs. So for all the methods we have
documentation on what they do and so on and so forth. So it’s everything you
need to get started. If you have any questions
about this a great place post them is Stack Overflow. Be sure to tag them with
google-play-games because we actually, as a matter
of daily routine, we are checking that daily. So that’s definitely the
best place to post questions. And add me on Google+ and
feel free to nag me to answer your questions on Stack Overflow
or to fix stuff that’s broken and anything else. All right, so that’s it for
today’s Game On! episode. We hope you enjoyed it. Definitely please
download our plugin and give us any
feedback that you have. So thank you very much. DAN GALPIN: Thank you.


  1. This episode of Game On! is from @Bruno Oliveira and @Dan Galpin. Today's show covers the Google Play Games Plugin for Unity®.

    The Google Play Games plugin for Unity is an open-source plugin that allows game developers to integrate with the Google Play Games API from a game written in Unity. Learn how to add sign-in, achievements, leaderboards and cloud save to your game!

    To download the plugin: 

    Game On! – Google Play Games Plugin for Unity


  2. Guys you have failed to explain RTMP .. There are 0 tutorials online how to create just simple cube move game that joins room and sends movement position, I Have tried every possible combination to start the game but no success, everything else I managed to create in 1 pass… Can you share some knowledge based on that… 

  3. Everything is working fine, but when I try to build the apk file, I get this error:

    Error building Player: CommandInvokationFailure: Failed to recompile android resource files. See the Console for details.
    C:Program Files (x86)Javajre7binjavac.exe -bootclasspath "C:/Users/Ted/android-sdks/platforms/android-19android.jar" -d "C:UsersTedDesktopClony BirdTempStagingAreabinclasses" -source 1.6 -target 1.6 -encoding ascii "" "" "" ""

    I've searched google, but to no avail. Anybody have any idea what's wrong? 

  4. Ok Ive had some success with this plugin. You first need to make sure all the manifests say the same minimum and target sdk versions for example minimum, 9 target 19, in both manifests. I may do a tutorial on this pluigin when its fully working

  5. Not working well for me.  Despite seeing confirmations in adb logcat of submitted highscores, they never appear.  Also the leaderboard isn't loading =/

  6. Will this plugin be updated soon? The new release of Google Play Services seems to not work with this plugin.

  7. The login works but authenticate always returns false, thus the user cant see leaderboards, achievements, etc.

     AndroidJavaException: java.lang.NoSuchMethodError: no method with name='getClass' signature='()Ljava/lang/Object;' in class Lcom/google/android/gms/common/api/b;

  8. why i always get IO error, it said i don';t have projectsettings.txt on my project folder, even tho i didn't edit anything on the plugin

Leave a Reply

(*) Required, Your email will not be published