Esempio n. 1
0
    IEnumerator submitScore()
    {
        string newUsername = usernameText.text;

        if (newUsername.Equals(null) || newUsername.Equals(""))
        {
            mainMenuButton.enabled    = true;
            leaderboardButton.enabled = true;
            submitButton.enabled      = true;
            yield break;
        }
        if (!oldUsername.Equals(newUsername))
        {
            yield return(signInAsUsername(newUsername));
        }

        int score = GameObject.FindObjectOfType <ScoreBetweenScenes> ().score;

        LeaderboardAPI.MatchType mType = GameObject.FindObjectOfType <ScoreBetweenScenes> ().matchType;
        yield return(api.submitScore(score, mType, () => {
            Debug.Log("Submitted score successfully to leaderboard.");
            mainMenuButton.enabled = true;
            leaderboardButton.enabled = true;
        },
                                     (error, errorData) => {
            Debug.LogError("Something went wrong while submitting a score. " + error + ", data: " + errorData.ToString());
            mainMenuButton.enabled = true;
            leaderboardButton.enabled = true;
            submitButton.enabled = true;
        }));
    }
Esempio n. 2
0
    // Use this for initialization
    void Start()
    {
        if (GameObject.FindObjectOfType <TimeBetweenScenes> ().IsComingFromEndGame)
        {
            MainMenuCanvas.SetActive(false);
            GameOverScreen.SetActive(true);

            int score = GameObject.FindObjectOfType <ScoreBetweenScenes> ().score;
            LeaderboardAPI.MatchType mType = GameObject.FindObjectOfType <ScoreBetweenScenes> ().matchType;
            api.submitScoreAsync(score, mType, () => {
                Debug.Log("Submitted score successfully to leaderboard.");
            },
                                 (error, errorData) => {
                Debug.LogError("Something went wrong while submitting a score. " + error + ", data: " + errorData.ToString());
            });


            finalScoreField.GetComponent <Text> ().text = GameObject.FindObjectOfType <ScoreBetweenScenes> ().score.ToString();
        }
    }
Esempio n. 3
0
    public void goToLeaderBoards()
    {
        sounds.GetComponent <AudioSource> ().Play();
        navigateToCertainCanvas(false, true, false, false, false, false, false);
        if (GameObject.FindObjectOfType <ScoreBetweenScenes> () == null)
        {
            // Brings the user to the default leaderboard (one minute AR) if navigating from main menu
            Leaderboards.GetComponent <LeaderboardUI> ().fetchAndDisplayScores(LeaderboardAPI.MatchType.OneMinuteAR);
        }
        else
        {
            // Brings the user to the leaderboard of the match type they were playing if they are coming from a match
            LeaderboardAPI.MatchType mType = GameObject.FindObjectOfType <ScoreBetweenScenes> ().matchType;

            if (mType == LeaderboardAPI.MatchType.OneMinuteAR)
            {
                dropDown.GetComponent <Dropdown> ().value = 0;
            }
            else if (mType == LeaderboardAPI.MatchType.ThreeMinuteAR)
            {
                dropDown.GetComponent <Dropdown> ().value = 1;
            }
            else if (mType == LeaderboardAPI.MatchType.FiveMinuteAR)
            {
                dropDown.GetComponent <Dropdown> ().value = 2;
            }
            else if (mType == LeaderboardAPI.MatchType.OneMinuteNonAR)
            {
                dropDown.GetComponent <Dropdown> ().value = 3;
            }
            else if (mType == LeaderboardAPI.MatchType.ThreeMinuteNonAR)
            {
                dropDown.GetComponent <Dropdown> ().value = 4;
            }
            else if (mType == LeaderboardAPI.MatchType.FiveMinuteNonAR)
            {
                dropDown.GetComponent <Dropdown> ().value = 5;
            }
            //Leaderboards.GetComponent<LeaderboardUI> ().fetchAndDisplayScores (GameObject.FindObjectOfType<ScoreBetweenScenes> ().matchType);
        }
    }
Esempio n. 4
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.";
     }));
 }