#define USE_NEW_INPUT_SYSTEM using UnityEngine; using UnityEngine.InputSystem; public class InputManager : MonoBehaviour { private PlayerInputActions playerInputActions; public static InputManager Instance { get; private set; } private void Awake() { if (Instance is not null) { Debug.LogError($"There is more than one InputManager! {transform} - {Instance}"); Destroy(gameObject); return; } Instance = this; playerInputActions = new(); playerInputActions.Player.Enable(); } public Vector2 GetMouseScreenPosition() { #if USE_NEW_INPUT_SYSTEM return Mouse.current.position.ReadValue(); #else return Input.mousePosition; #endif } public bool IsMouseButtonDownThisFrame() { #if USE_NEW_INPUT_SYSTEM return playerInputActions.Player.Click.WasPressedThisFrame(); #else return Input.GetMouseButtonDown(0); #endif } public Vector2 GetCameraMoveVector() { #if USE_NEW_INPUT_SYSTEM return playerInputActions.Player.CameraMovement.ReadValue(); #else Vector2 inputMoveDir = new(); if (Input.GetKey(KeyCode.W)) inputMoveDir.y = +1f; if (Input.GetKey(KeyCode.S)) inputMoveDir.y = -1f; if (Input.GetKey(KeyCode.A)) inputMoveDir.x = -1f; if (Input.GetKey(KeyCode.D)) inputMoveDir.x = +1f; return inputMoveDir; #endif } public float GetCameraRotateAmount() { #if USE_NEW_INPUT_SYSTEM return playerInputActions.Player.CameraRotate.ReadValue(); #else float rotateAmount = 0f; if (Input.GetKey(KeyCode.Q)) rotateAmount = +1f; if (Input.GetKey(KeyCode.E)) rotateAmount = -1f; return rotateAmount; #endif } public float GetCameraZoomAmount() { #if USE_NEW_INPUT_SYSTEM return playerInputActions.Player.CameraZoom.ReadValue(); #else return Input.mouseScrollDelta.y switch { > 0 => -1f, < 0 => +1f, _ => 0f }; #endif } }