Beispiel #1
0
    public IEnumerator leaderboard()
    {
        GooglePlayServiceManager.signIn();

        //Disabling button
        button.enabled     = false;
        crownImage.enabled = false;
        loadingImage.SetActive(true);

        //Waiting till sign-in process is complete, then renabling the button
        yield return(new WaitUntil(() => GooglePlayServiceManager.hasTriedToSignIn));

        button.enabled     = true;
        crownImage.enabled = true;
        loadingImage.SetActive(false);

        GooglePlayServiceManager.showHighScoreBoard();
    }
Beispiel #2
0
    //Called externally when player dies
    public void calculateHighScore(int endgameScore)
    {
        if (!GooglePlayServiceManager.hasTriedToSignIn)
        {
            GooglePlayServiceManager.signIn();
        }

        if (!GooglePlayServiceManager.hasCachedHiScore &&
            !GooglePlayServiceManager.isRetrievingHiScore)
        {
            GooglePlayServiceManager.retrieveHighScore();
        }


        //This may not return the value immediately, since retrieveHighScore() is asynchronous and it's speed depends on the user's internet speed
        //May take a few player deaths before this kicks in, but that's okay.
        if (GooglePlayServiceManager.hasCachedHiScore)
        {
            leaderboardHiScore = GooglePlayServiceManager.cachedLeaderboardScore;
        }

        /*
         * This was done to make sure that the highest score among the local and leaderboard high scores is the score being considered
         * Because sometimes the player may make a new high score while not connected to the internet
         * This also allows high scores to remain synched when two people are playing with two different devices with the same account
         */
        currentHighScore = Mathf.Max(currentHighScore, leaderboardHiScore);
        if (endgameScore > currentHighScore)
        {
            currentHighScore = endgameScore;
        }
        internalMemory.saveHiScore(currentHighScore);
        if (leaderboardHiScore != currentHighScore)
        {
            GooglePlayServiceManager.postHighScore(currentHighScore);
            leaderboardHiScore = currentHighScore; //That may not seem necessary, but it ensures that it only posts when there is a new high score
        }
    }