Partially implement lobby ui, fix ui pointers on network rig
This commit is contained in:
@@ -3,6 +3,7 @@ using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class LevelItemUI : MonoBehaviour
|
||||
@@ -27,6 +28,8 @@ public class LevelItemUI : MonoBehaviour
|
||||
[SerializeField]
|
||||
private Image backgroundImage;
|
||||
|
||||
public UnityEvent<Level> OnClicked;
|
||||
|
||||
public void Setup(Level level, bool isLocked)
|
||||
{
|
||||
this.level = level;
|
||||
@@ -35,4 +38,10 @@ public class LevelItemUI : MonoBehaviour
|
||||
nameText.text = level.levelName;
|
||||
difficultyText.text = "0";
|
||||
}
|
||||
|
||||
[Button]
|
||||
public void OnButtonClicked()
|
||||
{
|
||||
OnClicked?.Invoke(level);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,10 +4,12 @@ using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using Zenject;
|
||||
|
||||
public class LevelMenuUI : MonoBehaviour
|
||||
{
|
||||
[Title("Debug")]
|
||||
[Inject]
|
||||
[ReadOnly]
|
||||
private HVRInputModule uiInput;
|
||||
@@ -16,6 +18,11 @@ public class LevelMenuUI : MonoBehaviour
|
||||
[ReadOnly]
|
||||
private SceneManager sceneManager;
|
||||
|
||||
[SerializeField]
|
||||
[ReadOnly]
|
||||
private Canvas canvas;
|
||||
|
||||
[Title("Selection")]
|
||||
[SerializeField]
|
||||
private GameObject levelSelection;
|
||||
|
||||
@@ -23,11 +30,26 @@ public class LevelMenuUI : MonoBehaviour
|
||||
private GameObject levelSelectionContent;
|
||||
|
||||
[SerializeField]
|
||||
[ReadOnly]
|
||||
private Canvas canvas;
|
||||
private GameObject levelItemPrefab;
|
||||
|
||||
[Title("Detail")]
|
||||
[SerializeField]
|
||||
private GameObject levelDetail;
|
||||
|
||||
[SerializeField]
|
||||
private GameObject levelItemPrefab;
|
||||
private LevelItemUI levelDetailUI;
|
||||
|
||||
[SerializeField]
|
||||
[ReadOnly]
|
||||
private Level selectedLevel;
|
||||
|
||||
[SerializeField]
|
||||
private Button backButton;
|
||||
|
||||
[SerializeField]
|
||||
private Button startButton;
|
||||
|
||||
private bool isDetailVisible => selectedLevel != null;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
@@ -36,13 +58,26 @@ public class LevelMenuUI : MonoBehaviour
|
||||
canvas = GetComponent<Canvas>();
|
||||
uiInput?.AddCanvas(canvas);
|
||||
|
||||
backButton.onClick.AddListener(() => BackClicked());
|
||||
startButton.onClick.AddListener(() => StartClicked());
|
||||
|
||||
UpdateLevelSelection();
|
||||
UpdateUI();
|
||||
}
|
||||
|
||||
private void UpdateUI()
|
||||
{
|
||||
levelSelection.SetActive(!isDetailVisible);
|
||||
levelDetail.SetActive(isDetailVisible);
|
||||
backButton.gameObject.SetActive(isDetailVisible);
|
||||
}
|
||||
|
||||
private void UpdateLevelSelection()
|
||||
{
|
||||
foreach (Transform transform in levelSelectionContent.transform)
|
||||
{
|
||||
var item = transform.gameObject.GetComponent<LevelItemUI>();
|
||||
item.OnClicked.RemoveAllListeners();
|
||||
Destroy(transform.gameObject);
|
||||
}
|
||||
|
||||
@@ -51,7 +86,27 @@ public class LevelMenuUI : MonoBehaviour
|
||||
var go = Instantiate(levelItemPrefab);
|
||||
go.name = level.name;
|
||||
go.transform.SetParent(levelSelectionContent.transform, false);
|
||||
go.GetComponent<LevelItemUI>().Setup(level, false);
|
||||
var item = go.GetComponent<LevelItemUI>();
|
||||
item.Setup(level, false);
|
||||
item.OnClicked.AddListener(OnLevelSelected);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnLevelSelected(Level level)
|
||||
{
|
||||
selectedLevel = level;
|
||||
levelDetailUI.Setup(level, false);
|
||||
UpdateUI();
|
||||
}
|
||||
|
||||
private void BackClicked()
|
||||
{
|
||||
selectedLevel = null;
|
||||
UpdateUI();
|
||||
}
|
||||
|
||||
private void StartClicked()
|
||||
{
|
||||
sceneManager.SwitchToLevel(selectedLevel);
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/UI/LobbyMenuUI.cs.meta
Normal file
11
Assets/Scripts/UI/LobbyMenuUI.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6da8a5c9d23b43d4f8c87bc076080da6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user