Skip to content

Game.Input.InputActivator

Assembly:
(unspecified — typically in the game's runtime assembly, e.g. Assembly-CSharp)

Namespace: Game.Input

Type: class

Base: System.Object

Summary: Manages an "activator" for one or more ProxyAction instances. An InputActivator registers itself with the provided ProxyAction(s), controls whether those actions are considered active (enabled) and limits activation to a set of input devices via a device-type mask. It enforces that activators are not created for built-in actions unless an internal bypass is used. When its enabled flag or device mask changes it forces the associated ProxyAction(s) to update their state. Call Dispose() to unregister the activator when no longer needed.


Fields

  • private ProxyAction[] m_Actions Holds the set of ProxyAction instances this activator manages. Filled from the single-action or multi-action constructors. Null entries are filtered out and duplicates are removed in the multi-action constructor.

  • private string m_Name Name given to the activator (defaults to "InputActivator" when null is provided). Useful for debugging/logging.

  • private bool m_Enabled Internal flag backing the public enabled property. Changing it triggers Update() (unless disposed).

  • private InputManager.DeviceType m_Mask Device-type mask backing the public mask property. Specifies which input devices this activator applies to. Changing it triggers Update() (unless disposed).

  • private bool m_Disposed Tracks whether Dispose() has been called. Once disposed, further changes to enabled/mask are ignored and the activator will no longer be registered with actions.

Properties

  • public string name { get } Read-only; returns the activator name (m_Name). Useful for identifying the activator.

  • public IReadOnlyList<ProxyAction> actions { get } Read-only; returns the array of ProxyAction instances managed by this activator (m_Actions). The list is the deduplicated, non-null collection provided at construction.

  • public bool enabled { get; set } Gets or sets whether the activator is enabled. Setting this triggers Update() which causes each associated ProxyAction to re-evaluate its activation state. If the activator has been disposed, setting is ignored.

  • public InputManager.DeviceType mask { get; set } Gets or sets the device-type mask used by the activator. Setting this triggers Update() which causes each associated ProxyAction to re-evaluate its activation state. If the activator has been disposed, setting is ignored.

Constructors

  • public InputActivator(string activatorName, ProxyAction action, InputManager.DeviceType mask = InputManager.DeviceType.All, bool enabled = false) Creates an activator for a single ProxyAction. Throws ArgumentNullException if action is null. Throws ArgumentException if action.isBuiltIn is true.

  • internal InputActivator(bool ignoreIsBuiltIn, string activatorName, ProxyAction action, InputManager.DeviceType mask = InputManager.DeviceType.All, bool enabled = false) Internal constructor that allows bypassing the built-in action restriction when ignoreIsBuiltIn is true. Registers the activator with the action (adds to action.m_Activators) and sets enabled state.

  • public InputActivator(string activatorName, IList<ProxyAction> actions, InputManager.DeviceType mask = InputManager.DeviceType.All, bool enabled = false) Creates an activator for multiple ProxyAction instances. Null entries are filtered and duplicates removed. Throws ArgumentNullException if actions is null; throws ArgumentException if any action is built-in.

  • internal InputActivator(bool ignoreIsBuiltIn, string activatorName, IList<ProxyAction> actions, InputManager.DeviceType mask = InputManager.DeviceType.All, bool enabled = false) Internal multi-action constructor that can bypass built-in action check. Registers the activator with each action (adds to each action.m_Activators) and sets enabled state.

Methods

  • private void Update() : System.Void Iterates through m_Actions and calls each action's UpdateState() method. Called internally whenever enabled or mask change (and the object is not disposed). Ensures the ProxyAction(s) re-evaluate their effective state considering this activator.

  • public void Dispose() : System.Void Unregisters this activator from all associated ProxyAction instances by removing it from each action's m_Activators collection, and calls UpdateState() on each action to refresh their state. Marks the activator as disposed; after disposal further property changes are ignored.

Usage Example

// Example usage of InputActivator for modded input actions.

ProxyAction myAction = /* get or create a ProxyAction instance (must not be built-in) */;

// Create an activator for a single action, limited to keyboard only, initially disabled:
var activator = new InputActivator("MyActivator", myAction, InputManager.DeviceType.Keyboard, enabled: false);

// Enable the activator so the action becomes active for keyboard:
activator.enabled = true;

// Change the mask to keyboard + mouse:
activator.mask = InputManager.DeviceType.Keyboard | InputManager.DeviceType.Mouse;

// When finished (e.g., on mod unload), make sure to dispose to unregister:
activator.Dispose();

// For multiple actions:
IList<ProxyAction> actions = new List<ProxyAction> { actionA, actionB };
var multi = new InputActivator("MultiActivator", actions, InputManager.DeviceType.All, enabled: true);
// ...
multi.Dispose();

Notes and best practices: - The class registers itself into ProxyAction.m_Activators; do not forget to call Dispose() to remove it and avoid stale references. - Creation will throw if you attempt to create an activator for a built-in action unless you use the internal constructor with ignoreIsBuiltIn = true. - Property changes cause immediate Update() to the associated ProxyAction(s); avoid rapid property thrashing. - Not thread-safe: update/dispose operations should be done on the main/game thread consistent with other input/action operations.