41 lines
1.2 KiB
C#
41 lines
1.2 KiB
C#
using UnityEngine;
|
|
|
|
public class InputManager : MonoBehaviour {
|
|
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;
|
|
}
|
|
|
|
public Vector2 GetMouseScreenPosition() => Input.mousePosition;
|
|
public bool IsMouseButtonDown(int button) => Input.GetMouseButtonDown(button);
|
|
|
|
public Vector2 GetCameraMoveVector() {
|
|
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;
|
|
}
|
|
|
|
public float GetCameraRotateAmount() {
|
|
float rotateAmount = 0f;
|
|
if (Input.GetKey(KeyCode.Q)) rotateAmount = +1f;
|
|
if (Input.GetKey(KeyCode.E)) rotateAmount = -1f;
|
|
return rotateAmount;
|
|
}
|
|
|
|
public float GetCameraZoomAmount() =>
|
|
Input.mouseScrollDelta.y switch {
|
|
> 0 => -1f,
|
|
< 0 => +1f,
|
|
_ => 0f
|
|
};
|
|
} |