Skip to content

LayeredAction

Eric Lowry edited this page Nov 15, 2024 · 7 revisions

Namespace: namespace Lowry.UI.InputLayers

public class LayeredAction

Used to represent an IL_Action and register its InputAction🔗, but filtered to only fire when the desired InputLayer (_layer) is active.

💡General Information

This class is used as a filtering system for Unity's InputAction🔗 within the context of InputLayers.

The core concept is that events raised by the InputAction🔗 will only be passed onto this script's delegates if the _layer it is registered under is active.

Usage

This class is designed to be exposed as a serialized field🔗 within your own scripts in order to expose its custom property drawer in your Unity Inspector.

This allows you to easily select a specific InputAction🔗 and the InputLayer it should be registered to.

Then, you can simply react to its delegates in order to perform the desired actions.

Tip: In cases where another type of input should trigger the same effect as this LayeredAction (such as clicking on a button instead of using a controller input to activate it), then you can filter it based on _layer._isActive, or use the _layer.onActivated and _layer.onDeactivated events to know if the action's layer is currently active.

📄Fields

_action

private IL_Action _action;

Used to represent the InputAction🔗 this acts as a filtered pass-through for.

_layer

public InputLayer _layer;

The InputLayer that must be active for these actions to be performed.

📄Properties

_inputAction

public InputAction _inputAction { get {...} }

The InputAction🔗 this acts as a filtered pass-through for.

_name

public string _name { get {...} }

The name of the InputAction🔗 this acts as a filtered pass-through for.

_type

public InputActionType _type { get {...} }

The InputActionType🔗 of the InputAction🔗 this acts as a filtered pass-through for.

📄Delegates

onPerformedEvent

public event Action<CallbackContext> onPerformedEvent;

Triggered when _action gets Performed and _layer is active.

onStartedEvent

public event Action<CallbackContext> onStartedEvent;

Triggered when _action gets Started and _layer is active.

onCanceledEvent

public event Action<CallbackContext> onCanceledEvent;

Triggered when _action gets Calceled and _layer is active.

📄Methods

Enable(bool, bool)

public void Enable (bool enableMap = false, bool enableAction = false) {...}

Initializes this action, enabling it and/or the entire map it belongs to.
The map will remain enabled as long as s that belong to it are enabled.

Parameters:

  • enableMap: If true, the InputActionMap🔗 this action belongs to will be enabled.
    The map will remain enabled as long as LayeredActions that belong to it are enabled.
  • enableAction: If true, the action will be "manually" enabled.

Disable(bool, bool)

public void Disable (bool disableMap = false, bool disableAction = false) {...}

Closes down this action, disabling it and/or the entire map it belongs to.
The map will remain enabled as long as LayeredActions that belong to it are enabled.

Parameters:

  • disableMap: If true, the InputActionMap🔗 this action belongs to will be disabled.
    The map will remain enabled as long as LayeredActions that belong to it are enabled.
  • disableAction: If true, the action will be "manually" disabled.

EnableMap()

public void EnableMap () {...}

Enables the InputActionMap🔗 this action belongs to.

DisableMap()

public void DisableMap () {...}

Tires to disable the InputActionMap🔗 this action belongs to.

ActionPerformed(InputAction.CallbackContext)

public virtual void ActionPerformed (InputAction.CallbackContext context) {...}

Must be called as a result of _action being Performed.

PerformAction(InputAction.CallbackContext?)

public virtual void PerformAction(InputAction.CallbackContext? context) {...}

Can be called to force the onPerformedEvent to be triggered as long as _layer is active.

Parameters:

  • context: Should be left as null when using this method manually.

ActionStarted(InputAction.CallbackContext)

public virtual void ActionStarted (InputAction.CallbackContext context) {...}

Must be called as a result of _action being Started.

StartAction(InputAction.CallbackContext?)

public virtual void StartAction(InputAction.CallbackContext? context) {...}

Can be called to force the onStartedEvent to be triggered as long as _layer is active.

Parameters:

  • context: Should be left as null when using this method manually.

ActionCanceled(InputAction.CallbackContext)

public virtual void ActionCanceled (InputAction.CallbackContext context) {...}

Must be called as a result of _action being Canceled.

CancelAction(InputAction.CallbackContext?)

public virtual void CancelAction(InputAction.CallbackContext? context) {...}

Can be called to force the onCanceledEvent to be triggered as long as _layer is active.

Parameters:

  • context: Should be left as null when using this method manually.
Clone this wiki locally