Files
spacerace/Assets/Src/UI/MenuControls.cs
T
2023-07-25 18:47:45 +10:00

61 lines
1.3 KiB
C#

using UnityEngine;
using UnityEngine.UIElements;
using UnityEngine.InputSystem;
public class MenuControls : MonoBehaviour, SpaceRaceInput.IMenuActions {
[SerializeField]
UIDocument menuDoc;
[SerializeField]
UIDocument timingDoc;
[SerializeField]
ShipControls shipControls;
SpaceRaceInput input;
bool visible = false;
void Start() {
if (input == null) {
input = new SpaceRaceInput();
input.menu.SetCallbacks(this);
}
input.menu.Enable();
Debug.Log($"Menu {visible}");
Hide();
}
void Show() {
visible = true;
UnityEngine.Cursor.lockState = CursorLockMode.None;
menuDoc.enabled = true;
// take control off the ship
timingDoc.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;
shipControls.enabled = true;
}
public void OnToggleMenu(InputAction.CallbackContext ctx) {
visible = !visible;
Debug.Log($"Menu {visible}");
if (visible) {
Show();
return;
}
Hide();
return;
}
}