Partially implement lobby ui, fix ui pointers on network rig
This commit is contained in:
81
Assets/Scripts/UI/LobbyMenuUI.cs
Normal file
81
Assets/Scripts/UI/LobbyMenuUI.cs
Normal file
@@ -0,0 +1,81 @@
|
||||
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;
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user