75 lines
2.2 KiB
C#

using Assets.Scripts;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
namespace Assets.Scenes.Ride.Scripts
{
public class TopRankingItem : MonoBehaviour
{
private RawImage Head;
private RawImage Country;
private Text Name;
private Text Rank;//当前排名
private Text Timer;
private int _userId = 0;
public int UserId { get { return _userId; } }
private string _headUrl = string.Empty;
private string _countryUrl = string.Empty;
private string _name = string.Empty;
public int rank { get; set; }
CyclingController cyclingController;
private void Awake()
{
cyclingController = FindObjectOfType<CyclingController>();
Head = transform.Find("Head").GetComponent<RawImage>();
Country = transform.Find("Country").GetComponent<RawImage>();
Name = transform.Find("Name").GetComponent<Text>();
Rank = transform.Find("Rank").GetComponent<Text>();
Timer = transform.Find("Timer")?.GetComponent<Text>();
}
public void setTimer(string timer)
{
Timer.text = timer;
}
//设置当前排名
public void SetRank(int rank)
{
Rank.text = rank.ToString();
this.rank = rank;
}
public void setHead(string url)
{
if (!string.IsNullOrEmpty(url))
{
Utils.DisplayImage(Head, url, true);
var rect = ((RectTransform)Head.transform).rect;
Material material = Instantiate(Resources.Load<Material>("UI/Material/RoundedCornersTextureMaterial"));
material.SetVector(Shader.PropertyToID("_WidthHeightRadius"), new Vector4(rect.width, rect.height, rect.height, 0));
Head.material = material;
}
}
public void setCountry(Texture texture)
{
Country.texture = texture;
}
public void setName(string name)
{
if (!_name.Equals(name))
Name.text = name;
}
public void setUserId(int userId)
{
_userId = userId;
}
}
}