Beispiel #1
0
 public void fetchAndDisplayScores(LeaderboardAPI.MatchType matchType)
 {
     foreach (Transform child in scoresContentContainer.transform)
     {
         Destroy(child.gameObject);
     }
     scoresContainer.SetActive(false);
     loadingText.enabled = true;
     StartCoroutine(api.getLeaderboard(1, matchType, (scores) => {
         if (scores.Count == 0)
         {
             loadingText.text = "There are no scores for this match type!";
             return;
         }
         loadingText.enabled = false;
         scoresContainer.SetActive(true);
         RectTransform scoreContainerTransform   = scrollViewport.GetComponent <RectTransform>();
         RectTransform contentContainerTransform = scoresContentContainer.GetComponent <RectTransform>();
         float containerWidth  = scoreContainerTransform.rect.width;
         float containerHeight = scoreContainerTransform.rect.height;
         float textHeight      = containerHeight / 10;
         float contentHeight   = textHeight * scores.Count;
         contentContainerTransform.sizeDelta = new Vector2(1, contentHeight);
         for (int i = 0; i < scores.Count; i++)
         {
             LeaderboardAPI.LeaderboardScore score = scores[i];
             GameObject text = Instantiate(leaderboardTextObject) as GameObject;
             text.transform.SetParent(scoresContentContainer.transform, false);
             Text txt = text.GetComponent <Text>();
             txt.text = (i + 1) + ". " + score.username + " : " + score.score;
         }
     }, (error, errorData) => {
         Debug.LogError("Leaderboard score retrieval failed");
         loadingText.text = "An error occurred trying to retrieve the scores.";
     }));
 }
Beispiel #2
0
    IEnumerator doLogin(LeaderboardAPI api)
    {
        bool success = false;

        yield return(api.logInPlayer("james", "password1", () => {
            Debug.Log("Success! We logged in as james.");
            success = true;
        }, logFailure));

        if (!success)
        {
            yield break;
        }
        yield return(api.submitScore(6000, LeaderboardAPI.MatchType.OneMinuteAR, () => {
            Debug.Log("Score submitted successfully.");
        }, logFailure));

        yield return(api.getLeaderboard(0, (scores) => {
            foreach (LeaderboardAPI.LeaderboardScore score in scores)
            {
                Debug.Log("Retrieved a new score: " + score.score + " for match type " + score.type.ToString());
            }
        }, logFailure));
    }