menu
This commit is contained in:
1 parent
45fc3026b4
commit
7dc0a04856
15 files changed
+339
-125
No files matched your search
@@ -3,7 +3,6 @@ using UnityEngine.UIElements;
|
||||
using UnityEngine.InputSystem;
|
||||
|
||||
public class MenuControls : MonoBehaviour, SpaceRaceInput.IMenuActions {
|
||||
[SerializeField]
|
||||
UIDocument menuDoc;
|
||||
|
||||
[SerializeField]
|
||||
@@ -12,27 +11,43 @@ public class MenuControls : MonoBehaviour, SpaceRaceInput.IMenuActions {
|
||||
[SerializeField]
|
||||
ShipControls shipControls;
|
||||
|
||||
MenuUi menuUi;
|
||||
|
||||
SpaceRaceInput input;
|
||||
bool visible = false;
|
||||
|
||||
void Start() {
|
||||
void Awake() {
|
||||
menuDoc = GetComponent<UIDocument>();
|
||||
|
||||
if (input == null) {
|
||||
input = new SpaceRaceInput();
|
||||
input.menu.SetCallbacks(this);
|
||||
}
|
||||
input.menu.Enable();
|
||||
|
||||
menuUi = GetComponent<MenuUi>();
|
||||
if (!menuUi) {
|
||||
Debug.LogError("No MenuUI");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Hide();
|
||||
}
|
||||
|
||||
void OnDestroy() {
|
||||
input.menu.RemoveCallbacks(this);
|
||||
}
|
||||
|
||||
void Show() {
|
||||
visible = true;
|
||||
UnityEngine.Cursor.lockState = CursorLockMode.None;
|
||||
menuDoc.enabled = true;
|
||||
menuUi.AddTracks();
|
||||
|
||||
// take control off the ship
|
||||
timingDoc.enabled = false;
|
||||
shipControls.enabled = false;
|
||||
|
||||
}
|
||||
|
||||
void Hide() {
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
using System.IO;
|
||||
|
||||
public class MenuUi : MonoBehaviour {
|
||||
UIDocument uiDocument;
|
||||
VisualElement tracks;
|
||||
|
||||
void Start() {
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: af1d31f9c950ece1e852a40ebd6c45a2
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -20,7 +20,7 @@ public class ShipUi : MonoBehaviour {
|
||||
VisualElement sectors;
|
||||
VisualElement timeSheet;
|
||||
|
||||
void OnEnable() {
|
||||
void Awake() {
|
||||
speed = uiDocument.rootVisualElement.Q<Label>("speed");
|
||||
timer = uiDocument.rootVisualElement.Q<Label>("timer");
|
||||
sectors = uiDocument.rootVisualElement.Q<VisualElement>("sectors");
|
||||
@@ -28,6 +28,12 @@ public class ShipUi : MonoBehaviour {
|
||||
}
|
||||
|
||||
void FixedUpdate() {
|
||||
if (timer == null || speed == null) {
|
||||
Debug.LogWarning("no speed or timer");
|
||||
Awake();
|
||||
return;
|
||||
}
|
||||
|
||||
timer.text = $"{TimeSpan.FromSeconds(timing.lapTime):m\\:ss\\.fff}";
|
||||
speed.text = $"{ship.Speed():0} u/s";
|
||||
|
||||
|
||||
Reference in new issue
Block a user