82 lines
1.7 KiB
C#
82 lines
1.7 KiB
C#
using HurricaneVR.Framework.Core.UI;
|
|
using Sirenix.OdinInspector;
|
|
using TMPro;
|
|
using Unity.Netcode;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using Zenject;
|
|
|
|
public class LobbyMenuUI : MonoBehaviour
|
|
{
|
|
[Title("Debug")]
|
|
[Inject]
|
|
[ReadOnly]
|
|
private HVRInputModule uiInput;
|
|
|
|
[Inject]
|
|
[ReadOnly]
|
|
private SceneManager sceneManager;
|
|
|
|
[SerializeField]
|
|
[ReadOnly]
|
|
[Inject]
|
|
private GameManager gameManager;
|
|
|
|
[SerializeField]
|
|
[ReadOnly]
|
|
private Canvas canvas;
|
|
|
|
[Title("Join or Host")]
|
|
[SerializeField]
|
|
private GameObject joinOrHost;
|
|
|
|
[SerializeField]
|
|
private TMP_InputField roomCodeInput;
|
|
|
|
[SerializeField]
|
|
private Button joinButton;
|
|
|
|
[SerializeField]
|
|
private Button hostButton;
|
|
|
|
private bool isConnected => gameManager.IsMultiplayer;
|
|
|
|
private void Start()
|
|
{
|
|
if (uiInput == null) return;
|
|
|
|
canvas = GetComponent<Canvas>();
|
|
uiInput?.AddCanvas(canvas);
|
|
|
|
joinButton.onClick.AddListener(() => JoinClicked());
|
|
hostButton.onClick.AddListener(() => HostClicked());
|
|
gameManager.OnConnected.AddListener(() => UpdateUI());
|
|
gameManager.OnDisconnected.AddListener(() => UpdateUI());
|
|
|
|
UpdateUI();
|
|
}
|
|
|
|
private void UpdateUI()
|
|
{
|
|
joinOrHost.SetActive(!isConnected);
|
|
joinButton.interactable = true;
|
|
hostButton.interactable = true;
|
|
Debug.Log(isConnected);
|
|
}
|
|
|
|
private void JoinClicked()
|
|
{
|
|
gameManager.JoinGame(roomCodeInput.text);
|
|
joinButton.interactable = false;
|
|
hostButton.interactable = false;
|
|
}
|
|
|
|
private void HostClicked()
|
|
{
|
|
gameManager.HostGame();
|
|
joinButton.interactable = false;
|
|
hostButton.interactable = false;
|
|
|
|
}
|
|
}
|