Interface IInputContextManager
Defines the contract for a stack-based input context manager that controls which Unity Input System action maps are active at any given time and which contexts are permitted to process input based on a priority-and-blocking model.
Namespace: Scylla.Input
Assembly: ScyllaInput.dll
Syntax
public interface IInputContextManager
Remarks
An input context (represented by InputContext) describes a named mode of the game (e.g., Gameplay, Menu, Dialog) together with the set of action maps that should be enabled or disabled while that mode is active. Contexts are stacked in LIFO order; the context at the top of the stack is the active context.
Blocking rules determine whether lower-level contexts on the stack still process input:
-
A context with BlocksLowerPriority set to
trueprevents all contexts with a lower Priority value from receiving input. -
A context with ConsumesAllInput set to
trueprevents every context below it on the stack - regardless of priority - from receiving input. This is the strongest form of blocking.
Before pushing or querying a context by ID, the context must be registered via RegisterContext(InputContext). Contexts can also be pushed directly (auto-registering if needed) using the PushContext(InputContext) overload.
The concrete implementation is InputContextManager. Access it through
ScyllaInput.Instance.ContextManager.
Properties
ActiveContext
Gets the context currently at the top of the stack - the one whose action maps and
blocking rules are applied most recently. Returns null when the stack is empty.
Declaration
InputContext ActiveContext { get; }
Property Value
| Type | Description |
|---|---|
| InputContext |
ContextStack
Gets a read-only snapshot of the current context stack ordered from top (index 0) to bottom (highest index). Contexts lower in the list may be blocked depending on the blocking flags of contexts above them.
Declaration
IReadOnlyList<InputContext> ContextStack { get; }
Property Value
| Type | Description |
|---|---|
| IReadOnlyList<InputContext> |
IsInitialized
Gets whether Initialize(IInputActionManager) has been called and completed successfully.
Registration and stack operations are only valid while the manager is initialized.
The value is reset to false by Shutdown().
Declaration
bool IsInitialized { get; }
Property Value
| Type | Description |
|---|---|
| bool |
StackDepth
Gets the number of contexts currently on the stack. A value of 0 means the
stack is empty and ActiveContext is null.
Declaration
int StackDepth { get; }
Property Value
| Type | Description |
|---|---|
| int |
Methods
ClearContextStack()
Removes all contexts from the stack by calling PopContext() repeatedly until the stack is empty. Each pop fires the standard events.
Declaration
void ClearContextStack()
GetAllContexts()
Returns a snapshot list containing all currently registered contexts in an unspecified order. The returned list is a new collection; modifications to it do not affect the manager's internal registry.
Declaration
IReadOnlyList<InputContext> GetAllContexts()
Returns
| Type | Description |
|---|---|
| IReadOnlyList<InputContext> | A new IReadOnlyList<T> of all registered InputContext
instances. May be empty but never |
GetContext(string)
Retrieves a registered context by its ID without affecting the stack.
Declaration
InputContext GetContext(string contextID)
Parameters
| Type | Name | Description |
|---|---|---|
| string | contextID | The ID of the context to retrieve. A null or empty string returns |
Returns
| Type | Description |
|---|---|
| InputContext | The InputContext instance, or |
GetContextStackPosition(string)
Returns the zero-based position of the context in the stack, where 0 is the
top (most recently pushed) context.
Declaration
int GetContextStackPosition(string contextID)
Parameters
| Type | Name | Description |
|---|---|---|
| string | contextID | The context ID to locate. A null or empty string returns |
Returns
| Type | Description |
|---|---|
| int | The stack index of the context (0 = top), or |
HasContext(string)
Returns whether a context with the given ID is currently registered (not necessarily on the stack). Use IsContextActive(string) to check stack membership.
Declaration
bool HasContext(string contextID)
Parameters
| Type | Name | Description |
|---|---|---|
| string | contextID | The context ID to look up. A null or empty string returns |
Returns
| Type | Description |
|---|---|
| bool |
|
Initialize(IInputActionManager)
Initializes the context manager with a reference to the action manager used to apply action map enable/disable changes when contexts are pushed or popped. Must be called once before any stack operations. Calling a second time while already initialized logs a warning and has no effect.
Declaration
void Initialize(IInputActionManager actionManager)
Parameters
| Type | Name | Description |
|---|---|---|
| IInputActionManager | actionManager | The IInputActionManager used to enable and disable Unity Input System
action maps. Must not be |
IsContextActive(string)
Returns whether the context with the given ID is currently present anywhere on the context stack. Does not indicate whether the context is blocked; use ShouldProcessInput(string) for combined active+unblocked checking.
Declaration
bool IsContextActive(string contextID)
Parameters
| Type | Name | Description |
|---|---|---|
| string | contextID | The context ID to look for. A null or empty string returns |
Returns
| Type | Description |
|---|---|
| bool |
|
IsContextBlocked(string)
Returns whether the context with the given ID is prevented from receiving input by
a higher-positioned context on the stack. A context that is not on the stack at all
is also considered blocked (returns true).
Declaration
bool IsContextBlocked(string contextID)
Parameters
| Type | Name | Description |
|---|---|---|
| string | contextID | The context ID to evaluate. A null or empty string returns |
Returns
| Type | Description |
|---|---|
| bool |
|
PopContext()
Removes the context currently at the top of the stack, applies the new top context's action maps, fires the OnContextPopped and OnContextChanged events, and publishes the corresponding Scylla events.
Declaration
InputContext PopContext()
Returns
| Type | Description |
|---|---|
| InputContext | The context that was removed, or |
PopToContext(string)
Repeatedly calls PopContext() until the specified context is at the top
of the stack. If the context is not on the stack at all, no contexts are popped and
0 is returned. Each pop fires the standard events.
Declaration
int PopToContext(string contextID)
Parameters
| Type | Name | Description |
|---|---|---|
| string | contextID | The ID of the target context that should become the new top after popping.
A null or empty string returns |
Returns
| Type | Description |
|---|---|
| int | The number of contexts that were popped. Returns |
PushContext(InputContext)
Pushes the given InputContext directly onto the top of the stack. If the context is not yet registered it is auto-registered before being pushed. Applies action maps and fires the same events as PushContext(string).
Declaration
bool PushContext(InputContext context)
Parameters
| Type | Name | Description |
|---|---|---|
| InputContext | context | The context to push. Must not be |
Returns
| Type | Description |
|---|---|
| bool |
|
PushContext(string)
Pushes a registered context onto the top of the stack by its ID. Applies the context's action maps, updates IsActive and IsTopContext flags, fires the OnContextPushed and OnContextChanged events, and publishes the corresponding Scylla events.
Declaration
bool PushContext(string contextID)
Parameters
| Type | Name | Description |
|---|---|---|
| string | contextID | The ID of the context to push. The context must already be registered via
RegisterContext(InputContext). A null or empty string returns |
Returns
| Type | Description |
|---|---|
| bool |
|
RegisterContext(InputContext)
Adds the given InputContext to the registry of known contexts so it can be pushed by ID later. Each context ID must be unique within the manager.
Declaration
bool RegisterContext(InputContext context)
Parameters
| Type | Name | Description |
|---|---|---|
| InputContext | context | The context to register. Must not be |
Returns
| Type | Description |
|---|---|
| bool |
|
RemoveContext(string)
Removes a context from any position in the stack, not just the top. If the removed context was the top context, the new top is activated and action maps are re-applied. Fires OnContextPopped and, if the top changed, OnContextChanged.
Declaration
bool RemoveContext(string contextID)
Parameters
| Type | Name | Description |
|---|---|---|
| string | contextID | The ID of the context to remove. A null or empty string returns |
Returns
| Type | Description |
|---|---|
| bool |
|
ShouldProcessInput(string)
Returns whether a context is both on the stack and not blocked by any higher-priority
context. Equivalent to IsContextActive(id) && !IsContextBlocked(id).
Use this as the primary gate before polling input for a context-specific action.
Declaration
bool ShouldProcessInput(string contextID)
Parameters
| Type | Name | Description |
|---|---|---|
| string | contextID | The context ID to evaluate. A null or empty string returns |
Returns
| Type | Description |
|---|---|
| bool |
|
Shutdown()
Shuts down the context manager: clears the context stack (firing all pop events),
clears the registry, releases the action manager reference, sets
IsInitialized to false, and nullifies all event delegates. Has
no effect if the manager is not currently initialized.
Declaration
void Shutdown()
UnregisterContext(string)
Removes a context from the registry. If the context is currently on the stack it is also removed from the stack (equivalent to calling RemoveContext(string) first), triggering the appropriate events.
Declaration
bool UnregisterContext(string contextID)
Parameters
| Type | Name | Description |
|---|---|---|
| string | contextID | The ID of the context to unregister. A null or empty string causes the method to
return |
Returns
| Type | Description |
|---|---|
| bool |
|
Update()
Performs any per-frame maintenance required by the context manager. Called automatically by the Input module each frame. The current implementation is a no-op because context changes are entirely event-driven, but the method is reserved for future features such as time-based context expiry.
Declaration
void Update()
Events
OnContextChanged
Raised whenever the active (top-of-stack) context changes, either because a new
context was pushed or the top context was popped or removed. The first argument is
the previous top context (may be null if the stack was empty), and the second
argument is the new top context (may be null if the stack is now empty).
Declaration
event Action<InputContext, InputContext> OnContextChanged
Event Type
| Type | Description |
|---|---|
| Action<InputContext, InputContext> |
OnContextPopped
Raised after a context has been removed from the top of the stack (via PopContext()) or from an arbitrary position (via RemoveContext(string)) and its deactivation callback has been invoked. The argument is the removed context.
Declaration
event Action<InputContext> OnContextPopped
Event Type
| Type | Description |
|---|---|
| Action<InputContext> |
OnContextPushed
Raised after a context has been pushed onto the stack and its action maps have been applied. The argument is the newly pushed context.
Declaration
event Action<InputContext> OnContextPushed
Event Type
| Type | Description |
|---|---|
| Action<InputContext> |