Skip to content

Commit 07a96f2

Browse files
committed
Switched to new input system
1 parent e4669b9 commit 07a96f2

File tree

8 files changed

+191
-51
lines changed

8 files changed

+191
-51
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
# Visual Studio 2015 cache directory
1515
/.vs/
16+
.vsconfig
1617

1718
# Autogenerated VS/MD/Consulo solution and project files
1819
ExportedObj/

Assets/DebugOverlay/Console.cs

Lines changed: 68 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
using System;
22
using System.Collections;
33
using System.Collections.Generic;
4+
using Unity.Collections;
45
using UnityEngine;
6+
using UnityEngine.InputSystem;
57

68
public class Console : IGameSystem
79
{
@@ -27,6 +29,7 @@ public class Console : IGameSystem
2729
string[] m_History = new string[k_HistorySize];
2830
int m_HistoryDisplayIndex = 0;
2931
int m_HistoryNextIndex = 0;
32+
List<char> m_InputChars = new List<char>();
3033

3134
Color m_BackgroundColor = new Color(0, 0, 0, 0.9f);
3235
Vector4 m_TextColor = new Vector4(0.7f, 1.0f, 0.7f, 1.0f);
@@ -39,6 +42,40 @@ public Console()
3942
m_ConsoleBuffer = new System.UInt32[k_BufferSize];
4043
m_InputFieldBuffer = new char[k_InputBufferSize];
4144
AddCommand("help", CmdHelp, "Show available commands");
45+
AddCommand("dump", CmdDumpScene, "Dump scene hierarchy in active scene");
46+
Keyboard.current.onTextInput += OnTextInput;
47+
}
48+
49+
private void CmdDumpScene(string[] args)
50+
{
51+
var go = new List<GameObject>();
52+
UnityEngine.SceneManagement.SceneManager.GetActiveScene().GetRootGameObjects(go);
53+
foreach(var g in go)
54+
{
55+
RecurDump(g, 0);
56+
}
57+
}
58+
59+
private void RecurDump(GameObject go, int depth)
60+
{
61+
Write("{0}{1}\n", new string(' ', depth), go.name);
62+
for (var i = 0; i < go.transform.childCount; i++)
63+
{
64+
RecurDump(go.transform.GetChild(i).gameObject, depth + 1);
65+
}
66+
}
67+
68+
private void OnTextInput(char c)
69+
{
70+
if (!m_ConsoleOpen)
71+
return;
72+
73+
if(Char.IsControl(c) && c != '\n' && c != '\r' && c != '\b')
74+
{
75+
return;
76+
}
77+
78+
m_InputChars.Add(c);
4279
}
4380

4481
void CmdHelp(string[] args)
@@ -107,7 +144,7 @@ public void Show(float shown)
107144

108145
public void TickUpdate()
109146
{
110-
if (Input.GetKeyDown(KeyCode.F12))
147+
if(Keyboard.current.f12Key.wasPressedThisFrame)
111148
{
112149
m_ConsoleOpen = !m_ConsoleOpen;
113150
m_ConsoleFoldoutDest = m_ConsoleOpen ? 1.0f : 0.0f;
@@ -117,44 +154,41 @@ public void TickUpdate()
117154
if (!m_ConsoleOpen)
118155
return;
119156

120-
Scroll((int)Input.mouseScrollDelta.y);
121-
if (Input.anyKey)
157+
Scroll((int)Mouse.current.scroll.ReadValue().y);
158+
159+
if (Keyboard.current.leftArrowKey.wasPressedThisFrame && m_CursorPos > 0)
160+
m_CursorPos--;
161+
else if (Keyboard.current.rightArrowKey.wasPressedThisFrame && m_CursorPos < m_InputFieldLength)
162+
m_CursorPos++;
163+
else if (Keyboard.current.homeKey.wasPressedThisFrame || (Keyboard.current.aKey.wasPressedThisFrame && (Keyboard.current.leftCtrlKey.isPressed || Keyboard.current.rightCtrlKey.isPressed)))
164+
m_CursorPos = 0;
165+
else if (Keyboard.current.endKey.wasPressedThisFrame || (Keyboard.current.eKey.wasPressedThisFrame && (Keyboard.current.leftCtrlKey.isPressed || Keyboard.current.rightCtrlKey.isPressed)))
166+
m_CursorPos = m_InputFieldLength;
167+
else if (Keyboard.current.tabKey.wasPressedThisFrame)
168+
TabComplete();
169+
else if (Keyboard.current.upArrowKey.wasPressedThisFrame)
170+
HistoryPrev();
171+
else if (Keyboard.current.downArrowKey.wasPressedThisFrame)
172+
HistoryNext();
173+
else
122174
{
123-
if (Input.GetKeyDown(KeyCode.LeftArrow) && m_CursorPos > 0)
124-
m_CursorPos--;
125-
else if (Input.GetKeyDown(KeyCode.RightArrow) && m_CursorPos < m_InputFieldLength)
126-
m_CursorPos++;
127-
else if (Input.GetKeyDown(KeyCode.Home) || (Input.GetKeyDown(KeyCode.A) && (Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl))))
128-
m_CursorPos = 0;
129-
else if (Input.GetKeyDown(KeyCode.End) || (Input.GetKeyDown(KeyCode.E) && (Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl))))
130-
m_CursorPos = m_InputFieldLength;
131-
else if (Input.GetKeyDown(KeyCode.Tab))
132-
TabComplete();
133-
else if (Input.GetKeyDown(KeyCode.UpArrow))
134-
HistoryPrev();
135-
else if (Input.GetKeyDown(KeyCode.DownArrow))
136-
HistoryNext();
137-
else
175+
for (var i = 0; i < m_InputChars.Count; i++)
138176
{
139-
// TODO replace with garbage free alternative (perhaps impossible until new input system?)
140-
var inputString = Input.inputString;
141-
for (var i = 0; i < inputString.Length; i++)
177+
var ch = m_InputChars[i];
178+
if (ch == '\b')
179+
Backspace();
180+
else if (ch == '\n' || ch == '\r')
142181
{
143-
var ch = inputString[i];
144-
if (ch == '\b')
145-
Backspace();
146-
else if (ch == '\n' || ch == '\r')
147-
{
148-
var s = new string(m_InputFieldBuffer, 0, m_InputFieldLength);
149-
HistoryStore(s);
150-
ExecuteCommand(s);
151-
m_InputFieldLength = 0;
152-
m_CursorPos = 0;
153-
}
154-
else
155-
Type(ch);
182+
var s = new string(m_InputFieldBuffer, 0, m_InputFieldLength);
183+
HistoryStore(s);
184+
ExecuteCommand(s);
185+
m_InputFieldLength = 0;
186+
m_CursorPos = 0;
156187
}
188+
else
189+
Type(ch);
157190
}
191+
m_InputChars.Clear();
158192
}
159193
}
160194

Assets/Demo/DebugOverlayTest.unity

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ MonoBehaviour:
198198
m_Name:
199199
m_EditorClassIdentifier:
200200
player_cam: {fileID: 1637328087}
201-
mouse_sensitivity: 75
201+
mouse_sensitivity: 10
202202
jump_speed: 5
203203
player_friction: 8
204204
player_air_friction: 1
@@ -964,6 +964,7 @@ GameObject:
964964
- component: {fileID: 1637328087}
965965
- component: {fileID: 1637328089}
966966
- component: {fileID: 1637328088}
967+
- component: {fileID: 1637328092}
967968
m_Layer: 0
968969
m_Name: Main Camera
969970
m_TagString: MainCamera
@@ -1053,6 +1054,50 @@ Transform:
10531054
m_Children: []
10541055
m_Father: {fileID: 716915732}
10551056
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
1057+
--- !u!114 &1637328092
1058+
MonoBehaviour:
1059+
m_ObjectHideFlags: 0
1060+
m_CorrespondingSourceObject: {fileID: 0}
1061+
m_PrefabInstance: {fileID: 0}
1062+
m_PrefabAsset: {fileID: 0}
1063+
m_GameObject: {fileID: 1637328086}
1064+
m_Enabled: 1
1065+
m_EditorHideFlags: 0
1066+
m_Script: {fileID: 11500000, guid: a79441f348de89743a2939f4d699eac1, type: 3}
1067+
m_Name:
1068+
m_EditorClassIdentifier:
1069+
m_RenderShadows: 1
1070+
m_RequiresDepthTextureOption: 2
1071+
m_RequiresOpaqueTextureOption: 2
1072+
m_CameraType: 0
1073+
m_Cameras: []
1074+
m_RendererIndex: -1
1075+
m_VolumeLayerMask:
1076+
serializedVersion: 2
1077+
m_Bits: 1
1078+
m_VolumeTrigger: {fileID: 0}
1079+
m_VolumeFrameworkUpdateModeOption: 2
1080+
m_RenderPostProcessing: 0
1081+
m_Antialiasing: 0
1082+
m_AntialiasingQuality: 2
1083+
m_StopNaN: 0
1084+
m_Dithering: 0
1085+
m_ClearDepth: 1
1086+
m_AllowXRRendering: 1
1087+
m_AllowHDROutput: 1
1088+
m_UseScreenCoordOverride: 0
1089+
m_ScreenSizeOverride: {x: 0, y: 0, z: 0, w: 0}
1090+
m_ScreenCoordScaleBias: {x: 0, y: 0, z: 0, w: 0}
1091+
m_RequiresDepthTexture: 0
1092+
m_RequiresColorTexture: 0
1093+
m_Version: 2
1094+
m_TaaSettings:
1095+
m_Quality: 3
1096+
m_FrameInfluence: 0.1
1097+
m_JitterScale: 1
1098+
m_MipBias: 0
1099+
m_VarianceClampScale: 0.9
1100+
m_ContrastAdaptiveSharpening: 0
10561101
--- !u!1 &1705548852
10571102
GameObject:
10581103
m_ObjectHideFlags: 0

Assets/Demo/fpscontroller.cs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
using System.Collections;
1212
using System.Collections.Generic;
1313
using UnityEngine;
14+
using UnityEngine.InputSystem;
1415

1516
public class fpscontroller : MonoBehaviour
1617
{
@@ -24,6 +25,7 @@ public class fpscontroller : MonoBehaviour
2425
public float player_air_accel = 30.0f;
2526
public float player_speed = 7.0f;
2627

28+
private float cam_yaw = 0.0f;
2729
private Vector3 velocity = Vector3.zero;
2830

2931
CharacterController cc;
@@ -36,7 +38,8 @@ void Start()
3638
void Update()
3739
{
3840
// Turn player
39-
var turn_player = new Vector3(0, Input.GetAxisRaw("Mouse X"), 0);
41+
var turn_player = new Vector3(0, Mouse.current.delta.x.value, 0);
42+
4043
turn_player = turn_player * mouse_sensitivity * Time.deltaTime;
4144
transform.localEulerAngles += turn_player;
4245

@@ -53,7 +56,11 @@ void Update()
5356
var accel = isGrounded ? player_accel : player_air_accel;
5457

5558
// WASD movement
56-
var move = new Vector3(Input.GetAxisRaw("Horizontal"), 0, Input.GetAxisRaw("Vertical"));
59+
float horizontal = Keyboard.current.aKey.isPressed ? -1.0f : 0.0f;
60+
horizontal += Keyboard.current.dKey.isPressed ? 1.0f : 0.0f;
61+
float vertical = Keyboard.current.sKey.isPressed ? -1.0f : 0.0f;
62+
vertical += Keyboard.current.wKey.isPressed ? 1.0f : 0.0f;
63+
var move = new Vector3(horizontal, 0, vertical);
5764
var moveMagnitude = move.magnitude;
5865
if (moveMagnitude > 1.0f)
5966
move /= moveMagnitude;
@@ -87,14 +94,14 @@ void Update()
8794
cc.Move(velocity * Time.deltaTime);
8895

8996
// Jump
90-
if (isGrounded && Input.GetKeyDown(KeyCode.Space))
97+
if (isGrounded && Keyboard.current.spaceKey.isPressed)
9198
{
9299
velocity.y = jump_speed;
93100
}
94101

95102
// Camera look up/down
96-
var turn_cam = new Vector3(-Input.GetAxisRaw("Mouse Y"), 0, 0);
97-
turn_cam = turn_cam * mouse_sensitivity * Time.deltaTime;
98-
player_cam.transform.localEulerAngles += turn_cam;
103+
cam_yaw += -Mouse.current.delta.y.value * mouse_sensitivity * Time.deltaTime;
104+
cam_yaw = Mathf.Clamp(cam_yaw, -70.0f, 70.0f);
105+
player_cam.transform.localEulerAngles = new Vector3(cam_yaw, 0, 0);
99106
}
100107
}

Packages/manifest.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
{
22
"dependencies": {
3+
"com.unity.ide.visualstudio": "2.0.22",
4+
"com.unity.inputsystem": "1.13.1",
35
"com.unity.render-pipelines.core": "17.0.3",
46
"com.unity.render-pipelines.universal": "17.0.3",
57
"com.unity.modules.accessibility": "1.0.0",

Packages/packages-lock.json

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,29 @@
2424
},
2525
"com.unity.ext.nunit": {
2626
"version": "2.0.5",
27-
"depth": 3,
27+
"depth": 2,
2828
"source": "registry",
2929
"dependencies": {},
3030
"url": "https://packages.unity.com"
3131
},
32+
"com.unity.ide.visualstudio": {
33+
"version": "2.0.22",
34+
"depth": 0,
35+
"source": "registry",
36+
"dependencies": {
37+
"com.unity.test-framework": "1.1.9"
38+
},
39+
"url": "https://packages.unity.com"
40+
},
41+
"com.unity.inputsystem": {
42+
"version": "1.13.1",
43+
"depth": 0,
44+
"source": "registry",
45+
"dependencies": {
46+
"com.unity.modules.uielements": "1.0.0"
47+
},
48+
"url": "https://packages.unity.com"
49+
},
3250
"com.unity.mathematics": {
3351
"version": "1.3.2",
3452
"depth": 1,
@@ -104,7 +122,7 @@
104122
},
105123
"com.unity.test-framework": {
106124
"version": "1.4.6",
107-
"depth": 2,
125+
"depth": 1,
108126
"source": "registry",
109127
"dependencies": {
110128
"com.unity.ext.nunit": "2.0.3",

ProjectSettings/EditorSettings.asset

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,46 @@
33
--- !u!159 &1
44
EditorSettings:
55
m_ObjectHideFlags: 0
6-
serializedVersion: 4
7-
m_ExternalVersionControlSupport: Visible Meta Files
6+
serializedVersion: 13
87
m_SerializationMode: 2
8+
m_LineEndingsForNewScripts: 1
99
m_DefaultBehaviorMode: 0
10+
m_PrefabRegularEnvironment: {fileID: 0}
11+
m_PrefabUIEnvironment: {fileID: 0}
1012
m_SpritePackerMode: 0
13+
m_SpritePackerCacheSize: 10
1114
m_SpritePackerPaddingPower: 1
12-
m_ProjectGenerationIncludedExtensions: txt;xml;fnt;cd
15+
m_Bc7TextureCompressor: 0
16+
m_EtcTextureCompressorBehavior: 0
17+
m_EtcTextureFastCompressor: 2
18+
m_EtcTextureNormalCompressor: 2
19+
m_EtcTextureBestCompressor: 5
20+
m_ProjectGenerationIncludedExtensions: txt;xml;fnt;cd;asmref
1321
m_ProjectGenerationRootNamespace:
14-
m_UserGeneratedProjectSuffix:
15-
m_CollabEditorSettings:
16-
inProgressEnabled: 1
22+
m_EnableTextureStreamingInEditMode: 1
23+
m_EnableTextureStreamingInPlayMode: 1
24+
m_EnableEditorAsyncCPUTextureLoading: 0
25+
m_AsyncShaderCompilation: 1
26+
m_PrefabModeAllowAutoSave: 1
27+
m_EnterPlayModeOptionsEnabled: 1
28+
m_EnterPlayModeOptions: 1
29+
m_GameObjectNamingDigits: 1
30+
m_GameObjectNamingScheme: 0
31+
m_AssetNamingUsesSpace: 1
32+
m_InspectorUseIMGUIDefaultInspector: 0
33+
m_UseLegacyProbeSampleCount: 1
34+
m_SerializeInlineMappingsOnOneLine: 0
35+
m_DisableCookiesInLightmapper: 1
36+
m_AssetPipelineMode: 1
37+
m_RefreshImportMode: 0
38+
m_CacheServerMode: 0
39+
m_CacheServerEndpoint:
40+
m_CacheServerNamespacePrefix: default
41+
m_CacheServerEnableDownload: 1
42+
m_CacheServerEnableUpload: 1
43+
m_CacheServerEnableAuth: 0
44+
m_CacheServerEnableTls: 0
45+
m_CacheServerValidationMode: 2
46+
m_CacheServerDownloadBatchSize: 128
47+
m_EnableEnlightenBakedGI: 0
48+
m_ReferencedClipsExactNaming: 0

ProjectSettings/ProjectSettings.asset

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,8 @@ PlayerSettings:
162162
androidSupportedAspectRatio: 1
163163
androidMaxAspectRatio: 2.1
164164
androidMinAspectRatio: 1
165-
applicationIdentifier: {}
165+
applicationIdentifier:
166+
Standalone: com.DefaultCompany.DebugOverlay
166167
buildNumber:
167168
Standalone: 0
168169
VisionOS: 0
@@ -737,7 +738,7 @@ PlayerSettings:
737738
qnxGraphicConfPath:
738739
apiCompatibilityLevel: 6
739740
captureStartupLogs: {}
740-
activeInputHandler: 0
741+
activeInputHandler: 1
741742
windowsGamepadBackendHint: 0
742743
cloudProjectId:
743744
framebufferDepthMemorylessMode: 0

0 commit comments

Comments
 (0)