Skip to content

IL_Layer

Eric Lowry edited this page Aug 5, 2023 · 3 revisions

Namespace: namespace Lowry.UI.InputLayers

public sealed class IL_Layer : IComparable<IL_Layer>, IEquatable<IL_Layer>

An individual input layer to be stored within a IL_ScriptableRefs._layers List and used in placed inside the IL_ScriptableRefs._layers.

💡General Information

This class represents the core element of the InputLayers system, Layers. Layers are stored and organized within the IL_ScriptableRefs singleton scriptable object.

The basic usage of layers is that only the last one to have been Activated is considered active (_isActive). So any inputs or systems that rely on a specific layer to be active should only be available/functional when it is.

This uses a "stack" system so that as layers are Deactivated, previously activated layers become active again.

Example:
In your UI, if a popup appears and activates a new layer when it does; all the character controls (registered to a lower layer using a LayeredAction) will stop responding, whereas the popup's buttons will.
However, when the popup is closed, its layer will be deactivated, and the layer handling character controls will take back priority.

Each layer is unique and must have a unique name. This value is used to reference and store the layer.

Note: Layers are stored inside IL_PriorityLayers, which can cause more recently active layers to not take priority when Activated.

📄Fields

_frameActivated

private int _frameActivated;

Stores the Time.frameCount🔗 to ensure that the layer is not used on the same frame as it was activated on.

_name

private string _name;

The layer's name
This must be unique!

Publicly accessible through name.

📄Properties

_priority

public int? _priority { get {...} }

The priority this layer belongs to within the IL_ScriptableRefs.r_priorities .

_isActive

public bool _isActive { get {...} }

true if this layer is currently active.

_notActivatedThisFrame

internal bool _notActivatedThisFrame { get {...} }

Security: Ensures that the layer is not considered active on the same frame as it was activated on.
Otherwise, an input could be used to activate a layer, and then be triggered on that same layer immediately.

name

public string name { get {...} set {...} }

The layer's name
This must be unique!

📄Delegates

onActivated

public Action onActivated;

Is called when the layer has just been activated.
The layer will be active whenever it is at the top of the highest priority (non-empty) IL_ScriptableRefs.r_priorities's IL_PriorityLayer._layers StackableList.

onDeactivated

public Action onDeactivated;

Is called when the layer has just been deactivated.
The layer will be deactivated unless it is at the top of the highest priority (non-empty) IL_ScriptableRefs.r_priorities's IL_PriorityLayer._layers StackableList.

📄Methods

Activate()

public bool? Activate () {...}

Tries to activate this layer.

Returns:

  • true when the layer has been activated (or was already active).
  • false when the layer has not been activated (it will still be added to the relevant stack).
  • null when the layer isn't present inside any of the IL_ScriptableRefs.r_priorities.

Deactivate()

public void Deactivate () {...}

Deactivates a layer; also removes it from the relevant stack if present.

Activated()

internal void Activated () {...}

Must be called whenever the layer is activated.

Deactivated()

internal void Deactivated () {...}

Must be called whenever the layer is deactivated.

📒Notes

All the IComparable and IEquatable implementations are built by comparing _name values, as each layer has a unique name, which is its primary identifier.