31 lines
1.3 KiB
C#
31 lines
1.3 KiB
C#
using System;
|
|
using UnityEngine;
|
|
using UnityEngine.InputSystem;
|
|
|
|
public class GameInput : MonoBehaviour {
|
|
public static GameInput Instance { get; private set; }
|
|
private static PlayerInputActions playerInputActions;
|
|
|
|
private void Awake() {
|
|
Instance = this;
|
|
playerInputActions = new();
|
|
playerInputActions.Player.Enable();
|
|
playerInputActions.Player.Interact.performed += InteractPerformed;
|
|
playerInputActions.Player.InteractAlternate.performed += InteractAlternate_performed;
|
|
playerInputActions.Player.Pause.performed += Pause_performed;
|
|
}
|
|
|
|
|
|
public event EventHandler OnInteractAction;
|
|
public event EventHandler OnInteractAlternateAction;
|
|
public event EventHandler OnPauseAction;
|
|
|
|
private void InteractAlternate_performed(InputAction.CallbackContext obj) => OnInteractAlternateAction?.Invoke(this, EventArgs.Empty);
|
|
private void InteractPerformed(InputAction.CallbackContext obj) => OnInteractAction?.Invoke(this, EventArgs.Empty);
|
|
private void Pause_performed(InputAction.CallbackContext obj) => OnPauseAction?.Invoke(this, EventArgs.Empty);
|
|
|
|
public static Vector2 GetMovementVectorNormalized() {
|
|
Vector2 inputVector = playerInputActions.Player.Move.ReadValue<Vector2>();
|
|
return inputVector.normalized;
|
|
}
|
|
} |