using UnityEngine; using UnityEngine.UIElements; using UnityEngine.Rendering; using UnityEngine.InputSystem; public class MenuControls : MonoBehaviour { UIDocument menuDoc; [SerializeField] UIDocument timingDoc; [SerializeField] UIDocument crosshairDoc; [SerializeField] UIDocument controlsDoc; [SerializeField] ShipControls shipControls; MenuUI menuUi; Volume effectsVolume; [SerializeField] TimingUI timingUi; [SerializeField] ControlsUI controlsUI; [SerializeField] ShipAudio audio; SpaceRaceInput input; PlayerData _player; Toggle invertYToggle; Slider viewSensSlider; Label viewSensLabel; bool visible = false; void Awake() { menuDoc = GetComponent(); effectsVolume = GetComponent(); if (input == null) input = new SpaceRaceInput(); input.menu.Enable(); menuUi = GetComponent(); if (!menuUi) { Debug.LogError("No MenuUI"); return; } _player = PlayerDataService.Load(); SetupActions(); Hide(); } void SetupActions() { if (input == null) input = new SpaceRaceInput(); input.menu.Enable(); input.menu.ToggleMenu.started += OnToggleMenu; input.menu.CloseMenu.started += OnCloseMenu; } void OnDestroy() { input.menu.ToggleMenu.started -= OnToggleMenu; input.menu.CloseMenu.started -= OnCloseMenu; } void Show() { visible = true; UnityEngine.Cursor.lockState = CursorLockMode.None; menuDoc.enabled = true; effectsVolume.enabled = true; menuUi.AddTracks(); menuUi.FocusTracks(); BindSettings(); // 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; effectsVolume.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; } void OnToggleMenu(InputAction.CallbackContext _ctx) { visible = !visible; if (visible) { Show(); return; } Hide(); return; } void OnCloseMenu(InputAction.CallbackContext _ctx) { if (visible) Hide(); } void BindSettings() { Debug.Log("Setting controls change callbacks"); invertYToggle = menuDoc.rootVisualElement.Q("invertY"); viewSensSlider = menuDoc.rootVisualElement.Q("viewSens"); viewSensLabel = menuDoc.rootVisualElement.Q