using TMPro; using UnityEngine; using UnityEngine.Events; namespace LobbyRelaySample.UI { [RequireComponent(typeof(LobbyDataObserver))] public class LobbyButtonUI : MonoBehaviour { [SerializeField] TMP_Text lobbyNameText; [SerializeField] TMP_Text lobbyCountText; /// /// Subscribed to on instantiation to pass our lobby data back /// public UnityEvent onLobbyPressed; LobbyDataObserver m_DataObserver; void Awake() { m_DataObserver = GetComponent(); } /// /// UI CallBack /// public void OnLobbyClicked() { onLobbyPressed?.Invoke(m_DataObserver.observed); } public void UpdateLobby(LobbyData lobby) { m_DataObserver.observed.CopyObserved(lobby); } public void OnRoomUpdated(LobbyData data) { lobbyNameText.SetText(data.LobbyName); lobbyCountText.SetText($"{data.PlayerCount}/{data.MaxPlayerCount}"); } } }