Пример #1
0
        public static void GrabScores()
        {
            var boards = Resources.FindObjectsOfTypeAll <PlatformLeaderboardViewController>().First()?.GetComponentInChildren <LeaderboardTableView>()?.gameObject?
                         .transform?.Find("Viewport")?.Find("Content")?.GetComponentsInChildren <LeaderboardTableCell>();

            if (boards != null)
            {
                foreach (LeaderboardTableCell cell in boards)
                {
                    var    cellTexts  = cell.GetComponentsInChildren <TextMeshProUGUI>();
                    string playerName = "";
                    int    pos        = -1;
                    int    score      = -1;
                    foreach (TextMeshProUGUI text in cellTexts)
                    {
                        if (text.name == "PlayerName")
                        {
                            playerName = text.text;
                            if (UI.BasicUI.simpleNames)
                            {
                                if (text.text.Contains("<size=85%>"))
                                {
                                    playerName = text.text.Split('>', '<')[2];
                                    playerName = playerName.Remove(Mathf.Clamp(playerName.Length - 3, 0, playerName.Length), 3);
                                }
                                else if (text.text.Contains("<size=75%>"))
                                {
                                    playerName = text.text.Split('<')[0];
                                    playerName = playerName.Remove(Mathf.Clamp(playerName.Length - 3, 0, playerName.Length), 3);
                                }
                            }
                        }
                        if (text.name == "Rank")
                        {
                            pos = int.Parse(text.text);
                        }
                        if (text.name == "Score")
                        {
                            score = int.Parse(text.text.Replace(" ", ""));
                        }
                    }
                    LeaderboardInfo entry = new LeaderboardInfo(playerName, score, pos);
                    if (!playerScores.Any(x => (x.playerPosition == entry.playerPosition && x.playerScore == entry.playerScore)))
                    {
                        playerScores.Add(entry);
                    }
                    //        else
                    //          Log("Entry already present");
                }
            }
            if (!playerScores.Contains(playerScore))
            {
                playerScore = new LeaderboardInfo(PlayerName, 0, 0);
                if (!playerScores.Any(x => (x.playerPosition == 0)))
                {
                    playerScores.Add(playerScore);
                }
            }

            //foreach (LeaderboardInfo entry in playerScores)
            //  {
            //      Log("Yoinking Leaderboard Entry for Position: " + entry.playerPosition);
            //      Log("Name: " + entry.playerName);
            //      Log("Score: " + entry.playerScore);
            //}
        }