using Assets.Scripts; using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.UI; namespace Assets.Scenes.Ride.Scripts { public class CompetitionRankingItem : MonoBehaviour { private RawImage Head; private RawImage Country; private Image Background; private Text Name; private Text Speed; private Text Distance; private Text Ratio;//功体比 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; private string _speed = string.Empty; private string _distance = string.Empty; private string _ratio = string.Empty; public int rank { get; set; } private Texture countryTexture; CyclingController cyclingController; Color selectedColor = new Color(0.9764706f, 0.1882353f, 0.5254902f); Color unselectedColor = new Color(0.2078431f, 0.2078431f, 0.2627451f); private void Awake() { cyclingController = FindObjectOfType(); Background = transform.GetComponent(); Head = transform.Find("Head").GetComponent(); Country = transform.Find("Country").GetComponent(); Name = transform.Find("Name").GetComponent(); Speed = transform.Find("Speed").GetComponent(); Distance = transform.Find("Distance").GetComponent(); Ratio = transform.Find("Ratio").GetComponent(); Rank = transform.Find("Rank").GetComponent(); Timer = transform.Find("Timer")?.GetComponent(); countryTexture = Resources.Load("Images/flag_China_Person").texture; if (cyclingController.isWatch) { UIManager.AddEvent(this.gameObject, UnityEngine.EventSystems.EventTriggerType.PointerClick, Watch); } } private void Update() { if (cyclingController.currentPlayer.UserId == UserId) { Background.color = selectedColor; Ratio.color = Color.white; Distance.color = Color.white; } else { Distance.color = selectedColor; Background.color = unselectedColor; } } //切换到当前用户视角 public void Watch(BaseEventData baseEventData) { cyclingController.ChangeCurrentPlayer(_userId); } public void setTimer(string timer) { Timer.text = timer; } public void setRatio(string ratio) { if (!_ratio.Equals(ratio)) { Ratio.text = ratio; } } //设置当前排名 public void SetRank(int rank) { Rank.text = rank.ToString().PadLeft(3,'0'); 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("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 setSpeed(string speed) { if (!_speed.Equals(speed)) Speed.text = speed; } public void setDistance(string distance) { if (!_distance.Equals(distance)) Distance.text = distance; } public void setUserId(int userId) { _userId = userId; } } }