65 lines
1.7 KiB
C#
65 lines
1.7 KiB
C#
using UnityEngine;
|
|
using UnityEngine.UIElements;
|
|
using UnityEngine.SceneManagement;
|
|
|
|
using System.IO;
|
|
|
|
public class MenuUI : MonoBehaviour {
|
|
UIDocument uiDocument;
|
|
VisualElement tracks;
|
|
|
|
Button exit;
|
|
|
|
bool HideExitButton => Application.platform == RuntimePlatform.XboxOne || Application.isEditor;
|
|
|
|
void OnEnable() {
|
|
uiDocument = GetComponent<UIDocument>();
|
|
}
|
|
|
|
public void FocusTracks() {
|
|
uiDocument.rootVisualElement.Q<Button>().Focus();
|
|
}
|
|
|
|
public void AddTracks() {
|
|
SetupExit();
|
|
|
|
Scene current = SceneManager.GetActiveScene();
|
|
|
|
tracks = uiDocument.rootVisualElement.Q<VisualElement>("tracks");
|
|
tracks.Clear();
|
|
|
|
for (int i = 0; i < SceneManager.sceneCountInBuildSettings; ++i) {
|
|
int j = i; // top kek some pass by value thing ask liam
|
|
Scene scene = SceneManager.GetSceneByBuildIndex(i);
|
|
if (scene.name == current.name) continue;
|
|
string scenePath = SceneUtility.GetScenePathByBuildIndex(i);
|
|
string sceneName = Path.GetFileNameWithoutExtension(scenePath);
|
|
Button button = new Button { text = sceneName };
|
|
button.clicked += () => LoadScene(j);
|
|
tracks.Add(button);
|
|
}
|
|
}
|
|
|
|
void LoadScene(int i) {
|
|
Debug.Log($"Loading scene {i}");
|
|
SceneManager.LoadScene(i);
|
|
}
|
|
|
|
void SetupExit() {
|
|
exit = uiDocument.rootVisualElement.Q<Button>("exit");
|
|
|
|
if (HideExitButton) {
|
|
exit.style.display = DisplayStyle.None;
|
|
return;
|
|
}
|
|
|
|
exit.clicked += Exit;
|
|
}
|
|
|
|
void Exit() {
|
|
Debug.Log("Quitting");
|
|
Application.Quit();
|
|
}
|
|
|
|
}
|