using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class RankListPanel : MonoBehaviour { [SerializeField] private Transform itemParent; [SerializeField] private GameObject rankItem; [SerializeField] private List _items; [SerializeField] private Image icon; [SerializeField] private Text name; [SerializeField] private Text points; [SerializeField] private Button close; // Start is called before the first frame update void Start() { } private void OnEnable() { close.onClick.AddListener(Close); } // Update is called once per frame void Update() { } private void OnDisable() { close.onClick.RemoveListener(Close); } public void InitPanel(int id) { List list = new List(); for (int i = 0; i < 20; i++) { var data = new RankData(); data.point= DataManager.GetInt(i + "LevelRankPoint" + id); data.iconID=DataManager.GetString(i + "LevelRankIcon" + id); data.name=DataManager.GetString(i + "LevelRankName" + id); data.bo = false; list.Add(data); } var playerData = new RankData(); playerData.point = DataManager.HighestRecordPoints(id); playerData.name = ""; playerData.iconID = "zz"; playerData.bo = true; list.Add(playerData); list.Sort((s,x)=>x.point.CompareTo(s.point)); for (int i = 0; i < _items.Count; i++) { _items[i].SetData(list[i]); } name.text = playerData.name; points.text = playerData.point.ToString(); } private void Close() { gameObject.SetActive(false); } } public class RankData { public string name; public int point; public string iconID; public bool bo = false; }