Skip to content

Commit

Permalink
Add global binding add/remove events
Browse files Browse the repository at this point in the history
  • Loading branch information
TheNathannator committed Feb 14, 2024
1 parent 86ecd2c commit a31e673
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions Assets/Script/Input/Bindings/ControlBinding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ public class ActuationSettings
/// </summary>
public abstract class ControlBinding
{
public static event Action<ControlBinding, InputControl> BindingAdded;
public static event Action<ControlBinding, InputControl> BindingRemoved;

/// <summary>
/// Fired when a binding has been added or removed.
/// </summary>
Expand Down Expand Up @@ -97,6 +100,16 @@ public virtual void UpdateForFrame(double updateTime) { }
public abstract void OnDeviceAdded(InputDevice device);
public abstract void OnDeviceRemoved(InputDevice device);

protected void FireBindingAdded(InputControl control)
{
BindingAdded?.Invoke(this, control);
}

protected void FireBindingRemoved(InputControl control)
{
BindingRemoved?.Invoke(this, control);
}

protected void FireBindingsChanged()
{
BindingsChanged?.Invoke();
Expand Down Expand Up @@ -368,6 +381,7 @@ private void AddBinding(TBinding binding)
{
_bindings.Add(binding);
InputState.AddChangeMonitor(binding.Control, this, _bindings.Count - 1);
FireBindingAdded(binding.Control);
}

private bool RemoveBindings(Func<TBinding, bool> selector)
Expand All @@ -385,6 +399,7 @@ private bool RemoveBindings(Func<TBinding, bool> selector)
{
removed = true;
_bindings.RemoveAt(i);
FireBindingRemoved(binding.Control);
i--;
}
else
Expand Down

0 comments on commit a31e673

Please sign in to comment.