refactor: made the input reader expandable
This commit is contained in:
parent
12304c6bb4
commit
59a3d96b5b
10 changed files with 72 additions and 24 deletions
23
Assets/Scripts/Domain/Input/InputReader.cs
Normal file
23
Assets/Scripts/Domain/Input/InputReader.cs
Normal file
|
@ -0,0 +1,23 @@
|
|||
namespace Domain.Input {
|
||||
public abstract class InputReader {
|
||||
private bool _wasPressed;
|
||||
private bool _isPressed;
|
||||
|
||||
protected abstract int Key { get; }
|
||||
|
||||
public void UpdateInput() {
|
||||
_wasPressed = _isPressed;
|
||||
short keyState = Win32API.GetAsyncKeyState(Key);
|
||||
|
||||
if (_wasPressed && keyState == 0) {
|
||||
_isPressed = false;
|
||||
}else if (!_isPressed && keyState != 0) {
|
||||
_isPressed = true;
|
||||
}
|
||||
}
|
||||
|
||||
public bool KeyDown() => _isPressed && !_wasPressed;
|
||||
public bool KeyPressed() => _isPressed;
|
||||
public bool KeyUp() => !_isPressed && _wasPressed;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue