97 lines
2.1 KiB
C#
97 lines
2.1 KiB
C#
using UnityEngine;
|
|
using UnityEngine.UIElements;
|
|
using UnityEngine.InputSystem;
|
|
|
|
public class MenuControls : MonoBehaviour, SpaceRaceInput.IMenuActions {
|
|
UIDocument menuDoc;
|
|
|
|
[SerializeField]
|
|
UIDocument timingDoc;
|
|
|
|
[SerializeField]
|
|
UIDocument crosshairDoc;
|
|
|
|
[SerializeField]
|
|
UIDocument controlsDoc;
|
|
|
|
[SerializeField]
|
|
ShipControls shipControls;
|
|
|
|
MenuUI menuUi;
|
|
|
|
[SerializeField]
|
|
TimingUI timingUi;
|
|
|
|
[SerializeField]
|
|
ControlsUI controlsUI;
|
|
|
|
SpaceRaceInput input;
|
|
bool visible = false;
|
|
|
|
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();
|
|
menuUi.FocusTracks();
|
|
|
|
// TODO abstract all this cause it's shit
|
|
// take control off the ship
|
|
timingDoc.enabled = false;
|
|
crosshairDoc.enabled = false;
|
|
controlsDoc.enabled = false;
|
|
timingUi.enabled = false;
|
|
controlsUI.enabled = false;
|
|
shipControls.enabled = false;
|
|
}
|
|
|
|
void Hide() {
|
|
visible = false;
|
|
UnityEngine.Cursor.lockState = CursorLockMode.Locked;
|
|
menuDoc.enabled = false;
|
|
|
|
// resume control of the ship
|
|
timingDoc.enabled = true;
|
|
crosshairDoc.enabled = true;
|
|
controlsDoc.enabled = true;
|
|
timingUi.enabled = true;
|
|
controlsUI.enabled = true;
|
|
shipControls.enabled = true;
|
|
}
|
|
|
|
public void OnToggleMenu(InputAction.CallbackContext ctx) {
|
|
visible = !visible;
|
|
// Debug.Log($"Menu {visible}");
|
|
|
|
if (visible) {
|
|
Show();
|
|
return;
|
|
}
|
|
|
|
Hide();
|
|
return;
|
|
}
|
|
} |