refactor: made the input reader expandable
This commit is contained in:
parent
12304c6bb4
commit
59a3d96b5b
10 changed files with 72 additions and 24 deletions
5
Assets/Scripts/Domain/Input/CedillaReader.cs
Normal file
5
Assets/Scripts/Domain/Input/CedillaReader.cs
Normal file
|
@ -0,0 +1,5 @@
|
|||
namespace Domain.Input {
|
||||
public class CedillaReader : InputReader {
|
||||
protected override int Key { get; } = 0xBF; //VK_OEM_2 | cedilla
|
||||
}
|
||||
}
|
3
Assets/Scripts/Domain/Input/CedillaReader.cs.meta
Normal file
3
Assets/Scripts/Domain/Input/CedillaReader.cs.meta
Normal file
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: d07951ea53d84d559bda9060a769ce93
|
||||
timeCreated: 1713112770
|
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;
|
||||
}
|
||||
}
|
3
Assets/Scripts/Domain/Input/InputReader.cs.meta
Normal file
3
Assets/Scripts/Domain/Input/InputReader.cs.meta
Normal file
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 3b3b656d6cb1415eab0de81628a5b54e
|
||||
timeCreated: 1713112368
|
Loading…
Add table
Add a link
Reference in a new issue