using UnityEngine; using UnityEngine.InputSystem; public class GameManager : Singleton { public Transform Player { get; private set; } private InputAction menuAction; protected override void Awake() { base.Awake(); if (Instance != this) { return; } if (Camera.main != null) { Player = Camera.main.transform; } else { Debug.LogError("GameManager:没有找到主摄像机。", this); } menuAction = new InputAction( "ToggleMenu", InputActionType.Button, "{LeftHand}/primaryButton"); } private void OnEnable() { if (menuAction == null) { return; } menuAction.performed += OnMenuButtonPressed; menuAction.Enable(); } private void OnDisable() { if (menuAction == null) { return; } menuAction.performed -= OnMenuButtonPressed; menuAction.Disable(); } private void OnDestroy() { menuAction?.Dispose(); } private void OnMenuButtonPressed(InputAction.CallbackContext context) { UIManager.Instance.ToggleMenu(); } }