private void GenerateReport()
    {
        LeaderBoardReport report     = new LeaderBoardReport();
        Label             errorLabel = report.Q <Label>("Error");

        report.Setup();

        report.Q <Button>("Back").RegisterCallback <ClickEvent>(e =>
        {
            SceneManager.LoadScene(0);
        });

        uiDocument.rootVisualElement.Q("Root").Add(report);

        StartCoroutine(BackendlessHelper.GetAll(Populate));

        void Populate(TableData data, string error)
        {
            if (data != null)
            {
                if (data.data.Length <= 0)
                {
                    errorLabel.text = "Nothing to show";
                }
                else
                {
                    errorLabel.RemoveFromHierarchy();
                }

                Debug.Log($"Received table data with {data.data.Length} elements", this);
                foreach (PlayerRecord p in data.data)
                {
                    bool isMe = p.Player_Name == System.Environment.UserName;
                    LeaderBoardRecord element = GenerateRecord(isMe, p.Player_Name, p.Total_Kills, p.Total_Levels);

                    report.Q <VisualElement>("Records").Add(element);
                }
            }
            else
            {
                errorLabel.text = error;
            }
        }
    }
示例#2
0
 /// <summary>
 /// Updates the backendless record by adding the sepcified <paramref name="killsToAdd"/> and <paramref name="levelsToAdd"/>
 /// </summary>
 /// <param name="playerName">The identifying name of the client</param>
 /// <param name="killsToAdd">Number of kills to add</param>
 /// <param name="levelsToAdd">Nunber of levels to add</param>
 public void AddScore(string playerName, int killsToAdd, int levelsToAdd)
 {
     this.StartCoroutine(BackendlessHelper.GetRecord(BackendlessHelper.URIByName(playerName), (player, errors) =>
     {
         if (player == null)
         {
             var newPlayer = new PostPlayerRecord()
             {
                 Player_Name  = playerName,
                 Total_Kills  = killsToAdd,
                 Total_Levels = levelsToAdd,
             };
             this.StartCoroutine(BackendlessHelper.PostRecord(newPlayer));
         }
         else
         {
             player.Total_Kills  += killsToAdd;
             player.Total_Levels += levelsToAdd;
             this.StartCoroutine(BackendlessHelper.PutRecord(player));
         }
     }));
 }