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