-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added SimpleInputHelper to easily simulate a button/key click
- Loading branch information
Showing
6 changed files
with
95 additions
and
14 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,73 @@ | ||
using UnityEngine; | ||
|
||
public static class SimpleInputHelper | ||
{ | ||
private class ButtonClickInput : SimpleInput.ButtonInput | ||
{ | ||
public ButtonClickInput( string key ) : base( key ) { } | ||
|
||
public void OnUpdate() | ||
{ | ||
if( !value ) | ||
value = true; | ||
else | ||
{ | ||
StopTracking(); | ||
SimpleInput.OnUpdate -= OnUpdate; | ||
} | ||
} | ||
} | ||
|
||
private class MouseButtonClickInput : SimpleInput.MouseButtonInput | ||
{ | ||
public MouseButtonClickInput( int key ) : base( key ) { } | ||
|
||
public void OnUpdate() | ||
{ | ||
if( !value ) | ||
value = true; | ||
else | ||
{ | ||
StopTracking(); | ||
SimpleInput.OnUpdate -= OnUpdate; | ||
} | ||
} | ||
} | ||
|
||
private class KeyClickInput : SimpleInput.KeyInput | ||
{ | ||
public KeyClickInput( KeyCode key ) : base( key ) { } | ||
|
||
public void OnUpdate() | ||
{ | ||
if( !value ) | ||
value = true; | ||
else | ||
{ | ||
StopTracking(); | ||
SimpleInput.OnUpdate -= OnUpdate; | ||
} | ||
} | ||
} | ||
|
||
public static void TriggerButtonClick( string button ) | ||
{ | ||
ButtonClickInput buttonClick = new ButtonClickInput( button ); | ||
buttonClick.StartTracking(); | ||
SimpleInput.OnUpdate += buttonClick.OnUpdate; | ||
} | ||
|
||
public static void TriggerMouseButtonClick( int button ) | ||
{ | ||
MouseButtonClickInput mouseButtonClick = new MouseButtonClickInput( button ); | ||
mouseButtonClick.StartTracking(); | ||
SimpleInput.OnUpdate += mouseButtonClick.OnUpdate; | ||
} | ||
|
||
public static void TriggerKeyClick( KeyCode key ) | ||
{ | ||
KeyClickInput keyClick = new KeyClickInput( key ); | ||
keyClick.StartTracking(); | ||
SimpleInput.OnUpdate += keyClick.OnUpdate; | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Binary file not shown.