119 lines
2.8 KiB
C#
119 lines
2.8 KiB
C#
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class TournamentPlayParticipantItem : MonoBehaviour
|
|
{
|
|
public TournamentManager.CTournament.TournamentParticipant participant;
|
|
|
|
[SerializeField]
|
|
private Text positionNumberText;
|
|
|
|
[SerializeField]
|
|
private RawImage avatarImage;
|
|
|
|
[SerializeField]
|
|
private Text playerNameText;
|
|
|
|
[SerializeField]
|
|
private Text valueText;
|
|
|
|
[SerializeField]
|
|
private Color[] positionBgColors;
|
|
|
|
private Image backgroundImage;
|
|
|
|
private Animator animator;
|
|
|
|
private AudioSource audioSource;
|
|
|
|
[SerializeField]
|
|
private AudioClip[] audioClip;
|
|
|
|
private string lastValue = "";
|
|
|
|
private int lastPosition;
|
|
|
|
public bool isOwnerPlayer;
|
|
|
|
private void Start()
|
|
{
|
|
audioSource = GetComponent<AudioSource>();
|
|
backgroundImage = GetComponent<Image>();
|
|
animator = GetComponent<Animator>();
|
|
playerNameText.text = participant.playerName;
|
|
if (ulong.TryParse(participant.playerId, out var result))
|
|
{
|
|
avatarImage.GetComponent<SteamShowAvatarByUserId>().steamUserID = result;
|
|
}
|
|
lastPosition = participant.position;
|
|
}
|
|
|
|
private void FixedUpdate()
|
|
{
|
|
Refresh();
|
|
}
|
|
|
|
private void Refresh()
|
|
{
|
|
positionNumberText.text = (participant.position + 1).ToString();
|
|
if (isOwnerPlayer)
|
|
{
|
|
backgroundImage.color = positionBgColors[4];
|
|
}
|
|
else
|
|
{
|
|
switch (participant.position)
|
|
{
|
|
case 0:
|
|
backgroundImage.color = positionBgColors[0];
|
|
break;
|
|
case 1:
|
|
backgroundImage.color = positionBgColors[1];
|
|
break;
|
|
case 2:
|
|
backgroundImage.color = positionBgColors[2];
|
|
break;
|
|
default:
|
|
backgroundImage.color = positionBgColors[3];
|
|
break;
|
|
}
|
|
}
|
|
switch (TournamentManager.Instance.currentPlayTournament.tournamentTask)
|
|
{
|
|
case TournamentManager.CTournament.TournamentTask.Amount_fish:
|
|
valueText.text = participant.value.ToString("F0");
|
|
break;
|
|
case TournamentManager.CTournament.TournamentTask.Amount_fish_weight:
|
|
valueText.text = GameManager.Instance.ConvertWeight(participant.value);
|
|
break;
|
|
case TournamentManager.CTournament.TournamentTask.Best_fish_weight:
|
|
if (participant.bestFishId == -1)
|
|
{
|
|
valueText.text = "-";
|
|
return;
|
|
}
|
|
valueText.text = GameManager.GetFishNameFromSpecies((GameManager.FishSpecies)participant.bestFishId) + " " + GameManager.Instance.ConvertWeight(participant.value);
|
|
break;
|
|
}
|
|
base.transform.SetSiblingIndex(participant.position);
|
|
if (lastPosition > participant.position)
|
|
{
|
|
animator.SetTrigger("ChangePosition");
|
|
}
|
|
else if (lastValue != valueText.text)
|
|
{
|
|
animator.SetTrigger("ChangeValue");
|
|
lastValue = valueText.text;
|
|
}
|
|
if (lastPosition > participant.position && isOwnerPlayer)
|
|
{
|
|
audioSource.PlayOneShot(audioClip[0]);
|
|
}
|
|
if (lastPosition < participant.position && isOwnerPlayer)
|
|
{
|
|
audioSource.PlayOneShot(audioClip[1]);
|
|
}
|
|
lastPosition = participant.position;
|
|
}
|
|
}
|