Skip to content

Commit

Permalink
Try to prevent inputs from getting stuck active when a device disconn…
Browse files Browse the repository at this point in the history
…ects
  • Loading branch information
TheNathannator committed Oct 17, 2024
1 parent 7574bf7 commit 90b14ed
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
7 changes: 7 additions & 0 deletions Assets/Script/Input/Bindings/AxisBinding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,13 @@ public override void UpdateState(double time)
InvokeStateChanged(State);
}

public override void ResetState()
{
RawState = default;
State = default;
InvokeStateChanged(State);
}

private float CalculateState(float rawValue)
{
float max;
Expand Down
8 changes: 8 additions & 0 deletions Assets/Script/Input/Bindings/ButtonBinding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,14 @@ public override void UpdateState(double time)
InvokeStateChanged(State);
}

public override void ResetState()
{
PreviousState = default;
State = default;
_debounceTimer.Stop();
InvokeStateChanged(State);
}

private float CalculateState(float rawValue)
{
return rawValue * _invertSign;
Expand Down
12 changes: 12 additions & 0 deletions Assets/Script/Input/Bindings/ControlBinding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,12 @@ public virtual void UpdateState(double time)
InvokeStateChanged(State);
}

public virtual void ResetState()
{
State = default;
InvokeStateChanged(State);
}

protected void InvokeStateChanged(TState state)
{
StateChanged?.Invoke(state);
Expand Down Expand Up @@ -434,6 +440,12 @@ private bool RemoveBindings(Func<TBinding, bool> selector)
if (selector(binding))
{
removed = true;

// Reset binding state to prevent phantom inputs
binding.ResetState();
OnStateChanged(binding, InputManager.CurrentInputTime);
FireStateChanged();

_bindings.RemoveAt(i);
FireBindingRemoved(binding.Control);
i--;
Expand Down

0 comments on commit 90b14ed

Please sign in to comment.