要求:实现如图所示UI界面,按下某一按键实现排行榜的更新
M:
//数据模型类 主要负责数据(玩家的数据)
public class RankModel
{
//定义三个属性 姓名、分数、排名
//定义构造函数
public string Name{
set;
get;
}
public int Score{
set;
get;
}
public int Number{
set;
get;
}
public RankModel(string name,int score,int number){
Name = name;
Score = score;
Number = number;
}
}
V:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
//排行榜视图类:负责UI数据的显示,向外界提供UI数据初始化的方法
public class RankElementSc : MonoBehaviour
{
private Text numberText;//显示排名的子物体的text
private Text nameText;//显示名字的子物体的text
private Text scoreText;//显示分数的子物体的text
void Awake()
{
numberText = transform.Find("NumberText").GetComponent<Text>();
nameText = transform.Find("NameText").GetComponent<Text>();
scoreText = transform.Find("ScoreText").GetComponent<Text>();
}
//UI初始化
public void Init(RankModel rank){
Debug.Log(numberText + "" + rank.Number);
numberText.text = rank.Number.ToString();
nameText.text = rank.Name;
scoreText.text = rank.Score.ToString();
}
}
C:
using System.Collections;
using System.Collections.Generic;
usin