IEnumerator DisplayScores(int maxToDisplay)
    {
        //GUILayout.Label("High Scores:");
        List <DreamloLeaderBoard.Score> scoreList;

        do
        {
            scoreList = LeaderBoard.ToListHighToLow();
            yield return(null);
        }while (scoreList == null);

        int count           = 0;
        var LeaderBoardText = LeaderBoardScores.GetEnumerator();

        LeaderBoardText.MoveNext();

        foreach (DreamloLeaderBoard.Score s in scoreList)
        {
            count++;
            int    min  = Mathf.FloorToInt(s.seconds / 60);
            int    sec  = Mathf.FloorToInt(s.seconds % 60);
            string time = min.ToString("00") + ":" + sec.ToString("00");
            LeaderBoardText.Current.text = string.Format("{0}: {1}, Score: {2}, Time: {3}", s.LeaderBoardPos, s.playerName, s.score, time);
            LeaderBoardText.MoveNext();

            if (count >= maxToDisplay)
            {
                break;
            }
        }

        yield return(null);
    }
Esempio n. 2
0
    public void LoadScores()
    {
        List <Score> scores = new List <Score>();

        foreach (DreamloLeaderBoard.Score score in _dreamLoLB.ToListHighToLow())
        {
            Score simpleScore = Score.FromDreamLoScore(score);
            scores.Add(simpleScore);
        }
        CurrentScores = scores;
    }
    void OnGUI()
    {
        GUILayoutOption[] width200 = new GUILayoutOption[] { GUILayout.Width(200) };

        float width  = 400;         // Make this wider to add more columns
        float height = 200;

        Rect r = new Rect((Screen.width / 2) - (width / 2), (Screen.height / 2) - (height), width, height);

        GUILayout.BeginArea(r, new GUIStyle("box"));

        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...
                if (dl.publicCode == "")
                {
                    Debug.LogError("You forgot to set the publicCode variable");
                }
                if (dl.privateCode == "")
                {
                    Debug.LogError("You forgot to set the privateCode variable");
                }

                dl.AddScore(this.playerName, totalScore);

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

        if (this.gs == gameState.leaderboard)
        {
            GUILayout.Label("High Scores:");
            List <DreamloLeaderBoard.Score> scoreList = dl.ToListHighToLow();

            if (scoreList == null)
            {
                GUILayout.Label("(loading...)");
            }
            else
            {
                int maxToDisplay = 20;
                int count        = 0;
                foreach (DreamloLeaderBoard.Score currentScore in scoreList)
                {
                    count++;
                    GUILayout.BeginHorizontal();
                    GUILayout.Label(currentScore.playerName, width200);
                    GUILayout.Label(currentScore.score.ToString(), width200);
                    GUILayout.EndHorizontal();

                    if (count >= maxToDisplay)
                    {
                        break;
                    }
                }
            }
        }
        GUILayout.EndArea();
    }