-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGooglePlay.cs
More file actions
119 lines (98 loc) · 3.65 KB
/
GooglePlay.cs
File metadata and controls
119 lines (98 loc) · 3.65 KB
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#if UZU_GOOGLEPLAY
using UnityEngine;
using System.Collections;
namespace Uzu
{
// ***************************
// TODO: Cleanup!!
// - namespace by platform?
// - folders by platform?
// - other
// ***************************
//GooglePlay service -> use this to armonise the interface with the social API
//TODO:
// Does not need to be a gameobject, but I look at the plugin code and I'm kind of worry of the timing where everything is call
// Prefere use a game object and let everything get initialise on the proper timing for now.
/*Memo how to add Achievement
To run the game, you need to configure the application ID as a resource in your Android project.
You will also need to add games metadata in the AndroidManifest.xml.
1. Open Assets/Plugins/Android/res/values/ids.xml and replace the placeholder IDs.
a. Specify your application ID in the app_id resource.
b. Specify each achievement ID that you created earlier in the
corresponding achievement_* resource.
c. Specify each leaderboard ID that you created earlier in the corresponding
leaderboard_* resource.
2. Open AndroidManifest.xml and enter your package name in the package
attribute of the <manifest> element.
*/
public class GooglePlay : SA_Singleton<GooglePlay> {
static System.Action<bool> _onAuthentication;
public void Authenticate (System.Action<bool> onAuthentication)
{
_onAuthentication = onAuthentication;
}
void Start() {
//listen for GooglePlayConnection events
GooglePlayConnection.instance.addEventListener (GooglePlayConnection.PLAYER_CONNECTED, OnPlayerConnected);
GooglePlayConnection.instance.addEventListener (GooglePlayConnection.PLAYER_DISCONNECTED, OnPlayerDisconnected);
if(GooglePlayConnection.state == GPConnectionState.STATE_CONNECTED) {
//checking if player already connected
OnPlayerConnected ();
}
//GooglePlayConnection.instance.start (GooglePlayConnection.CLIENT_GAMES | GooglePlayConnection.CLIENT_APPSTATE );
GooglePlayConnection.instance.connect ();
}
public bool IsUserAuthenticated (){
return (GooglePlayConnection.state == GPConnectionState.STATE_CONNECTED);
}
#region Show GameService
public void ShowAchievementUI ()
{
if (IsUserAuthenticated ()) {
GooglePlayManager.instance.showAchievementsUI ();
}
}
public void ShowLeaderboardUI (string leaderboardId)
{
if (IsUserAuthenticated ()) {
GooglePlayManager.instance.showLeaderBoard (leaderboardId);
}
}
#endregion
#region Score and achievement report
public void ReportScore (long score, string leaderboardID)
{
if (IsUserAuthenticated ()) {
GooglePlayManager.instance.submitScore (leaderboardID, (int)score);
}
}
public void ReportAchievementProgress (string achievementID, float progress)
{
if (IsUserAuthenticated ()) {
if(progress>=100.0f){
GooglePlayManager.instance.reportAchievement(achievementID);
}else{
GooglePlayManager.instance.incrementAchievement (achievementID, (int)progress);
}
}
}
#endregion
//--------------------------------------
// EVENTS
//--------------------------------------
private void OnPlayerDisconnected() {
}
private void OnPlayerConnected() {
//GooglePlayManager.instance.loadPlayer ();
_onAuthentication(true);
}
protected override void OnDestroy() {
if(!GooglePlayConnection.IsDestroyed) {
GooglePlayConnection.instance.removeEventListener (GooglePlayConnection.PLAYER_CONNECTED, OnPlayerConnected);
GooglePlayConnection.instance.removeEventListener (GooglePlayConnection.PLAYER_DISCONNECTED, OnPlayerDisconnected);
}
base.OnDestroy();
}
}
}
#endif // UZU_GOOGLEPLAY