TapTapTap!!!(20)~実績・ランキング機能がうまくいかない~

TapTapTap!!!(19)~デバッグ用のツールをインストールする~では『Google Play Services の動作確認は Unity 上でできない。』ためデバッグ用のツールをインストールした。今回は、Google Play Services の実績機能を実装し動作を確認する。
1日かけてGitHub にあるデータを元に試行錯誤していたが、うまく行かなかったため今回は同場所に配布されているサンプルコードを実行しつつ、実績ランキング機能を実装していきたいと思う。以下に公開している GitHub を示す。
https://github.com/playgameservices/play-games-plugin-for-unity
1.サンプル用プロジェクトを作る
プロジェクトを作る方法については Unityでゲームを開発する(2)~プロジェクトを作製する~ に記載しているため省略する。今回は「Sample」としてプロジェクトを作成する。

TapTapTap!!!(16)~Google Play Services がインポートできない~ と TapTapTap!!!(17)~Google Play Services のインポート方法~ を参考にGoogle Play Services を設定する。その後、Project タブに 「Script」フォルダを作成し、その中に「Sample」という名前のスクリプトファイルを作成する。また、Hierarchy タブ内に空の GameObject を作成し、先程作った Sample ファイルをドラッグアンドドロップする。[File] > [Bulid Setting] からプラットフォームを Android に変更するのを忘れないこと

2.サンプルプログラムのコピペ
https://github.com/playgameservices/play-games-plugin-for-unity
に含まれている、「samples\Minimal\Source\Assets\Minimal」の 「MainGui」 ファイルのソースコードをコピーアンドペーストする。
ソースコードは以下の通り。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103 /*
* Copyright (C) 2014 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
using UnityEngine;
using System.Collections;
using UnityEngine.SocialPlatforms;
public class MainGui : MonoBehaviour
{
private const float FontSizeMult = 0.05f;
private bool mWaitingForAuth = false;
private string mStatusText = "Ready.";
void Start()
{
// Select the Google Play Games platform as our social platform implementation
GooglePlayGames.PlayGamesPlatform.Activate();
}
void OnGUI()
{
GUI.skin.button.fontSize = (int)(FontSizeMult * Screen.height);
GUI.skin.label.fontSize = (int)(FontSizeMult * Screen.height);
GUI.Label(new Rect(20, 20, Screen.width, Screen.height * 0.25f),
mStatusText);
Rect buttonRect = new Rect(0.25f * Screen.width, 0.10f * Screen.height,
0.5f * Screen.width, 0.25f * Screen.height);
Rect imageRect = new Rect(buttonRect.x + buttonRect.width / 4f,
buttonRect.y + buttonRect.height * 1.1f,
buttonRect.width / 2f, buttonRect.width / 2f);
if (mWaitingForAuth)
{
return;
}
string buttonLabel;
if (Social.localUser.authenticated)
{
buttonLabel = "Sign Out";
if (Social.localUser.image != null)
{
GUI.DrawTexture(imageRect, Social.localUser.image,
ScaleMode.ScaleToFit);
}
else
{
GUI.Label(imageRect, "No image available");
}
mStatusText = "Ready";
}
else
{
buttonLabel = "Authenticate";
}
if (GUI.Button(buttonRect, buttonLabel))
{
if (!Social.localUser.authenticated)
{
// Authenticate
mWaitingForAuth = true;
mStatusText = "Authenticating...";
Social.localUser.Authenticate((bool success) =>
{
mWaitingForAuth = false;
if (success)
{
mStatusText = "Welcome " + Social.localUser.userName;
}
else
{
mStatusText = "Authentication failed.";
}
});
}
else
{
// Sign out!
mStatusText = "Signing out.";
((GooglePlayGames.PlayGamesPlatform)Social.Active).SignOut();
}
}
}
}
これでサンプルプロジェクトは完成したので、これをapk ファイルへとビルドする。そして、TapTapTap!!!(19)~デバッグ用のツールをインストールする~を参考に実行してみたがうまくいかない。一時的にでもテスト用に Google Play コンソール上でテスト用に公開しないと行けないかもしれない。