-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #159 from amazingalek/tai/InputCommandHandlers
input command handlers
- Loading branch information
Showing
3 changed files
with
88 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
using System; | ||
using UnityEngine; | ||
|
||
namespace OWML.ModHelper.Input | ||
{ | ||
public class ModCommandListener : MonoBehaviour | ||
{ | ||
public event Action OnNewlyPressed; | ||
public event Action OnNewlyReleased; | ||
public event Action OnNewlyHeld; | ||
public event Action OnPressed; | ||
public event Action OnTapped; | ||
public event Action OnHeld; | ||
|
||
private float _minPressDuration, _maxTapDuration; | ||
private SingleAxisCommand _command; | ||
|
||
public void Initialize(SingleAxisCommand command, float minPressDuration = 0.1f, float maxTapDuration = 0.1f) | ||
{ | ||
_command = command; | ||
_minPressDuration = minPressDuration; | ||
_maxTapDuration = maxTapDuration; | ||
} | ||
|
||
private void Start() | ||
{ | ||
DontDestroyOnLoad(gameObject); | ||
} | ||
|
||
private void Update() | ||
{ | ||
if (_command == null) | ||
{ | ||
return; | ||
} | ||
if (_command.IsNewlyPressed()) | ||
{ | ||
OnNewlyPressed?.Invoke(); | ||
} | ||
if (_command.IsNewlyHeld(_minPressDuration)) | ||
{ | ||
OnNewlyHeld?.Invoke(); | ||
} | ||
if (_command.IsNewlyReleased()) | ||
{ | ||
OnNewlyReleased?.Invoke(); | ||
} | ||
if (_command.IsPressed()) | ||
{ | ||
OnPressed?.Invoke(); | ||
} | ||
if (_command.IsHeld(_minPressDuration)) | ||
{ | ||
OnHeld?.Invoke(); | ||
} | ||
if (_command.IsTapped(_maxTapDuration)) | ||
{ | ||
OnTapped?.Invoke(); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using UnityEngine; | ||
|
||
namespace OWML.ModHelper.Input | ||
{ | ||
public class ModCommandUpdater : MonoBehaviour | ||
{ | ||
private InputCommand _command; | ||
|
||
public void Initialize(InputCommand command) | ||
{ | ||
_command = command; | ||
} | ||
|
||
private void Start() | ||
{ | ||
DontDestroyOnLoad(gameObject); | ||
} | ||
|
||
private void Update() | ||
{ | ||
_command?.UpdateInputCommand(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters