36 lines
1014 B
C#
36 lines
1014 B
C#
using UnityEngine;
|
|
using UnityEngine.UIElements;
|
|
using UnityEngine.SceneManagement;
|
|
|
|
using System.IO;
|
|
|
|
public class MenuUi : MonoBehaviour {
|
|
UIDocument uiDocument;
|
|
VisualElement tracks;
|
|
|
|
void OnEnable() {
|
|
uiDocument = GetComponent<UIDocument>();
|
|
}
|
|
|
|
public void AddTracks() {
|
|
tracks = uiDocument.rootVisualElement.Q<VisualElement>("tracks");
|
|
tracks.Clear();
|
|
|
|
for (int i = 0; i < SceneManager.sceneCountInBuildSettings; ++i) {
|
|
int j = i; // top kek
|
|
Scene scene = SceneManager.GetSceneByBuildIndex(i);
|
|
string scenePath = SceneUtility.GetScenePathByBuildIndex(i);
|
|
string sceneName = Path.GetFileNameWithoutExtension(scenePath);
|
|
Button button = new Button();
|
|
button.text = sceneName;
|
|
button.clicked += () => LoadScene(j);
|
|
tracks.Add(button);
|
|
}
|
|
}
|
|
|
|
void LoadScene(int i) {
|
|
Debug.Log($"Loading scene {i}");
|
|
SceneManager.LoadScene(i);
|
|
}
|
|
}
|