refactor: Nullable Keyboard Input Actions
This commit is contained in:
parent
6af84bcb6d
commit
89b756a615
|
@ -9,8 +9,8 @@ namespace Pong.Behaviours;
|
|||
|
||||
public class KeyboardInputsBehaviour : BehaviourOverride, IButtonInputs<Keys>
|
||||
{
|
||||
private readonly Dictionary<Keys, Action<IButtonInputs<Keys>, Keys>> OnPressed = new(256);
|
||||
private readonly Dictionary<Keys, Action<IButtonInputs<Keys>, Keys>> OnReleased = new(256);
|
||||
private readonly Dictionary<Keys, Action<IButtonInputs<Keys>, Keys>?> OnPressed = new(256);
|
||||
private readonly Dictionary<Keys, Action<IButtonInputs<Keys>, Keys>?> OnReleased = new(256);
|
||||
|
||||
private int cachePressedCurrentlyCount = 0;
|
||||
private readonly Keys[] cachePressedCurrently = new Keys[256];
|
||||
|
@ -68,7 +68,7 @@ public class KeyboardInputsBehaviour : BehaviourOverride, IButtonInputs<Keys>
|
|||
if (WasPressed(currentlyPressedKey))
|
||||
continue;
|
||||
|
||||
action.Invoke(this, currentlyPressedKey);
|
||||
action?.Invoke(this, currentlyPressedKey);
|
||||
}
|
||||
|
||||
for (int i = 0; i < cachePressedPreviouslyCount; i++)
|
||||
|
@ -81,7 +81,7 @@ public class KeyboardInputsBehaviour : BehaviourOverride, IButtonInputs<Keys>
|
|||
if (IsPressed(previouslyPressedKey))
|
||||
continue;
|
||||
|
||||
action.Invoke(this, previouslyPressedKey);
|
||||
action?.Invoke(this, previouslyPressedKey);
|
||||
}
|
||||
|
||||
Array.Copy(cachePressedCurrently, cachePressedPreviously, cachePressedCurrentlyCount);
|
||||
|
|
Loading…
Reference in New Issue