Scylla Framework
  • API Reference
Search Results for

    Show / Hide Table of Contents
    • Scylla.Input
      • AutoResolveChange
      • AutoResolveResult
      • BindingConflict
      • BindingStorageSettings
      • BindingStorageType
      • BridgeSettings
      • BufferedInput
      • ConfigActionEntry
      • ConfigBindingEntry
      • ConfigConflict
      • ConfigSchemeGroup
      • ContextValidationMessage
      • ContextValidationSeverity
      • ControlScheme
      • ControlSchemeChangedEvent
      • ControlSchemeManager
      • ControlSchemeType
      • GamepadButton
      • GamepadType
      • IBindingStorage
      • IControlSchemeManager
      • IInputActionManager
      • IInputBindingManager
      • IInputBridgeManager
      • IInputBufferManager
      • IInputContextManager
      • IInputHintsManager
      • IInputListener
      • IScyllaInputBridge
      • InputActionCanceledEvent
      • InputActionManager
      • InputActionPerformedEvent
      • InputActionStartedEvent
      • InputBindingManager
      • InputBindingsLoadedEvent
      • InputBindingsSavedEvent
      • InputBridgeManager
      • InputBridgeQueryMode
      • InputBufferConsumedEvent
      • InputBufferManager
      • InputBufferedEvent
      • InputConflictResolution
      • InputContext
      • InputContextChangedEvent
      • InputContextDefinition
      • InputContextManager
      • InputContextPoppedEvent
      • InputContextPushedEvent
      • InputDeviceChangedEvent
      • InputDeviceConnectedEvent
      • InputDeviceDisconnectedEvent
      • InputDeviceType
      • InputDeviceUtil
      • InputDisabledEvent
      • InputEnabledEvent
      • InputEventType
      • InputHint
      • InputHintChangedEvent
      • InputHintsManager
      • InputIconSet
      • InputIconSet.IconMapping
      • InputIconSetChangedEvent
      • InputLoggingSettings
      • InputRebindCancelledEvent
      • InputRebindCompletedEvent
      • InputRebindManager
      • InputRebindOperation
      • InputRebindStartedEvent
      • InputRebindUtils
      • JSONFileBindingStorage
      • ManagedRebindCancelledEvent
      • ManagedRebindCompletedEvent
      • ManagedRebindDataRefreshedEvent
      • ManagedRebindStartedEvent
      • PlayerPrefsBindingStorage
      • RebindMode
      • RebindSettings
      • ScyllaInput
      • ScyllaInput.Meta
      • ScyllaInputAction
      • ScyllaInputActionMap
      • ScyllaInputBinding
      • ScyllaInputConfiguration
      • ScyllaInputContextConfiguration
      • ScyllaKey
      • ScyllaKeyConverter
      • ScyllaModifier
      • UnityInputSystemBridge
    • Scylla.Input.Editor
      • ControlSchemeDrawer
      • DeviceStatusWidget
      • IconMappingDrawer
      • InputIconSetEditor
      • ScyllaInputConfigurationEditor
      • ScyllaInputContextConfigurationEditor
      • ScyllaInputDependencyProvider
      • ScyllaInputEditor
      • ScyllaInputMenuItems
      • ScyllaInputWizard

    Class InputContextManager

    Concrete implementation of IInputContextManager that maintains a registry of named InputContext objects and a LIFO stack of active contexts, applying action map changes and publishing Scylla events as contexts are pushed, popped, or removed.

    Inheritance
    object
    InputContextManager
    Implements
    IInputContextManager
    Inherited Members
    object.Equals(object)
    object.Equals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    object.ReferenceEquals(object, object)
    object.ToString()
    Namespace: Scylla.Input
    Assembly: ScyllaInput.dll
    Syntax
    public class InputContextManager : IInputContextManager
    Remarks

    The internal stack is stored as a List<T> where index 0 is the top of the stack. All push operations insert at index 0 (Insert(0, context)) and all pop operations remove at index 0 (RemoveAt(0)), so ActiveContext is always _contextStack[0].

    Blocking is evaluated lazily at query time (in IsContextBlocked(string) and ShouldProcessInput(string)) rather than cached, so blocking state always reflects the current stack composition without any explicit invalidation.

    Every push and pop publishes three notifications: the C# event on this object, a SEX (Scylla Event eXchange) event via Scylla.Core.Events.ScyllaEvents.Publish<TEvent>(TEvent), and log entries at the Info level. Subscribers can choose whichever notification mechanism is most appropriate for their use case.

    An instance is created and owned by the ScyllaInput module and accessed via ScyllaInput.Instance.ContextManager. Do not create additional instances independently of the module lifecycle.

    Constructors

    InputContextManager()

    Initializes a new InputContextManager with empty context registry and stack. Call Initialize(IInputActionManager) before performing any stack operations.

    Declaration
    public InputContextManager()

    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
    public 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
    public 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
    public 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
    public 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
    public 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
    public IReadOnlyList<InputContext> GetAllContexts()
    Returns
    Type Description
    IReadOnlyList<InputContext>

    A new IReadOnlyList<T> of all registered InputContext instances. May be empty but never null.

    GetContext(string)

    Retrieves a registered context by its ID without affecting the stack.

    Declaration
    public InputContext GetContext(string contextID)
    Parameters
    Type Name Description
    string contextID

    The ID of the context to retrieve. A null or empty string returns null.

    Returns
    Type Description
    InputContext

    The InputContext instance, or null if no context with that ID is registered.

    GetContextStackPosition(string)

    Returns the zero-based position of the context in the stack, where 0 is the top (most recently pushed) context.

    Declaration
    public int GetContextStackPosition(string contextID)
    Parameters
    Type Name Description
    string contextID

    The context ID to locate. A null or empty string returns -1.

    Returns
    Type Description
    int

    The stack index of the context (0 = top), or -1 if the context is not on the stack.

    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
    public bool HasContext(string contextID)
    Parameters
    Type Name Description
    string contextID

    The context ID to look up. A null or empty string returns false.

    Returns
    Type Description
    bool

    true if a context with that ID exists in the registry; false otherwise.

    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
    public 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 null.

    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
    public bool IsContextActive(string contextID)
    Parameters
    Type Name Description
    string contextID

    The context ID to look for. A null or empty string returns false.

    Returns
    Type Description
    bool

    true if the context is on the stack at any position; false otherwise.

    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
    public bool IsContextBlocked(string contextID)
    Parameters
    Type Name Description
    string contextID

    The context ID to evaluate. A null or empty string returns true (blocked).

    Returns
    Type Description
    bool

    true if the context is not on the stack, or if any context above it on the stack has ConsumesAllInput set to true, or has BlocksLowerPriority set to true with a higher Priority value. false if the context is on the stack and no blocking context is above it.

    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
    public InputContext PopContext()
    Returns
    Type Description
    InputContext

    The context that was removed, or null if the stack was empty. A warning is logged when attempting to pop an empty stack.

    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
    public 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 0 immediately.

    Returns
    Type Description
    int

    The number of contexts that were popped. Returns 0 if the target context is already at the top or is not on the stack.

    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
    public bool PushContext(InputContext context)
    Parameters
    Type Name Description
    InputContext context

    The context to push. Must not be null. If the context is already on the stack the push is rejected and a warning is logged.

    Returns
    Type Description
    bool

    true if the context was pushed successfully; false if context is null or the context is already on the stack.

    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
    public 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 false without logging.

    Returns
    Type Description
    bool

    true if the context was pushed successfully; false if the ID is null/empty, the context is not registered, or the context is already on the stack.

    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
    public bool RegisterContext(InputContext context)
    Parameters
    Type Name Description
    InputContext context

    The context to register. Must not be null and must have a non-null, non-empty ContextID.

    Returns
    Type Description
    bool

    true if the context was added successfully; false if context is null, has an empty ID, or a context with the same ID is already registered. A warning is logged in all failure cases.

    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
    public bool RemoveContext(string contextID)
    Parameters
    Type Name Description
    string contextID

    The ID of the context to remove. A null or empty string returns false.

    Returns
    Type Description
    bool

    true if the context was found on the stack and removed; false if it was not on the stack.

    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
    public bool ShouldProcessInput(string contextID)
    Parameters
    Type Name Description
    string contextID

    The context ID to evaluate. A null or empty string returns false.

    Returns
    Type Description
    bool

    true if the context is active and not blocked; false if the context is absent from the stack or is blocked by a higher context.

    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
    public 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
    public 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 false immediately without logging.

    Returns
    Type Description
    bool

    true if a context with the given ID was found and removed; false if no such context is registered.

    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
    public 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
    public 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
    public 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
    public event Action<InputContext> OnContextPushed
    Event Type
    Type Description
    Action<InputContext>

    Implements

    IInputContextManager
    In this article
    Back to top Scylla Framework - Input Module API Documentation