public void TransformTable() { string jsonString = PlayerPrefs.GetString("highscoreTable"); if (String.IsNullOrEmpty(jsonString)) { return; } GameBehavior.Highscores highscores = JsonUtility.FromJson <GameBehavior.Highscores>(jsonString); for (int i = 0; i < highscores.highscoreEntryList.Count; i++) { for (int j = i + 1; j < highscores.highscoreEntryList.Count; j++) { if (highscores.highscoreEntryList[j].score < highscores.highscoreEntryList[i].score) { GameBehavior.HighscoreEntry tmp = highscores.highscoreEntryList[i]; highscores.highscoreEntryList[i] = highscores.highscoreEntryList[j]; highscores.highscoreEntryList[j] = tmp; } } } highscoreEntryTransformList = new List <Transform>(); foreach (GameBehavior.HighscoreEntry highscoreEntry in highscores.highscoreEntryList) { CreateHighScoreEntryTransform(highscoreEntry, entryContainer, highscoreEntryTransformList); } }
public void CreateHighScoreEntryTransform(GameBehavior.HighscoreEntry highscoreEntry, Transform container, List <Transform> transformList) { float templateHeight = 80f; Transform entryTransform = Instantiate(entryTemplate, container); RectTransform entryRectTransform = entryTransform.GetComponent <RectTransform>(); entryRectTransform.anchoredPosition = new Vector2(0, -templateHeight * transformList.Count); entryTransform.gameObject.SetActive(true); string name = highscoreEntry.name; entryTransform.Find("nameText").GetComponent <Text>().text = name; transformList.Add(entryTransform); }