WXGame/box1/Assets/Script/UI/RankListPanel.cs
DESKTOP-DDTRVOR\asus 603752a380 添加排行榜
2024-12-28 15:00:14 +08:00

84 lines
1.9 KiB
C#

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<RankItem> _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<RankData> list = new List<RankData>();
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;
}