using System; using System.Collections; using System.Collections.Generic; using System.Linq; using UnityEngine; using UnityEngine.Events; using UnityEngine.UI; public class LeaderboardController : MonoBehaviour { [SerializeField] private RectTransform _content; [SerializeField] private LeaderboardEntry _leaderboardEntryPrefab; [SerializeField] private InputField _nameInputField; private List _entries = new List(); private void Start() { UpdateLeaderboard(); } private void UpdateLeaderboard() { _entries.ForEach(x => Destroy(x.gameObject)); _entries.Clear(); _entries = new List(); var sortedList = PlayerSetup.Instance.PlayerInfo.Players.OrderByDescending(x => x.Score).ToList(); for (int i = 0; i < sortedList.Count; i++) { var newEntry = Instantiate(_leaderboardEntryPrefab, _content); _entries.Add(newEntry); newEntry.Init(sortedList[i], i); } } [ContextMenu("Debug submit")] public void SubmitNewEntry() { PlayerSetup.Instance.SetPlayerName(_nameInputField.text); UpdateLeaderboard(); } }