[Unity] Google Play Game Service CodeLab ( Step by Step )



Google Play Overview

1. Open CodeLab
2. Download Sample Game & Google Play Service Plugin
3. Google Play Console: Add new testing App
4. Set Bundle ID & SHA1
5. Set Achievements & LeaderBoards
6. Set testing accounts

Unity Overview

1. Import Lollygager Sample Game & Google Player Service Plugin
2. Set Google Play Service Android Configuration
3. Implement UI & code from CodeLab
4. Build & Test


Open CodeLab
Download Sample Game & Google Play Service Plugin

[Unity] Google Play Service

Import Lollygagger Sample Game

[Unity] Google Play Service

Set Bundle Identifier

You can create whatever you want, here just using GooglePlayService.

[Unity] Google Play Service

Add Scenes

Put MainMenu & GameScene into Build Settings, be sure to put MainMenu for the first one.

[Unity] Google Play Service

Create new App in Google Play Console

Like the ending of Bundle ID, here just named "GooglePlayService" for testing, then switch to Game Service settings.

[Unity] Google Play Service

[Unity] Google Play Service

[Unity] Google Play Service

Link Android Application

There are two major things for linking your mobile APK:
1. Bundle ID
2. SHA1

We already have Bundle ID, and you can generate SHA1 by debug keystore or any keystore you have.

Since windows command line can't copy text, so you can add > Certificate.txt to export certificate informations into another file. Make a backup and reuse it.

keytool -list -v -keystore ./yourKey.keystore -alias yourAlias > Certificate.txt

[Unity] Google Play Service

[Unity] Google Play Service

Get Client ID

You'll get a Client ID after setting successfully.

[Unity] Google Play Service

Set Achievements & LeaderBoards

Let's follow the CodeLab's steps, setup achievements & leaderboards for the sample lollygager game.

[Unity] Google Play Service

[Unity] Google Play Service

[Unity] Google Play Service

Retrive Resource XML

After setup, you can retrive resource XML from the bottom of Achievement page or LeaderBoard page.

[Unity] Google Play Service

[Unity] Google Play Service

Add testing accounts

[Unity] Google Play Service

Import Google Play Service Plugin

[Unity] Google Play Service

Open Google Play Setting

Window => Google Play Games => Setup => Android setup...

[Unity] Google Play Service

Google Play Configuration

There are three things need to be set:

1. Contants class name: Whatever, here just use GooglePlayService
2. Resources Definition: Copy from the achievement page or leaderboard page form Google Console
3. Web App Client ID (Optional): No need for using Game Services.

[Unity] Google Play Service

[Unity] Google Play Service

UI Setting

The MainMenu Scene only contains Start button by default. So you need to drag Login, Show Achievement and Show LeaderBoard buttons into the Scene, and bind there events.

[Unity] Google Play Service

Google Play Service API

Now, it's time to implement Google Play Service API. Just follow the CodeLab.

Initialize:

    PlayGamesClientConfiguration config = new PlayGamesClientConfiguration.Builder().Build();
    PlayGamesPlatform.DebugLogEnabled = true;
    PlayGamesPlatform.InitializeInstance(config);
    PlayGamesPlatform.Activate();

Authenticate:
Using the boolean flag to do silent login or not.

    PlayGamesPlatform.Instance.Authenticate( SignInCallback, false );

Achievements & LeaderBoards

    // Show Achievement
    PlayGamesPlatform.Instance.ShowAchievementsUI();

    // Update Achievement progress
    PlayGamesPlatform.Instance.ReportProgress( AchieveID, progress, callback );
    PlayGamesPlatform.Instance.IncrementAchievement( AchieveID, steps, callback );

    // Show LeaderBoard
    PlayGamesPlatform.Instance.ShowLeaderboardUI();

    // Update user score
    PlayGamesPlatform.Instance.ReportScore( score, ID, callback );
Build & Test

If you still get problems, check the following points

1. Bundle ID : Unity == Console ?
2. Keystore: Unity == Console ?
3. Testing accounts ?

[Unity] Google Play Service

[Unity] Google Play Service

[Unity] Google Play Service

[Unity] Google Play Service

[Unity] Google Play Service

Reference

Google Play Game Services
Plugin for Unity (Github)




歡迎您留言與分享!(Welcome for comments or sharing!)

Related Post:

Tagged on: ,