Skip to content

Commit

Permalink
Merge pull request #2 from kyubuns/NewInputSystemSupport
Browse files Browse the repository at this point in the history
New input system support
  • Loading branch information
kyubuns authored Mar 31, 2021
2 parents 134cdb9 + d54f090 commit a1425d9
Show file tree
Hide file tree
Showing 10 changed files with 134 additions and 19 deletions.
11 changes: 9 additions & 2 deletions Assets/AbcConsole/Runtime/AbcConsole.asmdef
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"name": "AbcConsole",
"references": [
"GUID:f48a88687021943959a850c81ac6e5b5"
"GUID:f48a88687021943959a850c81ac6e5b5",
"GUID:75469ad4d38634e559750d17036d5f7c"
],
"includePlatforms": [],
"excludePlatforms": [],
Expand All @@ -10,6 +11,12 @@
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [],
"versionDefines": [
{
"name": "com.unity.inputsystem",
"expression": "",
"define": "NEW_INPUT_SYSTEM_SUPPORT"
}
],
"noEngineReferences": false
}
8 changes: 4 additions & 4 deletions Assets/AbcConsole/Runtime/Internal/Console.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ private void UpdateKeys()
{
if (!_ui.InputField.IsActive()) return;

if (Input.GetKeyDown(KeyCode.Tab)) RequestAutocomplete();
if (Input.GetKeyDown(KeyCode.UpArrow)) RequestHistoryUp();
if (Input.GetKeyDown(KeyCode.DownArrow)) RequestHistoryDown();
if (KeyInput.GetTabKeyDown()) RequestAutocomplete();
if (KeyInput.GetUpArrowKeyDown()) RequestHistoryUp();
if (KeyInput.GetDownArrowKeyDown()) RequestHistoryDown();
}

private void RequestAutocomplete()
Expand Down Expand Up @@ -264,7 +264,7 @@ private void OnInputFieldEndEdit()
{
_onInputFieldEndEditFrame = Time.frameCount;

if (Input.GetKeyDown(KeyCode.Return))
if (KeyInput.GetReturnKeyDown())
{
OnClickEnterButton();
_ui.InputField.FocusAndMoveToEnd();
Expand Down
69 changes: 69 additions & 0 deletions Assets/AbcConsole/Runtime/Internal/KeyInput.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#if NEW_INPUT_SYSTEM_SUPPORT
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;
#else
using UnityEngine;
#endif

namespace AbcConsole.Internal
{
public static class KeyInput
{
#if NEW_INPUT_SYSTEM_SUPPORT
public static bool GetKeyDown(string keyCode)
{
return ((KeyControl) Keyboard.current[keyCode]).wasPressedThisFrame;
}
#else
public static bool GetKeyDown(KeyCode keyCode)
{
return Input.GetKeyDown(keyCode);
}
#endif

public static bool GetEscapeKeyDown()
{
#if NEW_INPUT_SYSTEM_SUPPORT
return Keyboard.current.escapeKey.wasPressedThisFrame;
#else
return Input.GetKeyDown(KeyCode.Escape);
#endif
}

public static bool GetReturnKeyDown()
{
#if NEW_INPUT_SYSTEM_SUPPORT
return Keyboard.current.enterKey.wasPressedThisFrame;
#else
return Input.GetKeyDown(KeyCode.Return);
#endif
}

public static bool GetTabKeyDown()
{
#if NEW_INPUT_SYSTEM_SUPPORT
return Keyboard.current.tabKey.wasPressedThisFrame;
#else
return Input.GetKeyDown(KeyCode.Tab);
#endif
}

public static bool GetUpArrowKeyDown()
{
#if NEW_INPUT_SYSTEM_SUPPORT
return Keyboard.current.upArrowKey.wasPressedThisFrame;
#else
return Input.GetKeyDown(KeyCode.UpArrow);
#endif
}

public static bool GetDownArrowKeyDown()
{
#if NEW_INPUT_SYSTEM_SUPPORT
return Keyboard.current.downArrowKey.wasPressedThisFrame;
#else
return Input.GetKeyDown(KeyCode.DownArrow);
#endif
}
}
}
3 changes: 3 additions & 0 deletions Assets/AbcConsole/Runtime/Internal/KeyInput.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions Assets/AbcConsole/Runtime/Internal/TriggerKey.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ namespace AbcConsole.Internal
{
public class TriggerKey : MonoBehaviour
{
#if NEW_INPUT_SYSTEM_SUPPORT
[SerializeField] private string keyCode = "Backquote";
#else
[SerializeField] private KeyCode keyCode = KeyCode.BackQuote;
#endif
private Root _root;

public void Start()
Expand All @@ -14,12 +18,12 @@ public void Start()

public void Update()
{
if (Input.GetKeyDown(keyCode))
if (KeyInput.GetKeyDown(keyCode))
{
_root.OnClickTriggerButton();
}

if (Root.CurrentInstance.State != ConsoleState.None && Input.GetKeyDown(KeyCode.Escape))
if (Root.CurrentInstance.State != ConsoleState.None && KeyInput.GetEscapeKeyDown())
{
_root.OnClickTriggerButton();
}
Expand Down
40 changes: 32 additions & 8 deletions Assets/AbcConsole/Samples~/Demo/AbcConsoleDemo.unity
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,11 @@ PrefabInstance:
m_Modification:
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 2244211959391475033, guid: dbaf8f1b5f85448b889de2ef8b5f22cc,
type: 3}
propertyPath: keyCode
value: Backquote
objectReference: {fileID: 0}
- target: {fileID: 3537220671408263148, guid: dbaf8f1b5f85448b889de2ef8b5f22cc,
type: 3}
propertyPath: m_IsActive
Expand Down Expand Up @@ -495,16 +500,35 @@ MonoBehaviour:
m_GameObject: {fileID: 1974646334}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 4f231c4fb786f3946a6b90b886c48677, type: 3}
m_Script: {fileID: 11500000, guid: 01614664b831546d2ae94a42149d80ac, type: 3}
m_Name:
m_EditorClassIdentifier:
m_HorizontalAxis: Horizontal
m_VerticalAxis: Vertical
m_SubmitButton: Submit
m_CancelButton: Cancel
m_InputActionsPerSecond: 10
m_RepeatDelay: 0.5
m_ForceModuleActive: 0
m_MoveRepeatDelay: 0.5
m_MoveRepeatRate: 0.1
m_ActionsAsset: {fileID: -944628639613478452, guid: ca9f5fa95ffab41fb9a615ab714db018,
type: 3}
m_PointAction: {fileID: 1054132383583890850, guid: ca9f5fa95ffab41fb9a615ab714db018,
type: 3}
m_MoveAction: {fileID: 3710738434707379630, guid: ca9f5fa95ffab41fb9a615ab714db018,
type: 3}
m_SubmitAction: {fileID: 2064916234097673511, guid: ca9f5fa95ffab41fb9a615ab714db018,
type: 3}
m_CancelAction: {fileID: -1967631576421560919, guid: ca9f5fa95ffab41fb9a615ab714db018,
type: 3}
m_LeftClickAction: {fileID: 8056856818456041789, guid: ca9f5fa95ffab41fb9a615ab714db018,
type: 3}
m_MiddleClickAction: {fileID: 3279352641294131588, guid: ca9f5fa95ffab41fb9a615ab714db018,
type: 3}
m_RightClickAction: {fileID: 3837173908680883260, guid: ca9f5fa95ffab41fb9a615ab714db018,
type: 3}
m_ScrollWheelAction: {fileID: 4502412055082496612, guid: ca9f5fa95ffab41fb9a615ab714db018,
type: 3}
m_TrackedDevicePositionAction: {fileID: 4754684134866288074, guid: ca9f5fa95ffab41fb9a615ab714db018,
type: 3}
m_TrackedDeviceOrientationAction: {fileID: 1025543830046995696, guid: ca9f5fa95ffab41fb9a615ab714db018,
type: 3}
m_DeselectOnBackgroundClick: 1
m_PointerBehavior: 0
--- !u!114 &1974646336
MonoBehaviour:
m_ObjectHideFlags: 0
Expand Down
2 changes: 1 addition & 1 deletion Assets/AbcConsole/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "dev.kyubuns.abcconsole",
"displayName": "AbcConsole",
"version": "1.0.2",
"version": "1.1.0",
"unity": "2019.4",
"description": "Mobile-friendly debug console system",
"documentationUrl": "https://github.com/kyubuns/AbcConsole",
Expand Down
1 change: 1 addition & 0 deletions Packages/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"com.unity.device-simulator": "2.2.4-preview",
"com.unity.ide.rider": "1.1.4",
"com.unity.ide.vscode": "1.2.3",
"com.unity.inputsystem": "1.0.2",
"com.unity.test-framework": "1.1.22",
"com.unity.textmeshpro": "2.1.1",
"com.unity.timeline": "1.2.18",
Expand Down
7 changes: 7 additions & 0 deletions Packages/packages-lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,13 @@
"dependencies": {},
"url": "https://packages.unity.com"
},
"com.unity.inputsystem": {
"version": "1.0.2",
"depth": 0,
"source": "registry",
"dependencies": {},
"url": "https://packages.unity.com"
},
"com.unity.mathematics": {
"version": "1.1.0",
"depth": 1,
Expand Down
4 changes: 2 additions & 2 deletions ProjectSettings/ProjectSettings.asset
Original file line number Diff line number Diff line change
Expand Up @@ -742,6 +742,6 @@ PlayerSettings:
projectName:
organizationId:
cloudEnabled: 0
enableNativePlatformBackendsForNewInputSystem: 0
disableOldInputManagerSupport: 0
enableNativePlatformBackendsForNewInputSystem: 1
disableOldInputManagerSupport: 1
legacyClampBlendShapeWeights: 0

0 comments on commit a1425d9

Please sign in to comment.