TapTapTap!!!(37)~実績機能やイベント機能を実装する~

TapTapTap!!!(36)~Google Play Service for Unity をインポートする続き~でようやく、Google Play Service と Unity の連携を行う事ができた。今回は、Google Play コンソールで登録した実績やイベント、リーダーボードを実装する。
イベントやリーダーボードの追加方法についてはTapTapTap!!!(18)~実績・ランキング機能を準備する~で記載している省略する。
1.実績機能を組み込む
イベントやリーダーボードの追加後まずは、GooglePlayGames 用のスクリプトを作成する。内容としては、各イベントのIDを適したタイミングで出力することである。サンプルとして以下のスクリプトを作成した。
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 using GooglePlayGames.BasicApi;
using System.Reflection;
using UnityEngine;
public static class GooglePlayUtility
{
/// <summary>
/// GooglePlayGames の開始
/// </summary>
public static void StartGooglePlayGames()
{
// Google Play Games を有効化
GooglePlayGames.PlayGamesPlatform.Activate();
// Google Play Games へのログイン
Social.localUser.Authenticate((bool success) =>
{
((GooglePlayGames.PlayGamesPlatform)Social.Active).SetGravityForPopups(Gravity.TOP);
});
}
/// <summary>
/// 連続タップした
/// </summary>
public static void ContinuityTap(int count)
{
if (count == 8)
{
GooglePlayAchievement("CgkI2puh8aQaEAIQBQ");
}
else if (count == 50)
{
GooglePlayAchievement("CgkI2puh8aQaEAIQ");
}
else if (count == 100)
{
GooglePlayAchievement("CgkI2puh8aQaEAIQBw");
}
}
/// <summary>
/// レベルが到達した
/// </summary>
public static void ReachedLEVEL(int level)
{
if (level == 8)
{
GooglePlayAchievement("CgkI2puh8aQaEAIQBg");
}
else if (level == 50)
{
GooglePlayAchievement("CgkI2puh8aQaEAIQCA");
}
else if (level == 100)
{
GooglePlayAchievement("CgkI2puh8aQaEAIQCQ");
}
}
/// <summary>
/// プレイ回数
/// </summary>
public static void PlayAnyTimes()
{
// 5回プレイした
GooglePlayIncrementAchievement("CgkI2puh8aQaEAIQDQ", 20);
// 10回プレイした
GooglePlayIncrementAchievement("CgkI2puh8aQaEAIQDg", 10);
}
/// <summary>
/// GooglePlayGames 実績解除
/// </summary>
/// <param name="id">実績 ID</param>
private static void GooglePlayAchievement(string id)
{
// Google Play Games を有効化
Social.ReportProgress(id, 100.0f, (bool success) =>
{
((GooglePlayGames.PlayGamesPlatform)Social.Active).SetGravityForPopups(Gravity.TOP);
});
}
/// <summary>
/// GooglePlayGames 実績解除
/// </summary>
/// <param name="id">実績 ID</param>
private static void GooglePlayIncrementAchievement(string id, int increment)
{
// Google Play Games の実績解除
Social.ReportProgress(id, increment, (bool success) =>
{
((GooglePlayGames.PlayGamesPlatform)Social.Active).SetGravityForPopups(Gravity.TOP);
});
}
}
2.実機で動作確認を行う
しかしながらリーダーボードや実績の表示画面を作成していなかったため、実機では確認を行うことができなかった。次回はリーダーボードや実績の確認画面等を作成する。