private static void SetMyLeaderboardRank(Leaderboard leaderboard, int rank) { LeaderboardEntry le = GetMyLeaderboardEntry(leaderboard); le.rank = rank; WriteMyLeaderboardEntry(leaderboard); }
private static void SetMyLeaderboardScore(Leaderboard leaderboard, long score) { LeaderboardEntry le = GetMyLeaderboardEntry(leaderboard); le.score = score; WriteMyLeaderboardEntry(leaderboard); }
public static float GetMyLeaderboardFloatScore(Leaderboard leaderboard = (Leaderboard)0) { LeaderboardEntry le = GetMyLeaderboardEntry(leaderboard); if (le == null) { return(0); } return(le.floatScore); }
public static long GetMyLeaderboardScore(Leaderboard leaderboard = (Leaderboard)0) { LeaderboardEntry le = GetMyLeaderboardEntry(leaderboard); if (le == null) { return(0); } return(le.score); }
private static void WriteMyLeaderboardEntry(Leaderboard leaderboard = (Leaderboard)0) { LeaderboardEntry le = GetMyLeaderboardEntry(leaderboard); if (le == null) // Just in case { return; } PlayerPrefs.SetString(PREF_MY_LEADERBOARD_SCORE + leaderboard.ToString(), le.prefData); }
private static void ReadMyLeaderboardScores() { for (int i = 0, imax = EnumUtils.GetCount <Leaderboard>(); i < imax; i++) { Leaderboard l = (Leaderboard)i; string rawData = PlayerPrefs.GetString(PREF_MY_LEADERBOARD_SCORE + l, "You|11|0"); string[] rawDataArray = rawData.Split('|'); _myLeaderboardEntries[(int)l] = new LeaderboardEntry(rawDataArray); } }
private void AddTopScore(string[] scoreData, Leaderboard leaderboard = (Leaderboard)0, TimeScope timeScope = TimeScope.AllTime) { if (!LeaderboardEntry.CheckRawDataValid(scoreData)) // Data not valid, skip it, this should not be happens excepts no top scores in newly made leaderboards { Debug.LogWarning("ScoreManager:AddTopScore - scoreData invalid: " + scoreData); return; } switch (timeScope) { case TimeScope.AllTime: _topScoresAllTimeDict[leaderboard].Add(new LeaderboardEntry(scoreData)); break; case TimeScope.Week: _topScoresWeekDict[leaderboard].Add(new LeaderboardEntry(scoreData)); break; default: case TimeScope.Today: _topScoresTodayDict[leaderboard].Add(new LeaderboardEntry(scoreData)); break; } }
// Compares the player score with the leaderboard, and do update if neccessary, for offline only // If online and connected to Game Center / Play Games, this is not neccessary and new downloaded leaderboard will override this private static void CompareScoreToLeaderboard(Leaderboard leaderboard = (Leaderboard)0, TimeScope timeScope = TimeScope.AllTime) { if (!instanceExists) { return; } if (instance.debugMode) { Debug.LogFormat("LeaderboardManager:CompareScoreToLeaderboard({0},{1})", leaderboard, timeScope); } List <LeaderboardEntry> topScores = GetTopScores(leaderboard, timeScope); LeaderboardEntry myLeaderboardEntry = GetMyLeaderboardEntry(leaderboard); int loadTopScoreCount = topScores.Count; int myRank = GetMyLeaderboardRank(leaderboard, timeScope); bool topScoresChanged = myRank <= loadTopScoreCount; if (topScoresChanged) // Update my rank row first { topScores[myRank - 1] = new LeaderboardEntry(GetMyLeaderboardEntry(leaderboard), myRank); } for (int i = Mathf.Min(loadTopScoreCount, myRank - 1) - 1; i >= 0; i--) // From either my upper rank, or top scores bottom, check toward top { LeaderboardEntry le = topScores[i]; // This top score entry if (GetMyLeaderboardScore(leaderboard) <= le.score) // Not better than this top score, just break { break; } topScoresChanged = true; int newRank = i + 1; // i >= 0 but rank >= 1, so +1 if (timeScope == TimeScope.AllTime) { SetMyLeaderboardRank(leaderboard, newRank); } topScores[i] = new LeaderboardEntry(myLeaderboardEntry, newRank); Debug.Log(i + "|" + topScores[i]); // Move the ranks down if (i == loadTopScoreCount - 1) // Skip if the bottom { continue; } topScores[i + 1] = new LeaderboardEntry(le, newRank + 1); } if (instance.debugMode) { Debug.LogFormat("LeaderboardManager:CompareScoreToLeaderboard - topScoresChanged={0}", topScoresChanged); } if (topScoresChanged) { SetTopScores(leaderboard, timeScope, topScores); // Do a update too, the online score may also get changed DownloadLeaderboardTopScores(leaderboard, timeScope); } }
private static void SetMyLeaderboardEntry(Leaderboard leaderboard, LeaderboardEntry leaderboardEntry) { _myLeaderboardEntries[(int)leaderboard] = leaderboardEntry; WriteMyLeaderboardEntry(leaderboard); }
public LeaderboardEntry(LeaderboardEntry orig, int r) { name = orig.name; rank = r; score = orig.score; }