menu
This commit is contained in:
1 parent
5135c50172
commit
268608a459
46 files changed
+5298
-74
No files matched your search
@@ -0,0 +1,61 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user