Partially implement lobby ui, fix ui pointers on network rig

This commit is contained in:
2024-09-09 16:31:08 +02:00
parent d7eb1e65d2
commit 8529ebb4a9
20 changed files with 4229 additions and 917 deletions

View File

@@ -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);
}
}