/// <summary> /// 显示排行榜面板 /// </summary> void ShowRankPanel() { //获取GameScore数据对象,降序排列取前10个数据 var param = new Dictionary <string, object>(); param.Add("order", "-score"); param.Add("limit", 10); StartCoroutine(_leanCloud.Query("GameScore", param, t => { var results = JsonUtility.FromJson <QueryRankResult>(t); var scores = new List <KeyValuePair <string, string> >(); //将数据转化为字符串 foreach (var result in results.results) { scores.Add( new KeyValuePair <string, string>(result.playerName, result.score.ToString())); } foreach (var score in scores) { var item = Instantiate(RankName); item.SetActive(true); item.GetComponent <Text>().text = score.Key; item.transform.SetParent(RankName.transform.parent); item = Instantiate(RankScore); item.SetActive(true); item.GetComponent <Text>().text = score.Value; item.transform.SetParent(RankScore.transform.parent); } RankPanel.SetActive(true); })); }
//获取GameScore数据对象,降序排列取前10个数据进行显示 private void ShowRankPanel() { //初始化 Dictionary为键类型所使用的比较容器 var param = new Dictionary <string, object>(); //将指定的键添加到Dictionary中 param.Add("order", "-score"); param.Add("limit", 10); //通过协程依次获取数据并在比较容器Dictionary进行查找所有保存的结果 并按一定顺序排序 ?=> StartCoroutine(_leanCloud.Query("GameScore", param, t => { //从云端调取所有的结果 var results = JsonUtility.FromJson <QueryRankResult>(t); //初始化比较容器中的列表 var scores = new List <KeyValuePair <string, string> >(); //依次查找云端所有的数据并将数据转化为字符串添加到列表scores中 foreach (var result in results.results) { scores.Add( new KeyValuePair <string, string>(result.playerName, result.score.ToString()) ); } //依次查找scores列表中的结果进行分类显示 foreach (var score in scores) { //生成排名用户的昵称 var item = Instantiate(RankName); //进行状态显示 item.SetActive(true); //获取昵称下的text组件进行赋值 item.GetComponent <Text>().text = score.Key; //将用户昵称设置在父物体下 item.transform.SetParent(RankName.transform.parent); //同理设置对应昵称的分数 item = Instantiate(RankScore); item.SetActive(true); item.GetComponent <Text>().text = score.Value; item.transform.SetParent(RankScore.transform.parent); } //显示排名面板 RankPanel.SetActive(true); })); }