using UnityEngine.Events ;
[CreateAssetMenu(fileName = "InputReader", menuName = "Game/Input Reader")]
public class InputReader : ScriptableObject , GameInput . IGameplayActions
public class InputReader : ScriptableObject , GameInput . IGameplayActions , GameInput . IDialoguesActions
// gameplay
public event UnityAction jumpEvent ;
public event UnityAction jumpCanceledEvent ;
public event UnityAction attackEvent ;
public event UnityAction enableMouseControlCameraEvent ;
public event UnityAction disableMouseControlCameraEvent ;
public GameInput gameInput ;
// Dialogue
public event UnityAction advanceDialogueEvent = delegate { } ;
public event UnityAction onMoveSelectionEvent = delegate { } ;
private GameInput gameInput ;
private void OnEnable ( )
{
gameInput . Gameplay . SetCallbacks ( this ) ;
gameInput . Dialogues . SetCallbacks ( this ) ;
gameInput . Gameplay . Enable ( ) ;
EnableGameplayInput ( ) ;
gameInput . Gameplay . Disable ( ) ;
DisableAllInput ( ) ;
& & context . phase = = InputActionPhase . Performed )
& & context . phase = = InputActionPhase . Performed )
attackEvent . Invoke ( ) ;
}
& & context . phase = = InputActionPhase . Performed )
& & context . phase = = InputActionPhase . Performed )
extraActionEvent . Invoke ( ) ;
}
& & context . phase = = InputActionPhase . Performed )
& & context . phase = = InputActionPhase . Performed )
interactEvent . Invoke ( ) ;
}
& & context . phase = = InputActionPhase . Performed )
& & context . phase = = InputActionPhase . Performed )
& & context . phase = = InputActionPhase . Canceled )
& & context . phase = = InputActionPhase . Canceled )
jumpCanceledEvent . Invoke ( ) ;
}
public void OnPause ( InputAction . CallbackContext context )
{
if ( pauseEvent ! = null
& & context . phase = = InputActionPhase . Performed )
& & context . phase = = InputActionPhase . Performed )
pauseEvent . Invoke ( ) ;
}
if ( context . phase = = InputActionPhase . Canceled )
disableMouseControlCameraEvent ? . Invoke ( ) ;
}
private bool IsDeviceMouse ( InputAction . CallbackContext context ) = > context . control . device . name = = "Mouse" ;
public void OnMoveSelection ( InputAction . CallbackContext context )
{
if ( context . phase = = InputActionPhase . Performed )
onMoveSelectionEvent ( ) ;
private bool IsDeviceMouse ( InputAction . CallbackContext context ) = > context . control . device . name = = "Mouse" ;
public void OnAdvanceDialogue ( InputAction . CallbackContext context )
{
if ( context . phase = = InputActionPhase . Performed )
advanceDialogueEvent ( ) ;
}
public void EnableDialogueInput ( )
{
gameInput . Dialogues . Enable ( ) ;
gameInput . Gameplay . Disable ( ) ;
}
public void EnableGameplayInput ( )
{
gameInput . Gameplay . Enable ( ) ;
gameInput . Dialogues . Disable ( ) ;
}
public void DisableAllInput ( )
{
gameInput . Gameplay . Disable ( ) ;
gameInput . Dialogues . Disable ( ) ;
}
}