113 lines
2.6 KiB
C#
113 lines
2.6 KiB
C#
using HurricaneVR.Framework.Core.UI;
|
|
using Sirenix.OdinInspector;
|
|
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;
|
|
|
|
[Inject]
|
|
[ReadOnly]
|
|
private SceneManager sceneManager;
|
|
|
|
[SerializeField]
|
|
[ReadOnly]
|
|
private Canvas canvas;
|
|
|
|
[Title("Selection")]
|
|
[SerializeField]
|
|
private GameObject levelSelection;
|
|
|
|
[SerializeField]
|
|
private GameObject levelSelectionContent;
|
|
|
|
[SerializeField]
|
|
private GameObject levelItemPrefab;
|
|
|
|
[Title("Detail")]
|
|
[SerializeField]
|
|
private GameObject levelDetail;
|
|
|
|
[SerializeField]
|
|
private LevelItemUI levelDetailUI;
|
|
|
|
[SerializeField]
|
|
[ReadOnly]
|
|
private Level selectedLevel;
|
|
|
|
[SerializeField]
|
|
private Button backButton;
|
|
|
|
[SerializeField]
|
|
private Button startButton;
|
|
|
|
private bool isDetailVisible => selectedLevel != null;
|
|
|
|
private void Start()
|
|
{
|
|
if (uiInput == null) return;
|
|
|
|
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);
|
|
}
|
|
|
|
foreach (var level in sceneManager.Levels)
|
|
{
|
|
var go = Instantiate(levelItemPrefab);
|
|
go.name = level.name;
|
|
go.transform.SetParent(levelSelectionContent.transform, 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);
|
|
}
|
|
}
|