Skip to content

Commit a1425d9

Browse files
authored
Merge pull request #2 from kyubuns/NewInputSystemSupport
New input system support
2 parents 134cdb9 + d54f090 commit a1425d9

File tree

10 files changed

+134
-19
lines changed

10 files changed

+134
-19
lines changed
+9-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
{
22
"name": "AbcConsole",
33
"references": [
4-
"GUID:f48a88687021943959a850c81ac6e5b5"
4+
"GUID:f48a88687021943959a850c81ac6e5b5",
5+
"GUID:75469ad4d38634e559750d17036d5f7c"
56
],
67
"includePlatforms": [],
78
"excludePlatforms": [],
@@ -10,6 +11,12 @@
1011
"precompiledReferences": [],
1112
"autoReferenced": true,
1213
"defineConstraints": [],
13-
"versionDefines": [],
14+
"versionDefines": [
15+
{
16+
"name": "com.unity.inputsystem",
17+
"expression": "",
18+
"define": "NEW_INPUT_SYSTEM_SUPPORT"
19+
}
20+
],
1421
"noEngineReferences": false
1522
}

Assets/AbcConsole/Runtime/Internal/Console.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,9 @@ private void UpdateKeys()
9191
{
9292
if (!_ui.InputField.IsActive()) return;
9393

94-
if (Input.GetKeyDown(KeyCode.Tab)) RequestAutocomplete();
95-
if (Input.GetKeyDown(KeyCode.UpArrow)) RequestHistoryUp();
96-
if (Input.GetKeyDown(KeyCode.DownArrow)) RequestHistoryDown();
94+
if (KeyInput.GetTabKeyDown()) RequestAutocomplete();
95+
if (KeyInput.GetUpArrowKeyDown()) RequestHistoryUp();
96+
if (KeyInput.GetDownArrowKeyDown()) RequestHistoryDown();
9797
}
9898

9999
private void RequestAutocomplete()
@@ -264,7 +264,7 @@ private void OnInputFieldEndEdit()
264264
{
265265
_onInputFieldEndEditFrame = Time.frameCount;
266266

267-
if (Input.GetKeyDown(KeyCode.Return))
267+
if (KeyInput.GetReturnKeyDown())
268268
{
269269
OnClickEnterButton();
270270
_ui.InputField.FocusAndMoveToEnd();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#if NEW_INPUT_SYSTEM_SUPPORT
2+
using UnityEngine.InputSystem;
3+
using UnityEngine.InputSystem.Controls;
4+
#else
5+
using UnityEngine;
6+
#endif
7+
8+
namespace AbcConsole.Internal
9+
{
10+
public static class KeyInput
11+
{
12+
#if NEW_INPUT_SYSTEM_SUPPORT
13+
public static bool GetKeyDown(string keyCode)
14+
{
15+
return ((KeyControl) Keyboard.current[keyCode]).wasPressedThisFrame;
16+
}
17+
#else
18+
public static bool GetKeyDown(KeyCode keyCode)
19+
{
20+
return Input.GetKeyDown(keyCode);
21+
}
22+
#endif
23+
24+
public static bool GetEscapeKeyDown()
25+
{
26+
#if NEW_INPUT_SYSTEM_SUPPORT
27+
return Keyboard.current.escapeKey.wasPressedThisFrame;
28+
#else
29+
return Input.GetKeyDown(KeyCode.Escape);
30+
#endif
31+
}
32+
33+
public static bool GetReturnKeyDown()
34+
{
35+
#if NEW_INPUT_SYSTEM_SUPPORT
36+
return Keyboard.current.enterKey.wasPressedThisFrame;
37+
#else
38+
return Input.GetKeyDown(KeyCode.Return);
39+
#endif
40+
}
41+
42+
public static bool GetTabKeyDown()
43+
{
44+
#if NEW_INPUT_SYSTEM_SUPPORT
45+
return Keyboard.current.tabKey.wasPressedThisFrame;
46+
#else
47+
return Input.GetKeyDown(KeyCode.Tab);
48+
#endif
49+
}
50+
51+
public static bool GetUpArrowKeyDown()
52+
{
53+
#if NEW_INPUT_SYSTEM_SUPPORT
54+
return Keyboard.current.upArrowKey.wasPressedThisFrame;
55+
#else
56+
return Input.GetKeyDown(KeyCode.UpArrow);
57+
#endif
58+
}
59+
60+
public static bool GetDownArrowKeyDown()
61+
{
62+
#if NEW_INPUT_SYSTEM_SUPPORT
63+
return Keyboard.current.downArrowKey.wasPressedThisFrame;
64+
#else
65+
return Input.GetKeyDown(KeyCode.DownArrow);
66+
#endif
67+
}
68+
}
69+
}

Assets/AbcConsole/Runtime/Internal/KeyInput.cs.meta

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/AbcConsole/Runtime/Internal/TriggerKey.cs

+6-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ namespace AbcConsole.Internal
44
{
55
public class TriggerKey : MonoBehaviour
66
{
7+
#if NEW_INPUT_SYSTEM_SUPPORT
8+
[SerializeField] private string keyCode = "Backquote";
9+
#else
710
[SerializeField] private KeyCode keyCode = KeyCode.BackQuote;
11+
#endif
812
private Root _root;
913

1014
public void Start()
@@ -14,12 +18,12 @@ public void Start()
1418

1519
public void Update()
1620
{
17-
if (Input.GetKeyDown(keyCode))
21+
if (KeyInput.GetKeyDown(keyCode))
1822
{
1923
_root.OnClickTriggerButton();
2024
}
2125

22-
if (Root.CurrentInstance.State != ConsoleState.None && Input.GetKeyDown(KeyCode.Escape))
26+
if (Root.CurrentInstance.State != ConsoleState.None && KeyInput.GetEscapeKeyDown())
2327
{
2428
_root.OnClickTriggerButton();
2529
}

Assets/AbcConsole/Samples~/Demo/AbcConsoleDemo.unity

+32-8
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,11 @@ PrefabInstance:
220220
m_Modification:
221221
m_TransformParent: {fileID: 0}
222222
m_Modifications:
223+
- target: {fileID: 2244211959391475033, guid: dbaf8f1b5f85448b889de2ef8b5f22cc,
224+
type: 3}
225+
propertyPath: keyCode
226+
value: Backquote
227+
objectReference: {fileID: 0}
223228
- target: {fileID: 3537220671408263148, guid: dbaf8f1b5f85448b889de2ef8b5f22cc,
224229
type: 3}
225230
propertyPath: m_IsActive
@@ -495,16 +500,35 @@ MonoBehaviour:
495500
m_GameObject: {fileID: 1974646334}
496501
m_Enabled: 1
497502
m_EditorHideFlags: 0
498-
m_Script: {fileID: 11500000, guid: 4f231c4fb786f3946a6b90b886c48677, type: 3}
503+
m_Script: {fileID: 11500000, guid: 01614664b831546d2ae94a42149d80ac, type: 3}
499504
m_Name:
500505
m_EditorClassIdentifier:
501-
m_HorizontalAxis: Horizontal
502-
m_VerticalAxis: Vertical
503-
m_SubmitButton: Submit
504-
m_CancelButton: Cancel
505-
m_InputActionsPerSecond: 10
506-
m_RepeatDelay: 0.5
507-
m_ForceModuleActive: 0
506+
m_MoveRepeatDelay: 0.5
507+
m_MoveRepeatRate: 0.1
508+
m_ActionsAsset: {fileID: -944628639613478452, guid: ca9f5fa95ffab41fb9a615ab714db018,
509+
type: 3}
510+
m_PointAction: {fileID: 1054132383583890850, guid: ca9f5fa95ffab41fb9a615ab714db018,
511+
type: 3}
512+
m_MoveAction: {fileID: 3710738434707379630, guid: ca9f5fa95ffab41fb9a615ab714db018,
513+
type: 3}
514+
m_SubmitAction: {fileID: 2064916234097673511, guid: ca9f5fa95ffab41fb9a615ab714db018,
515+
type: 3}
516+
m_CancelAction: {fileID: -1967631576421560919, guid: ca9f5fa95ffab41fb9a615ab714db018,
517+
type: 3}
518+
m_LeftClickAction: {fileID: 8056856818456041789, guid: ca9f5fa95ffab41fb9a615ab714db018,
519+
type: 3}
520+
m_MiddleClickAction: {fileID: 3279352641294131588, guid: ca9f5fa95ffab41fb9a615ab714db018,
521+
type: 3}
522+
m_RightClickAction: {fileID: 3837173908680883260, guid: ca9f5fa95ffab41fb9a615ab714db018,
523+
type: 3}
524+
m_ScrollWheelAction: {fileID: 4502412055082496612, guid: ca9f5fa95ffab41fb9a615ab714db018,
525+
type: 3}
526+
m_TrackedDevicePositionAction: {fileID: 4754684134866288074, guid: ca9f5fa95ffab41fb9a615ab714db018,
527+
type: 3}
528+
m_TrackedDeviceOrientationAction: {fileID: 1025543830046995696, guid: ca9f5fa95ffab41fb9a615ab714db018,
529+
type: 3}
530+
m_DeselectOnBackgroundClick: 1
531+
m_PointerBehavior: 0
508532
--- !u!114 &1974646336
509533
MonoBehaviour:
510534
m_ObjectHideFlags: 0

Assets/AbcConsole/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "dev.kyubuns.abcconsole",
33
"displayName": "AbcConsole",
4-
"version": "1.0.2",
4+
"version": "1.1.0",
55
"unity": "2019.4",
66
"description": "Mobile-friendly debug console system",
77
"documentationUrl": "https://github.com/kyubuns/AbcConsole",

Packages/manifest.json

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"com.unity.device-simulator": "2.2.4-preview",
1111
"com.unity.ide.rider": "1.1.4",
1212
"com.unity.ide.vscode": "1.2.3",
13+
"com.unity.inputsystem": "1.0.2",
1314
"com.unity.test-framework": "1.1.22",
1415
"com.unity.textmeshpro": "2.1.1",
1516
"com.unity.timeline": "1.2.18",

Packages/packages-lock.json

+7
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,13 @@
108108
"dependencies": {},
109109
"url": "https://packages.unity.com"
110110
},
111+
"com.unity.inputsystem": {
112+
"version": "1.0.2",
113+
"depth": 0,
114+
"source": "registry",
115+
"dependencies": {},
116+
"url": "https://packages.unity.com"
117+
},
111118
"com.unity.mathematics": {
112119
"version": "1.1.0",
113120
"depth": 1,

ProjectSettings/ProjectSettings.asset

+2-2
Original file line numberDiff line numberDiff line change
@@ -742,6 +742,6 @@ PlayerSettings:
742742
projectName:
743743
organizationId:
744744
cloudEnabled: 0
745-
enableNativePlatformBackendsForNewInputSystem: 0
746-
disableOldInputManagerSupport: 0
745+
enableNativePlatformBackendsForNewInputSystem: 1
746+
disableOldInputManagerSupport: 1
747747
legacyClampBlendShapeWeights: 0

0 commit comments

Comments
 (0)