You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

58 lines
1.4 KiB
C#

using System;
using TMPro;
using Unity.BossRoom.UnityServices.Lobbies;
using UnityEngine;
using UnityEngine.UI;
using VContainer;
namespace Unity.BossRoom.Gameplay.UI
{
public class RoomNameBox : MonoBehaviour
{
[SerializeField]
TextMeshProUGUI m_RoomNameText;
[SerializeField]
Button m_CopyToClipboardButton;
LocalLobby m_LocalLobby;
string m_LobbyCode;
[Inject]
private void InjectDependencies(LocalLobby localLobby)
{
m_LocalLobby = localLobby;
m_LocalLobby.changed += UpdateUI;
}
void Awake()
{
UpdateUI(m_LocalLobby);
}
private void OnDestroy()
{
m_LocalLobby.changed -= UpdateUI;
}
private void UpdateUI(LocalLobby localLobby)
{
if (!string.IsNullOrEmpty(localLobby.LobbyCode))
{
m_LobbyCode = localLobby.LobbyCode;
m_RoomNameText.text = $"Lobby Code: {m_LobbyCode}";
gameObject.SetActive(true);
m_CopyToClipboardButton.gameObject.SetActive(true);
}
else
{
gameObject.SetActive(false);
}
}
public void CopyToClipboard()
{
GUIUtility.systemCopyBuffer = m_LobbyCode;
}
}
}