Ejemplo n.º 1
0
 public ScoreEntry(int rank, string name, int score)
 {
     this.rank  = rank;
     this.name  = name;
     this.score = score;
     line       = null;
 }
Ejemplo n.º 2
0
    // Messages:

    IEnumerator Start()
    {
        WWW request = new WWW("https://dollarone.games/elympics/getHighscores?username=hitchh1k3r&unique=true");

        yield return(request);

        if (string.IsNullOrEmpty(request.error))
        {
            List <ScoreEntry> newScores = new List <ScoreEntry>();
            HighScoreData     data      = JsonUtility.FromJson <HighScoreData>("{\"scores\":" + request.text + "}");
            int count = 0;
            for (int i = 0; i < data.scores.Length; ++i)
            {
                if (data.scores[i].score > 0 && data.scores[i].name != null &&
                    data.scores[i].name.Trim() != "")
                {
                    if (++count > 15)
                    {
                        newScores.Add(new ScoreEntry(0, data.scores[i].name, data.scores[i].score));
                    }
                }
            }
            newScores.Sort((x, y) => (y.score - x.score));
            scores = newScores.ToArray();
            int rank      = 1;
            int runRank   = 1;
            int lastScore = int.MaxValue;
            for (int i = 0; i < scores.Length; ++i)
            {
                if (lastScore > scores[i].score)
                {
                    rank      = runRank;
                    lastScore = scores[i].score;
                }
                scores[i].rank = rank;
                ++runRank;
            }
        }

        for (int i = 0; i < 25 && i < scores.Length; ++i)
        {
            GameObject     newScore = Instantiate(scoreEntry);
            ScoreEntryLine line     = newScore.GetComponent <ScoreEntryLine>();
            scores[i].line = line;
            newScore.transform.SetParent(transform);
            RectTransform rTrans = (RectTransform)newScore.transform;
            rTrans.localScale = Vector3.one;
            rTrans.offsetMin  = new Vector2(10, -45 - (i * 35));
            rTrans.offsetMax  = new Vector2(-20, -15 - (i * 35));
            DrawScore(scores[i]);
        }

        yield break;
    }