perf: Check If Inputs Have Been Listened On

This commit is contained in:
Syntriax 2023-11-24 16:18:55 +03:00
parent d60537f940
commit 44bee2df08
1 changed files with 16 additions and 6 deletions

View File

@ -59,16 +59,26 @@ public class KeyboardInputsBehaviour : BehaviourOverride, IKeyboardInputs
for (int i = 0; i < cachePressedCurrentlyCount; i++)
{
Keys currentlyPressedKey = cachePressedCurrently[i];
if (!WasPressed(currentlyPressedKey))
if (OnPressed.TryGetValue(currentlyPressedKey, out var action))
if (!OnPressed.TryGetValue(currentlyPressedKey, out var action))
continue;
if (WasPressed(currentlyPressedKey))
continue;
action.Invoke(this, currentlyPressedKey);
}
for (int i = 0; i < cachePressedPreviouslyCount; i++)
{
Keys previouslyPressedKey = cachePressedPreviously[i];
if (!IsPressed(previouslyPressedKey))
if (OnReleased.TryGetValue(previouslyPressedKey, out var action))
if (!OnReleased.TryGetValue(previouslyPressedKey, out var action))
continue;
if (IsPressed(previouslyPressedKey))
continue;
action.Invoke(this, previouslyPressedKey);
}