using TMPro;
using UnityEngine;
namespace LobbyRelaySample.UI
{
///
/// Shows the player info in-lobby and game
///
[RequireComponent(typeof(LobbyUserObserver))]
public class LobbyUserCardUI : ObserverPanel
{
[SerializeField]
TMP_Text m_DisplayNameText;
[SerializeField]
TMP_Text m_StatusText;
[SerializeField]
TMP_Text m_EmoteText;
public bool IsAssigned
{
get { return UserId != null; }
}
public string UserId { get; private set; }
private LobbyUserObserver m_observer;
public void SetUser(LobbyUser myLobbyUser)
{
Show();
if (m_observer == null)
m_observer = GetComponent();
m_observer.BeginObserving(myLobbyUser);
UserId = myLobbyUser.ID;
}
public void OnUserLeft()
{
UserId = null;
Hide();
m_observer.EndObserving();
}
public override void ObservedUpdated(LobbyUser observed)
{
m_DisplayNameText.SetText(observed.DisplayName);
m_StatusText.SetText(SetStatusFancy(observed.UserStatus));
m_EmoteText.SetText(observed.Emote);
}
string SetStatusFancy(UserStatus status)
{
switch (status)
{
case UserStatus.Lobby:
return "Lobby."; // Light Blue
case UserStatus.Ready:
return "Ready!"; // Light Mint
case UserStatus.Connecting:
return "Connecting."; // Bright Yellow
case UserStatus.Connected:
return "Connected."; //Orange
default:
return "In Lobby.";
}
}
}
}