Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feat] Added support for the New Unity Input System. #15

Merged
merged 1 commit into from
Jan 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Assets/Plugins/CandyCoded.Forms/CandyCoded.Forms.asmdef
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"name": "CandyCoded.Forms",
"references": [
"UnityEngine.UI"
"UnityEngine.UI",
"Unity.InputSystem"
],
"includePlatforms": [],
"excludePlatforms": [],
Expand Down
31 changes: 26 additions & 5 deletions Assets/Plugins/CandyCoded.Forms/Scripts/Form.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.EventSystems;
#if ENABLE_INPUT_SYSTEM
using UnityEngine.InputSystem;
#endif
using UnityEngine.UI;

namespace CandyCoded.Forms
Expand All @@ -30,6 +33,26 @@ public class Form : MonoBehaviour

private Form _parentForm;

#if ENABLE_INPUT_SYSTEM
private bool _isTabKeyDown => Keyboard.current.tabKey.wasPressedThisFrame;

private bool _isReturnKeyDown => Keyboard.current.enterKey.wasPressedThisFrame;

private bool _isLeftShiftHeld => Keyboard.current.leftShiftKey.isPressed;

private bool _isRightShiftHeld => Keyboard.current.rightShiftKey.isPressed;
#else
private bool _isTabKeyDown => Input.GetKeyDown(KeyCode.Tab);

private bool _isReturnKeyDown => Input.GetKeyDown(KeyCode.Return);

private bool _isLeftShiftHeld => Input.GetKey(KeyCode.LeftShift);

private bool _isRightShiftHeld => Input.GetKey(KeyCode.RightShift);
#endif

private bool _isShiftHeld => _isLeftShiftHeld || _isRightShiftHeld;

private void Awake()
{

Expand Down Expand Up @@ -64,12 +87,12 @@ private void Update()
return;
}

if (Input.GetKeyDown(KeyCode.Tab))
if (_isTabKeyDown)
{
HandleTabPress(selectable, allSelectable);
}

if (Input.GetKeyDown(KeyCode.Return))
if (_isReturnKeyDown)
{
HandleReturnPress();
}
Expand Down Expand Up @@ -120,9 +143,7 @@ private void HandleTabPress(Selectable selectable, Selectable[] allSelectable)
var prevSelectable = selectable.FindSelectableOnUp() ?? allSelectable.Last();
var nextSelectable = selectable.FindSelectableOnDown() ?? allSelectable.First();

var next = Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift)
? prevSelectable
: nextSelectable;
var next = _isShiftHeld ? prevSelectable : nextSelectable;

_eventSystem.SetSelectedGameObject(next.gameObject, null);

Expand Down
5 changes: 3 additions & 2 deletions Packages/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
"com.unity.collab-proxy": "1.2.16",
"com.unity.ide.rider": "1.1.4",
"com.unity.ide.vscode": "1.2.0",
"com.unity.inputsystem": "1.0.1",
"com.unity.multiplayer-hlapi": "1.0.6",
"com.unity.nuget.newtonsoft-json": "2.0.0",
"com.unity.purchasing": "2.0.6",
"com.unity.test-framework": "1.1.14",
"com.unity.textmeshpro": "2.0.1",
Expand Down Expand Up @@ -44,7 +46,6 @@
"com.unity.modules.video": "1.0.0",
"com.unity.modules.vr": "1.0.0",
"com.unity.modules.wind": "1.0.0",
"com.unity.modules.xr": "1.0.0",
"com.unity.nuget.newtonsoft-json": "2.0.0"
"com.unity.modules.xr": "1.0.0"
}
}
9 changes: 8 additions & 1 deletion Packages/packages-lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"url": "https://packages.unity.com"
},
"com.unity.ext.nunit": {
"version": "1.0.5",
"version": "1.0.6",
"depth": 2,
"source": "registry",
"dependencies": {},
Expand All @@ -60,6 +60,13 @@
"dependencies": {},
"url": "https://packages.unity.com"
},
"com.unity.inputsystem": {
"version": "1.0.1",
"depth": 0,
"source": "registry",
"dependencies": {},
"url": "https://packages.unity.com"
},
"com.unity.multiplayer-hlapi": {
"version": "1.0.6",
"depth": 0,
Expand Down