rabidus-test/Assets/Scripts/LeaderboardEntry.cs

68 lines
1.9 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class LeaderboardEntry : MonoBehaviour
{
[SerializeField] private TMPro.TextMeshProUGUI _numText;
[SerializeField] private Text _numText2;
[SerializeField] private TMPro.TextMeshProUGUI _nameText;
[SerializeField] private Text _nameText2;
[SerializeField] private TMPro.TextMeshProUGUI _scoreText;
[SerializeField] private Text _scoreText2;
[SerializeField] private Image _lable;
[SerializeField] private Image _selectBackground;
[SerializeField] private Sprite _goldLable;
public int MaxIndex = 29;
[SerializeField]
private List<GameObject> _medals = new List<GameObject>();
public void Init(Player player, int index, bool selected = false)
{
if (index < 3)
{
_medals[index].SetActive(true);
_lable.sprite = _goldLable;
}
if (index <= MaxIndex)
{
if(_numText != default)
_numText.SetText($"{index + 1}");
if(_numText2 != default)
_numText2.text = $"{index + 1}";
}
else
{
if(_numText != default)
_numText.SetText($"-");
if(_numText2 != default)
_numText2.text = $"-";
}
if(_scoreText != default)
_scoreText.SetText($"{player.Score}");
if(_scoreText2 != default)
_scoreText2.text = $"{player.Score}";
if (selected)
{
if(_nameText != default)
_nameText.SetText("ÂÛ");
if(_nameText2 != default)
_nameText2.text = "ÂÛ";
_selectBackground.gameObject.SetActive(true);
}
else
{
if(_nameText != default)
_nameText.SetText(player.Name);
if(_nameText2 != default)
_nameText2.text = player.Name;
}
}
}