Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using UnityEngine;
- using UnityEngine.InputSystem;
- namespace InputReader
- {
- [CreateAssetMenu(menuName = "Input Reader")]
- public class InputReader : ScriptableObject, GameInput.IGameplayActions, GameInput.IUIActions, GameInput.IActive_InventoryActions
- {
- public event Action<Vector2> OnMoveEvent;
- public event Action OnNormalAttack;
- public event Action OnAttackStopped;
- public event Action OnDashEvent;
- public event Action OnPauseEvent;
- public event Action OnResumeEvent;
- public event Action<int> OnToggleItemSlot;
- #region Exposed_Variables
- #endregion
- #region Private_Variables
- private GameInput _gameInput;
- #endregion
- #region Public_Variables
- #endregion
- #region Unity_Calls
- private void OnEnable()
- {
- if (_gameInput == null)
- {
- _gameInput = new GameInput();
- _gameInput.Gameplay.SetCallbacks(this);
- _gameInput.UI.SetCallbacks(this);
- _gameInput.Active_Inventory.SetCallbacks(this);
- SetGameplay();
- }
- }
- #endregion
- #region Private_Methods
- #endregion
- #region Public_Methods
- public void SetGameplay()
- {
- _gameInput.Gameplay.Enable();
- _gameInput.Active_Inventory.Enable();
- _gameInput.UI.Disable();
- }
- public void SetUI()
- {
- _gameInput.Gameplay.Disable();
- _gameInput.UI.Enable();
- _gameInput.Active_Inventory.Disable();
- }
- #endregion
- #region GamePlay
- public void OnMove(InputAction.CallbackContext context)
- {
- OnMoveEvent?.Invoke(context.ReadValue<Vector2>());
- }
- public void OnNormal_Attack(InputAction.CallbackContext context)
- {
- if (context.performed)
- {
- OnNormalAttack?.Invoke();
- }
- if (context.canceled)
- {
- OnAttackStopped?.Invoke();
- }
- }
- public void OnDash(InputAction.CallbackContext context)
- {
- if (context.performed)
- {
- OnDashEvent?.Invoke();
- }
- }
- public void OnPause(InputAction.CallbackContext context)
- {
- if (context.performed)
- {
- OnPauseEvent?.Invoke();
- SetUI();
- }
- }
- #endregion
- #region UI
- public void OnResume(InputAction.CallbackContext context)
- {
- if (context.performed)
- {
- OnResumeEvent?.Invoke();
- SetGameplay();
- }
- }
- #endregion
- #region Active Inventory
- public void OnActiveItemSlot(InputAction.CallbackContext context)
- {
- if (context.performed)
- {
- OnToggleItemSlot?.Invoke((int)context.ReadValue<float>());
- }
- }
- #endregion
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement