Game.Input.InputBarrier
Assembly: Game
Namespace: Game.Input
Type: class
Base: System.Object, System.IDisposable
Summary: InputBarrier is a lightweight helper that groups one or more ProxyActionMap and/or ProxyAction instances and can temporarily block input for a specified device mask. When blocked or when the device mask changes the barrier updates the state of the associated action maps and actions. It also registers itself with the maps/actions so they can be aware of active barriers. Call Dispose to unregister the barrier and restore states.
Fields
-
private readonly ProxyActionMap[] m_Maps
Stores the ProxyActionMap instances associated with this barrier. These maps receive this barrier in their m_Barriers collection when the barrier is constructed. -
private readonly ProxyAction[] m_Actions
Stores the ProxyAction instances associated with this barrier. These actions receive this barrier in their m_Barriers collection when the barrier is constructed. -
private readonly string m_Name
The barrier name provided at construction or the default "InputBarrier". Exposed via the name property. -
private bool m_Blocked
Internal flag that indicates whether the barrier is currently blocking input. Backing field for the blocked property; setting the property triggers Update() when changed. -
private InputManager.DeviceType m_Mask
Device type mask that restricts which input devices the barrier affects. Backing field for the mask property; changing it triggers Update(). -
private bool m_Disposed
Tracks whether Dispose() has been called. When true, further modifications (blocked/mask) are ignored and disposal is one-time.
Properties
-
public string name { get; }
Read-only name of the barrier (m_Name). -
public IReadOnlyList<ProxyActionMap> maps { get; }
Read-only list of associated ProxyActionMap instances (m_Maps). -
public IReadOnlyList<ProxyAction> actions { get; }
Read-only list of associated ProxyAction instances (m_Actions). -
public bool blocked { get; private set }
When set, toggles whether the barrier is blocking input. Setter will ignore changes if the barrier is already disposed; when changed it sets m_Blocked and calls Update() to refresh the state of associated maps/actions. -
public InputManager.DeviceType mask { get; set; }
Device type mask controlling which input devices the barrier affects. Changing the mask (unless disposed and unless unchanged) sets m_Mask and calls Update().
Constructors
-
public InputBarrier(string barrierName, ProxyActionMap map, InputManager.DeviceType mask = InputManager.DeviceType.All, bool blocked = false)
Creates a barrier for a single ProxyActionMap. Registers the barrier with the supplied map (adds to map.m_Barriers) and sets initial mask and blocked state. Throws ArgumentNullException if map is null. -
public InputBarrier(string barrierName, ProxyAction action, InputManager.DeviceType mask = InputManager.DeviceType.All, bool blocked = false)
Creates a barrier for a single ProxyAction. Registers the barrier with the supplied action (adds to action.m_Barriers) and sets initial mask and blocked state. Throws ArgumentNullException if action is null. -
public InputBarrier(string barrierName, IList<ProxyActionMap> maps, IList<ProxyAction> actions, InputManager.DeviceType mask = InputManager.DeviceType.All, bool blocked = false)
Creates a barrier for multiple maps and actions. Null checks the provided lists, removes null entries and duplicates via Where/Distinct/ToArray, registers the barrier with each non-null map/action, sets mask and initial blocked state. Throws ArgumentNullException if maps or actions is null. -
public InputBarrier(string barrierName, IList<ProxyActionMap> maps, InputManager.DeviceType mask = InputManager.DeviceType.All, bool blocked = false)
Convenience overload for multiple maps (no actions). Calls the main maps+actions constructor with an empty actions list. -
public InputBarrier(string barrierName, IList<ProxyAction> actions, InputManager.DeviceType mask = InputManager.DeviceType.All, bool blocked = false)
Convenience overload for multiple actions (no maps). Calls the main maps+actions constructor with an empty maps list.
Methods
-
private void Update() : System.Void
Internal helper that calls UpdateState() on each associated ProxyActionMap and ProxyAction. This is invoked whenever blocked or mask changes (and the barrier is not disposed) to let the proxies recompute their effective state considering active barriers. -
public void Dispose() : System.Void
Unregisters the barrier from all associated maps and actions (removes itself from their m_Barriers collections), calls UpdateState() on each to refresh their state, and marks the barrier as disposed. Dispose is idempotent — further calls do nothing.
Usage Example
// Create a barrier for a single map and block it for all devices
var barrier = new InputBarrier("UIBlock", someProxyActionMap, InputManager.DeviceType.All, blocked: true);
// Temporarily unblock input for keyboard only
barrier.mask = InputManager.DeviceType.Keyboard;
barrier.blocked = false;
// Create a barrier for multiple actions
var actions = new List<ProxyAction> { actionA, actionB };
var actionBarrier = new InputBarrier("ActionsBarrier", actions, InputManager.DeviceType.Gamepad, blocked: true);
// When finished, remove the barrier so maps/actions no longer consider it
actionBarrier.Dispose();
barrier.Dispose();
Notes and caveats: - The constructors automatically register the barrier with the provided maps/actions (they add the barrier to their internal m_Barriers), so the maps/actions will reflect the barrier immediately via Update(). - Setting blocked or mask after Dispose() has no effect. - Null lists passed to the multi-list constructor will throw ArgumentNullException. Null elements inside the lists are filtered out; duplicate entries are removed. - This class is not explicitly thread-safe; use from the main/game thread or ensure appropriate synchronization.