예제 #1
0
        private static void SetMyLeaderboardRank(Leaderboard leaderboard, int rank)
        {
            LeaderboardEntry le = GetMyLeaderboardEntry(leaderboard);

            le.rank = rank;
            WriteMyLeaderboardEntry(leaderboard);
        }
예제 #2
0
        private static void SetMyLeaderboardScore(Leaderboard leaderboard, long score)
        {
            LeaderboardEntry le = GetMyLeaderboardEntry(leaderboard);

            le.score = score;
            WriteMyLeaderboardEntry(leaderboard);
        }
예제 #3
0
        public static float GetMyLeaderboardFloatScore(Leaderboard leaderboard = (Leaderboard)0)
        {
            LeaderboardEntry le = GetMyLeaderboardEntry(leaderboard);

            if (le == null)
            {
                return(0);
            }
            return(le.floatScore);
        }
예제 #4
0
        public static long GetMyLeaderboardScore(Leaderboard leaderboard = (Leaderboard)0)
        {
            LeaderboardEntry le = GetMyLeaderboardEntry(leaderboard);

            if (le == null)
            {
                return(0);
            }
            return(le.score);
        }
예제 #5
0
        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);
        }
예제 #6
0
 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);
     }
 }
예제 #7
0
        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;
            }
        }
예제 #8
0
        // 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);
            }
        }
예제 #9
0
 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;
 }