61 lines
1.9 KiB
C#
61 lines
1.9 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using LitJson;
|
|
using NaughtyAttributes;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
|
|
public class SettlePanel : MonoBehaviour
|
|
{
|
|
|
|
public GameObject settlePre;
|
|
|
|
public TextMeshProUGUI text;
|
|
|
|
/// <summary>
|
|
/// 预制体父节点
|
|
/// </summary>
|
|
public GameObject Node;
|
|
public static void Show()
|
|
{
|
|
WorldUIManager.Ins.Cover("UI/SettlePanel", false);
|
|
}
|
|
|
|
public void Start()
|
|
{
|
|
Dictionary<string, SettleInfo> tempDictionary = JsonMapper.ToObject<Dictionary<string, SettleInfo>>(GameManager.Ins.settleData);
|
|
|
|
text.color = Color.yellow;
|
|
text.text = "完成";
|
|
|
|
// 创建最终的字典,将 string 转换为 int
|
|
Dictionary<int, SettleInfo> playerDictionary = new Dictionary<int, SettleInfo>();
|
|
foreach (var entry in tempDictionary)
|
|
{
|
|
// 将键转换为 int
|
|
int key = int.Parse(entry.Key);
|
|
playerDictionary[key] = entry.Value;
|
|
}
|
|
var sortedPlayerDictionary = playerDictionary.OrderByDescending(pair => pair.Value.Score)
|
|
.ToDictionary(pair => pair.Key, pair => pair.Value);
|
|
// 打印排序后的结果
|
|
|
|
int ranking = 0;
|
|
foreach (SettleInfo info in sortedPlayerDictionary.Values)
|
|
{
|
|
bool isShow;
|
|
ranking++;
|
|
isShow = GameLocal.Ins.self.index == info.playerName ? true : false;
|
|
CreateSettleItem("玩家" + info.playerName.ToString(), info.Score, ranking, info.Title, isShow);
|
|
|
|
}
|
|
}
|
|
public void CreateSettleItem(string playerName, int Score, int Ranking, string Title, bool isShow)
|
|
{
|
|
GameObject item = Instantiate(settlePre, Node.transform);
|
|
|
|
item.GetComponent<SettleItem>().Init(playerName, Score, Ranking, Title, isShow);
|
|
}
|
|
}
|