Skip to content

Commit

Permalink
- Added 'any key' option to OnInput trigger
Browse files Browse the repository at this point in the history
  • Loading branch information
DiogoDeAndrade committed Mar 29, 2024
1 parent 1bb3cc8 commit ef1d320
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 6 deletions.
6 changes: 5 additions & 1 deletion Assets/OkapiKit/Scripts/Editor/TriggerOnInputEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public override void OnInspectorGUI()
{
actionsName = "Actions while pressed";
elseActionsName = "Actions while released";
}
}
}
else if (inputType == TriggerOnInput.InputType.Key)
{
Expand All @@ -88,6 +88,10 @@ public override void OnInspectorGUI()
EditorGUILayout.PropertyField(propAxis, new GUIContent("Axis", "Axis"));
EditorGUILayout.PropertyField(propDeadArea, new GUIContent("Dead Area", "How far from center does the axis have to go for it to execute this trigger?"));
}
else if (inputType == TriggerOnInput.InputType.AnyKey)
{
EditorGUILayout.PropertyField(propContinuous, new GUIContent("Continuous", "If active, this triggers while any key is pressed, if not this trigger only executes when a key is just pressed."));
}
if ((propContinuous.boolValue) || (inputType == TriggerOnInput.InputType.Axis))
{
EditorGUILayout.PropertyField(propNegate, new GUIContent("Negate", "Do we want to trigger this when the input DOESN'T happen, instead of the other way around?"));
Expand Down
24 changes: 22 additions & 2 deletions Assets/OkapiKit/Scripts/Triggers/TriggerOnInput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace OkapiKit
[AddComponentMenu("Okapi/Trigger/On Input")]
public class TriggerOnInput : Trigger
{
public enum InputType { Button = 0, Key = 1, Axis = 2 };
public enum InputType { Button = 0, Key = 1, Axis = 2, AnyKey = 3 };

[SerializeField]
InputType inputType = InputType.Button;
Expand All @@ -33,6 +33,7 @@ public enum InputType { Button = 0, Key = 1, Axis = 2 };
protected ActionTrigger[] elseActions;

float cooldownTimer = 0.0f;
bool prevAnyKey = false;

public override string GetTriggerTitle() => "On Input";

Expand All @@ -41,10 +42,15 @@ public override string GetRawDescription(string ident, GameObject refObject)
string desc = "When ";
if (inputType == InputType.Button) desc += $"button {buttonName} ";
else if (inputType == InputType.Key) desc += $"key {key} ";
else
else if (inputType == InputType.Axis)
{
desc += $"axis {axis} ";
}
else
{
desc += $"any key ";
}

if (continuous)
{
if (negate) desc += "is not held";
Expand Down Expand Up @@ -110,6 +116,20 @@ void Update()
elseTrigger = !isTrigger;
c = true;
}
else if (inputType == InputType.AnyKey)
{
if (continuous)
{
isTrigger = Input.anyKey;
elseTrigger = !Input.anyKey;
}
else
{
isTrigger = Input.anyKeyDown;
elseTrigger = !Input.anyKey && prevAnyKey;
}
prevAnyKey = Input.anyKey;
}

if ((c) && (negate))
{
Expand Down
2 changes: 1 addition & 1 deletion Assets/OkapiKit/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "com.videojogoslusofona.okapikit",
"displayName": "OkapiKit",
"version": "1.14.1",
"version": "1.15.0",
"unity": "2022.3",
"description": "OkapiKit is a toolkit for creation of simple games without code.",
"keywords": [ "kit" ],
Expand Down
4 changes: 2 additions & 2 deletions Assets/OkapiKitSamples/package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"name": "com.videojogoslusofona.okapikit.samples",
"displayName": "OkapiKit Samples",
"version": "1.14.1",
"version": "1.15.0",
"unity": "2022.3",
"description": "OkapiKit is a toolkit for creation of simple games without code. This package is just the samples for OkapiKit, they are not required to use Okapi Kit, and requires the Okapi Kit package.",
"keywords": [ "okapi", "samples" ],
"category": "samples",
"dependencies": {},
"relatedPackages": {
"com.videojogoslusofona.okapikit": "1.14.1"
"com.videojogoslusofona.okapikit": "1.15.0"
},
"author": {
"name": "Videojogos ULHT",
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ cursor on top of the Trigger icon (blue dot) on the Player object and we can see
[Master484]:http://m484games.ucoz.com/
[Warspawn]:https://opengameart.org/users/warspawn
[pansapiens]:https://opengameart.org/users/pansapiens
[rileygombart]:https://opengameart.org/users/rileygombart
[chabull]:https://opengameart.org/users/chabull
[IMakeGames]:http://www.imake-games.com/
[Winternaut]:https://opengameart.org/users/winternaut
Expand Down
4 changes: 4 additions & 0 deletions ReleaseNotes.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Release Notes

## V1.15.0

- Added "any key" option to OnInput trigger

## V1.14.1

- Fixed issue with builds in version V1.14.0
Expand Down
3 changes: 3 additions & 0 deletions Todo.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ Features:
- Add insert point option for path
- Comment Code
- Documentation
- Support for Analytics (extra package?)
- Add OnDestroy event

Usability:
----------
Expand All @@ -34,6 +36,7 @@ Usability:
- Add node ID property to actions/triggers
- Remove Naughty Attributes completely (reduce dependencies)
- On single-line OkapiValue, add a "Value" label to the edit boxes, so we can increase/decrease value by dragging
- Disable hierarchy icons on OkapiConfig

Simple usage:
-------------
Expand Down

0 comments on commit ef1d320

Please sign in to comment.