Esempio n. 1
0
    IEnumerator populateLeaderboard()
    {
        dreamloLeaderBoard.Score[] scoresArray = leaderboard.ToScoreArray();
        if (scoresArray.Length > 0)
        {
            int    remainingDots;
            string dots   = "";
            int    length = scoresArray.Length;
            for (int i = 1; i <= length; i++)
            {
                dots          = "";
                remainingDots = MAX_CHARACTERS_IN_LEADERBOARD_ROW - scoresArray [i - 1].playerName.Length - i.ToString().Length - 8;
                for (int j = 0; j < remainingDots; j++)
                {
                    dots += ".";
                }
                leaderboardResults.text += i + ". " + scoresArray [i - 1].playerName + " " + dots + " " + scoresArray[i - 1].score + "\n";
            }
        }
        yield return(new WaitForFixedUpdate());

        leaderboardWrapper.sizeDelta = new Vector2(leaderboardResults.rectTransform.rect.width, leaderboardResults.rectTransform.rect.height);
    }
Esempio n. 2
0
    void OnGUI()
    {
        GUILayoutOption[] width200 = new GUILayoutOption[] { GUILayout.Width(200) };

        GUILayout.BeginArea(new Rect((Screen.width / 2) - 200, (Screen.height / 2) - 100, 400, 200));

        GUILayout.BeginVertical();
        GUILayout.Label("Time Left:" + this.timeLeft.ToString("0.000"));
        if (this.gs == gameState.waiting || this.gs == gameState.running)
        {
            if (GUILayout.Button("Click me as much as you can in " + this.startTime.ToString("0") + " seconds!"))
            {
                this.totalScore++;
                this.gs = gameState.running;
            }

            GUILayout.Label("Total Score: " + this.totalScore.ToString());
        }



        if (this.gs == gameState.enterscore)
        {
            GUILayout.Label("Total Score: " + this.totalScore.ToString());
            GUILayout.BeginHorizontal();
            GUILayout.Label("Your Name: ");
            this.playerName = GUILayout.TextField(this.playerName, width200);

            if (GUILayout.Button("Save Score"))
            {
                // add the score...
                dl.AddScore(this.playerName, totalScore);

                this.gs = gameState.leaderboard;
            }
            GUILayout.EndHorizontal();
        }

        if (this.gs == gameState.leaderboard)
        {
            GUILayout.Label("High Scores:");
            dreamloLeaderBoard.Score[] scoreList = dl.ToScoreArray();

            if (scoreList == null)
            {
                GUILayout.Label("(loading...)");
            }
            else
            {
                foreach (dreamloLeaderBoard.Score currentScore in scoreList)
                {
                    GUILayout.BeginHorizontal();
                    GUILayout.Label(currentScore.playerName, width200);
                    GUILayout.Label(currentScore.score.ToString(), width200);
                    GUILayout.EndHorizontal();
                }
            }
        }

        GUILayout.EndVertical();
        GUILayout.EndArea();
    }