-
Notifications
You must be signed in to change notification settings - Fork 0
/
LeaderboardBehaviour.cs
129 lines (124 loc) · 6.22 KB
/
LeaderboardBehaviour.cs
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
120
121
122
123
124
125
126
127
128
129
using LootLocker.Requests;
using System.Collections;
using UnityEngine;
namespace SametHope.RapidLeaderboard
{
/// <summary>
/// A MonoBehaviour class responsible for handling rapid leaderboard-related operations by utilizing coroutines in runtime.
/// </summary>
public class LeaderboardBehaviour : MonoBehaviour
{
/// <summary>
/// Starts a guest session asynchronously and invokes the specified callbacks on success or failure.
/// </summary>
/// <param name="onSuccess">Callback to invoke when the guest session is successfully started.</param>
/// <param name="onFailure">Callback to invoke if starting the guest session fails.</param>
internal IEnumerator Co_StartSessionAsGuest(System.Action<LootLockerGuestSessionResponse> onSuccess = null, System.Action<LootLockerGuestSessionResponse> onFailure = null)
{
bool responseReceived = false;
LootLockerSDKManager.StartGuestSession((response) =>
{
if (!response.success)
{
responseReceived = true;
onFailure?.Invoke(response);
return;
}
responseReceived = true;
onSuccess?.Invoke(response);
});
yield return new WaitWhile(() => responseReceived == false);
}
/// <summary>
/// Sets the player name asynchronously and invokes the specified callbacks on success or failure.
/// </summary>
/// <param name="nameToSet">The name to set for the player.</param>
/// <param name="onSuccess">Callback to invoke when the player name is successfully set.</param>
/// <param name="onFailure">Callback to invoke if setting the player name fails.</param>
internal IEnumerator Co_SetPlayerName(string nameToSet, System.Action<PlayerNameResponse> onSuccess = null, System.Action<PlayerNameResponse> onFailure = null)
{
bool responseReceived = false;
LootLockerSDKManager.SetPlayerName(nameToSet, (response) =>
{
if (!response.success)
{
responseReceived = true;
onFailure?.Invoke(response);
return;
}
responseReceived = true;
onSuccess?.Invoke(response);
});
yield return new WaitWhile(() => responseReceived == false);
}
/// <summary>
/// Submits the player's score asynchronously to the specified leaderboard and invokes the specified callbacks on success or failure.
/// </summary>
/// <param name="memberId">The ID of the player whose score is being submitted.</param>
/// <param name="score">The score to submit.</param>
/// <param name="leaderboardKey">The key identifying the leaderboard.</param>
/// <param name="onSuccess">Callback to invoke when the score submission is successful.</param>
/// <param name="onFailure">Callback to invoke if the score submission fails.</param>
internal IEnumerator Co_SubmitScore(string memberId, int score, string leaderboardKey, System.Action<LootLockerSubmitScoreResponse> onSuccess = null, System.Action<LootLockerSubmitScoreResponse> onFailure = null)
{
bool responseReceived = false;
LootLockerSDKManager.SubmitScore(memberId, score, leaderboardKey, (response) =>
{
if (!response.success)
{
responseReceived = true;
onFailure?.Invoke(response);
return;
}
responseReceived = true;
onSuccess?.Invoke(response);
});
yield return new WaitWhile(() => responseReceived == false);
}
/// <summary>
/// Coroutine that retrieves a list of scores from the specified leaderboard asynchronously.
/// </summary>
/// <param name="leaderboardKey">The key identifying the leaderboard.</param>
/// <param name="count">The number of scores to retrieve.</param>
/// <param name="onSuccess">Callback to invoke when the scores are successfully retrieved.</param>
/// <param name="onFailure">Callback to invoke if retrieving the scores fails.</param>
internal IEnumerator Co_GetScoreList(string leaderboardKey, int count, System.Action<LootLockerGetScoreListResponse> onSuccess = null, System.Action<LootLockerGetScoreListResponse> onFailure = null)
{
bool responseReceived = false;
LootLockerSDKManager.GetScoreList(leaderboardKey, count, (response) =>
{
if (!response.success)
{
responseReceived = true;
onFailure?.Invoke(response);
return;
}
responseReceived = true;
onSuccess?.Invoke(response);
});
yield return new WaitWhile(() => responseReceived == false);
}
/// <summary>
/// Coroutine that retrieves the rank of the player from the specified leaderboard asynchronously.
/// </summary>
/// <param name="leaderboardKey">The key identifying the leaderboard.</param>
/// <param name="onSuccess">Callback to invoke when the player's rank is successfully retrieved.</param>
/// <param name="onFailure">Callback to invoke if retrieving the player's rank fails.</param>
internal IEnumerator Co_GetMemberRank(string leaderboardKey, System.Action<LootLockerGetMemberRankResponse> onSuccess = null, System.Action<LootLockerGetMemberRankResponse> onFailure = null)
{
bool responseReceived = false;
LootLockerSDKManager.GetMemberRank(leaderboardKey, LeaderboardManager.PlayerID, (response) =>
{
if (!response.success)
{
responseReceived = true;
onFailure?.Invoke(response);
return;
}
responseReceived = true;
onSuccess?.Invoke(response);
});
yield return new WaitWhile(() => responseReceived == false);
}
}
}