InteractionInputTable

Reflection-based collection that auto-discovers methods marked with [InteractionInput] on an Interaction subclass, creates InteractionInput entries for each unique input name, and manages binding/unbinding all inputs as a group. Implements IEnumerable<InteractionInput> for iteration and ISerializationCallbackReceiver to refresh bindings on deserialization.

Definition

Namespace: Paragon.Townskeep.InteractionSystem Assembly: Townskeep.dll

[Serializable, HideReferenceObjectPicker]
public class InteractionInputTable : IEnumerable<InteractionInput>, ISerializationCallbackReceiver

Implements: IEnumerable<InteractionInput>, ISerializationCallbackReceiver

Remarks

InteractionInputTable is the bridge between declarative [InteractionInput] attributes and runtime input handling. It performs two key operations:

  1. Discovery — On construction and after deserialization, it scans the owning Interaction subclass via reflection for methods bearing [InteractionInputAttribute]. Each discovered method is converted to an Action delegate and registered on the corresponding InteractionInput.

  2. Lifecycle ManagementBind() and Unbind() iterate all entries and subscribe/unsubscribe them from Unity's Input System in bulk. This is called automatically by Interaction.OnBegin() and Interaction.OnComplete()/OnCancel().

The table stores inputs in a Dictionary<string, InteractionInput> keyed by the input name. Multiple methods can share the same input name — they are all registered as callbacks on the same InteractionInput entry.

Name Resolution

When [InteractionInput] has an explicit Name, that name is used as the dictionary key. When Name is empty, the method name is split from PascalCase via Odin's SplitPascalCase() extension (e.g., OnChopTree"On Chop Tree").

Quick Lookup

Goal
How

Add a runtime callback

inputTable.AddInputCallback("InputName", callback)

Remove a runtime callback

inputTable.RemoveInputCallback("InputName", callback)

Check if input exists

inputTable.TryGetInputCallback("InputName", out input)

Subscribe all to Unity

inputTable.Bind()

Unsubscribe all from Unity

inputTable.Unbind()

Get input count

inputTable.Count

Properties

Count

The number of registered InteractionInput entries.

Constructor

Parameter
Type
Description

interaction

Interaction

The owning interaction to scan for [InteractionInput] methods

Creates the table, stores the interaction reference, and immediately calls UpdateInteractionInputs() to discover and register all attributed methods.

Methods

AddInputCallback

Adds a callback to an existing named input at runtime.

Parameter
Type
Description

inputName

string

The name of the input (must match a discovered entry)

callback

Action

The callback to add

circle-exclamation

RemoveInputCallback

Removes a callback from an existing named input.

Parameter
Type
Description

inputName

string

The name of the input

callback

Action

The callback to remove

circle-exclamation

TryGetInputCallback

Attempts to retrieve an InteractionInput by name.

Parameter
Type
Description

inputName

string

The name to look up

interactionInput

out InteractionInput

The found input, or null

Returns: true if the input was found.

Bind

Subscribes all InteractionInput entries to their respective Unity InputAction phase events. Called automatically by Interaction.OnBegin() when the interactor has input control.

Unbind

Unsubscribes all InteractionInput entries from their respective Unity InputAction phase events. Called automatically by Interaction.OnComplete() and Interaction.OnCancel().

GetEnumerator

Iterates over all InteractionInput values in the table.

Internal Mechanism

UpdateInteractionInputs

Called on construction and OnAfterDeserialize(). Performs the full discovery and registration pipeline:

circle-info

UpdateInteractionInputs() preserves serialized InteractionInput instances (including their InputActionReference and InputPhase settings) when possible. If an input name already exists in the table, the existing instance is reused — only its callbacks are refreshed.

Common Pitfalls

circle-exclamation
circle-exclamation
circle-exclamation

Examples

Accessing the table from an Interaction

Querying inputs

See Also

Last updated