Skip to content

Commit ccab35f

Browse files
author
Rene Damm
authored
CHANGE: Move XR layouts (except Magic Leap) back into input system (#910).
1 parent 4241130 commit ccab35f

26 files changed

+1146
-117
lines changed

Assets/Tests/InputSystem/APIVerificationTests.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ private bool IsValidNameForConstant(string name)
1919

2020
private bool TypeHasValidNamespace(TypeReference type)
2121
{
22+
// The XR stuff is putting some things in Unity.XR and UnityEngine.XR. While we still have
23+
// these in the input system itself, accept that namespace. Remove it when
24+
// the XR layouts are removed.
25+
if (type.Namespace.StartsWith("Unity.XR") || type.Namespace.StartsWith("UnityEngine.XR"))
26+
return true;
27+
2228
// The compiler generates a <Module> type which we want to ignore
2329
return type.Namespace.StartsWith("UnityEngine.InputSystem") || type.Name == "<Module>";
2430
}
@@ -398,6 +404,8 @@ bool IgnoreTypeForDocs(TypeDefinition type)
398404
type.FullName == typeof(UnityEngine.InputSystem.Processors.EditorWindowSpaceProcessor).FullName ||
399405
// All our XR stuff completely lacks docs. Get XR team to fix this.
400406
type.Namespace.StartsWith("UnityEngine.InputSystem.XR") ||
407+
type.Namespace.StartsWith("UnityEngine.XR") ||
408+
type.Namespace.StartsWith("Unity.XR") ||
401409
false;
402410
}
403411

Assets/Tests/InputSystem/Plugins/XRTests.cs

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,9 @@ public void Layouts_XRLayoutFeatures_OnlyContainAllowedCharacters()
133133

134134
var generatedLayout = InputSystem.LoadLayout(createdDevice.layout);
135135
Assert.That(generatedLayout, Is.Not.Null);
136-
Assert.That(generatedLayout.controls.Count, Is.EqualTo(1));
136+
Assert.That(generatedLayout.controls.Count, Is.EqualTo(kNumBaseHMDControls + 1));
137137

138-
var childControl = generatedLayout.controls[0];
138+
var childControl = generatedLayout["SimpleFeature1"];
139139
Assert.That(childControl.name, Is.EqualTo(new InternedString("SimpleFeature1")));
140140
}
141141

@@ -226,44 +226,44 @@ public void Layouts_AllFeatureTypes_AreRepresentedInTheGeneratedLayout()
226226

227227
var generatedLayout = InputSystem.LoadLayout("XRInputV1::XRManufacturer::XRDevice");
228228
Assert.That(generatedLayout, Is.Not.Null);
229-
Assert.That(generatedLayout.controls.Count, Is.EqualTo(7));
229+
Assert.That(generatedLayout.controls.Count, Is.EqualTo(kNumBaseHMDControls + 7));
230230

231-
var binaryControl = generatedLayout.controls[0];
231+
var binaryControl = generatedLayout["Button"];
232232
Assert.That(binaryControl.name, Is.EqualTo(new InternedString("Button")));
233233
Assert.That(binaryControl.offset, Is.EqualTo(0));
234234
Assert.That(binaryControl.layout, Is.EqualTo(new InternedString("Button")));
235235
Assert.That(binaryControl.usages.Count, Is.EqualTo(1));
236236
Assert.That(binaryControl.usages[0], Is.EqualTo(new InternedString("ButtonUsage")));
237237

238-
var discreteControl = generatedLayout.controls[1];
238+
var discreteControl = generatedLayout["DiscreteState"];
239239
Assert.That(discreteControl.name, Is.EqualTo(new InternedString("DiscreteState")));
240240
Assert.That(discreteControl.offset, Is.EqualTo(4));
241241
Assert.That(discreteControl.layout, Is.EqualTo(new InternedString("Integer")));
242242
Assert.That(discreteControl.usages.Count, Is.EqualTo(1));
243243
Assert.That(discreteControl.usages[0], Is.EqualTo(new InternedString("DiscreteStateUsage")));
244244

245-
var axisControl = generatedLayout.controls[2];
245+
var axisControl = generatedLayout["Axis"];
246246
Assert.That(axisControl.name, Is.EqualTo(new InternedString("Axis")));
247247
Assert.That(axisControl.offset, Is.EqualTo(8));
248248
Assert.That(axisControl.layout, Is.EqualTo(new InternedString("Analog")));
249249
Assert.That(axisControl.usages.Count, Is.EqualTo(1));
250250
Assert.That(axisControl.usages[0], Is.EqualTo(new InternedString("Axis1DUsage")));
251251

252-
var vec2Control = generatedLayout.controls[3];
252+
var vec2Control = generatedLayout["Vector2"];
253253
Assert.That(vec2Control.name, Is.EqualTo(new InternedString("Vector2")));
254254
Assert.That(vec2Control.offset, Is.EqualTo(12));
255255
Assert.That(vec2Control.layout, Is.EqualTo(new InternedString("Vector2")));
256256
Assert.That(vec2Control.usages.Count, Is.EqualTo(1));
257257
Assert.That(vec2Control.usages[0], Is.EqualTo(new InternedString("Axis2DUsage")));
258258

259-
var vec3Control = generatedLayout.controls[4];
259+
var vec3Control = generatedLayout["Vector3"];
260260
Assert.That(vec3Control.name, Is.EqualTo(new InternedString("Vector3")));
261261
Assert.That(vec3Control.offset, Is.EqualTo(20));
262262
Assert.That(vec3Control.layout, Is.EqualTo(new InternedString("Vector3")));
263263
Assert.That(vec3Control.usages.Count, Is.EqualTo(1));
264264
Assert.That(vec3Control.usages[0], Is.EqualTo(new InternedString("Axis3DUsage")));
265265

266-
var rotationControl = generatedLayout.controls[5];
266+
var rotationControl = generatedLayout["Rotation"];
267267
Assert.That(rotationControl.name, Is.EqualTo(new InternedString("Rotation")));
268268
Assert.That(rotationControl.offset, Is.EqualTo(32));
269269
Assert.That(rotationControl.layout, Is.EqualTo(new InternedString("Quaternion")));
@@ -272,7 +272,7 @@ public void Layouts_AllFeatureTypes_AreRepresentedInTheGeneratedLayout()
272272

273273
// Custom element is skipped, but occupies 256 bytes
274274

275-
var lastControl = generatedLayout.controls[6];
275+
var lastControl = generatedLayout["Last"];
276276
Assert.That(lastControl.name, Is.EqualTo(new InternedString("Last")));
277277
Assert.That(lastControl.offset, Is.EqualTo(304));
278278
Assert.That(lastControl.layout, Is.EqualTo(new InternedString("Button")));
@@ -291,37 +291,37 @@ public void Layouts_ButtonsArePackedByTheByte_WhileLargerStructuresAreFourByteAl
291291

292292
var generatedLayout = InputSystem.LoadLayout("XRInputV1::XRManufacturer::XRDevice");
293293
Assert.That(generatedLayout, Is.Not.Null);
294-
Assert.That(generatedLayout.controls.Count, Is.EqualTo(8));
294+
Assert.That(generatedLayout.controls.Count, Is.EqualTo(kNumBaseHMDControls + 8));
295295

296-
var currentControl = generatedLayout.controls[0];
296+
var currentControl = generatedLayout["Button1"];
297297
Assert.That(currentControl.offset, Is.EqualTo(0));
298298
Assert.That(currentControl.layout, Is.EqualTo(new InternedString("Button")));
299299

300-
currentControl = generatedLayout.controls[1];
300+
currentControl = generatedLayout["Button2"];
301301
Assert.That(currentControl.offset, Is.EqualTo(1));
302302
Assert.That(currentControl.layout, Is.EqualTo(new InternedString("Button")));
303303

304-
currentControl = generatedLayout.controls[2];
304+
currentControl = generatedLayout["Button3"];
305305
Assert.That(currentControl.offset, Is.EqualTo(2));
306306
Assert.That(currentControl.layout, Is.EqualTo(new InternedString("Button")));
307307

308-
currentControl = generatedLayout.controls[3];
308+
currentControl = generatedLayout["Button4"];
309309
Assert.That(currentControl.offset, Is.EqualTo(3));
310310
Assert.That(currentControl.layout, Is.EqualTo(new InternedString("Button")));
311311

312-
currentControl = generatedLayout.controls[4];
312+
currentControl = generatedLayout["Button5"];
313313
Assert.That(currentControl.offset, Is.EqualTo(4));
314314
Assert.That(currentControl.layout, Is.EqualTo(new InternedString("Button")));
315315

316-
currentControl = generatedLayout.controls[5];
316+
currentControl = generatedLayout["Button6"];
317317
Assert.That(currentControl.offset, Is.EqualTo(5));
318318
Assert.That(currentControl.layout, Is.EqualTo(new InternedString("Button")));
319319

320-
currentControl = generatedLayout.controls[6];
320+
currentControl = generatedLayout["Axis1"];
321321
Assert.That(currentControl.offset, Is.EqualTo(8));
322322
Assert.That(currentControl.layout, Is.EqualTo(new InternedString("Analog")));
323323

324-
currentControl = generatedLayout.controls[7];
324+
currentControl = generatedLayout["Button7"];
325325
Assert.That(currentControl.offset, Is.EqualTo(12));
326326
Assert.That(currentControl.layout, Is.EqualTo(new InternedString("Button")));
327327
}
@@ -430,6 +430,8 @@ public void Components_CanUpdateGameObjectTransformThroughTrackedPoseDriver()
430430
}
431431
}
432432

433+
private const int kNumBaseHMDControls = 10;
434+
433435
private static InputDeviceDescription CreateSimpleDeviceDescriptionByRole(InputDeviceRole role)
434436
{
435437
return new InputDeviceDescription
@@ -550,10 +552,7 @@ public static InputDeviceDescription CreateDeviceDescription()
550552
};
551553
}
552554

553-
public FourCC format
554-
{
555-
get { return new FourCC('X', 'R', 'S', '0'); }
556-
}
555+
public FourCC format => new FourCC('X', 'R', 'S', '0');
557556
}
558557

559558
[StructLayout(LayoutKind.Explicit)]

Packages/com.unity.inputsystem/CHANGELOG.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,21 @@ however, it has to be formatted properly to pass verification tests.
99

1010
## [1.0.0-preview.1] - 2999-9-20
1111

12+
### Changed
13+
14+
- Generated action wrappers now won't `Destroy` the generated Asset in a finalizer, but instead implement `IDisposable`.
15+
- Added back XR layouts (except for Magic Leap) that were removed for `1.0-preview`.
16+
* We removed these layouts under the assumption that they would almost concurrently become available in the respective device-specific XR packages. However, this did not work out as expected and the gap here turned out to be more than what we anticipated.
17+
* To deal with this gap, we have moved the bulk of the XR layouts back and will transition things gradually as support in device-specific packages becomes publicly available.
18+
1219
### Fixed
1320

1421
- Fixed a bug where the Input Settings Window might throw exceptions after assembly reload.
1522
- Correctly implemented `IsPointerOverGameObject` method for `InputSystemUIInputModule`.
1623
- Several bugs with layout overrides registered with (`InputSystem.RegisterLayoutOverrides`).
1724
* In `1.0-preview`, layout overrides could lead to corruption of the layout state and would also not be handled correctly by the various editor UIs.
1825
- Selecting a layout in the input debugger no longer selects its first child item, too.
26+
- Fixed XR devices reporting noise as valid user input (should fix problem of control schemes involving VR devices always activating when using `PlayerInput`).
1927
- Fixed tap/swipe gesture detection in touch samples.
2028

2129
### Actions
@@ -29,14 +37,11 @@ however, it has to be formatted properly to pass verification tests.
2937
- Fixed `Invoke CSharp Events` when selected in `PlayerInput` not triggering `PlayerInput.onActionTriggered`.
3038
- Fixed duplicating multiple items at the same time in the action editor duplicating them repeatedly.
3139

32-
### Changed
33-
34-
- Generated action wrappers now won't `Destroy` the generated Asset in a finalizer, but instead implement `IDisposable`.
35-
3640
### Added
3741

3842
- Will now recognize Xbox One and PS4 controllers connected to iOS devices correctly as Xbox One and PS4 controllers.
3943
- Added a new sample called "Custom Device Usages" that shows how to use a layout override on `Gamepad` to allow distinguishing two gamepads in bindings based on which player the gamepad is assigned to.
44+
- Added abstract `TrackedDevice` input device class as the basis for various kinds of tracked devices.
4045

4146
## [1.0.0-preview] - 2019-9-20
4247

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
using UnityEngine.InputSystem.Controls;
2+
using UnityEngine.InputSystem.Layouts;
3+
using UnityEngine.Scripting;
4+
5+
namespace UnityEngine.InputSystem
6+
{
7+
/// <summary>
8+
/// An input device that has its orientation and position in space tracked.
9+
/// </summary>
10+
[InputControlLayout(displayName = "Tracked Device", isGenericTypeOfDevice = true)]
11+
[Preserve]
12+
public class TrackedDevice : InputDevice
13+
{
14+
[InputControl(noisy = true)]
15+
[Preserve]
16+
public IntegerControl trackingState { get; private set; }
17+
[InputControl(noisy = true)]
18+
[Preserve]
19+
public ButtonControl isTracked { get; private set; }
20+
[InputControl(noisy = true)]
21+
[Preserve]
22+
public Vector3Control devicePosition { get; private set; }
23+
[InputControl(noisy = true)]
24+
[Preserve]
25+
public QuaternionControl deviceRotation { get; private set; }
26+
27+
protected override void FinishSetup()
28+
{
29+
base.FinishSetup();
30+
31+
trackingState = GetChildControl<IntegerControl>("trackingState");
32+
isTracked = GetChildControl<ButtonControl>("isTracked");
33+
devicePosition = GetChildControl<Vector3Control>("devicePosition");
34+
deviceRotation = GetChildControl<QuaternionControl>("deviceRotation");
35+
}
36+
}
37+
}

Packages/com.unity.inputsystem/InputSystem/Devices/TrackedDevice.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Packages/com.unity.inputsystem/InputSystem/Editor/ControlPicker/InputControlPickerDropdown.cs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -173,11 +173,8 @@ private void AddDeviceTreeItemRecursive(InputControlLayout layout, AdvancedDropd
173173
}
174174

175175
// Add controls.
176-
var haveControls = false;
177176
if (shouldIncludeDeviceLayout && m_Mode != InputControlPicker.Mode.PickDevice)
178177
{
179-
var childCountBefore = deviceItem.children.Count();
180-
181178
// The keyboard is special in that we want to allow binding by display name (i.e. character
182179
// generated by a key) instead of only by physical key location. Also, we want to give an indication
183180
// of which specific key an entry refers to by taking the current keyboard layout into account.
@@ -206,8 +203,6 @@ private void AddDeviceTreeItemRecursive(InputControlLayout layout, AdvancedDropd
206203
{
207204
AddControlTreeItemsRecursive(layout, deviceItem, layout.name, null, searchable);
208205
}
209-
210-
haveControls = deviceItem.children.Count() != childCountBefore;
211206
}
212207

213208
// Add child items.
@@ -217,7 +212,7 @@ private void AddDeviceTreeItemRecursive(InputControlLayout layout, AdvancedDropd
217212
if (!ShouldIncludeDeviceLayout(childLayout))
218213
continue;
219214

220-
if (isFirstChild && haveControls)
215+
if (isFirstChild)
221216
deviceItem.AddSeparator("More Specific " + deviceItem.name.GetPlural());
222217
isFirstChild = false;
223218

@@ -367,7 +362,8 @@ private bool ShouldIncludeDeviceLayout(InputControlLayout layout)
367362

368363
// By default, if a device has no (usable) controls, we don't want it listed in the control picker
369364
// except if we're picking devices.
370-
if (!layout.controls.Any(x => LayoutMatchesExpectedControlLayoutFilter(x.layout)) && m_Mode != InputControlPicker.Mode.PickDevice)
365+
if (!layout.controls.Any(x => LayoutMatchesExpectedControlLayoutFilter(x.layout)) && layout.controls.Any(x => true) &&
366+
m_Mode != InputControlPicker.Mode.PickDevice)
371367
return false;
372368

373369
// If we have a device filter, see if we should ignore the device.

Packages/com.unity.inputsystem/InputSystem/InputManager.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1502,6 +1502,7 @@ internal void InitializeData()
15021502
RegisterControlLayout("HumiditySensor", typeof(HumiditySensor));
15031503
RegisterControlLayout("AmbientTemperatureSensor", typeof(AmbientTemperatureSensor));
15041504
RegisterControlLayout("StepCounter", typeof(StepCounter));
1505+
RegisterControlLayout("Tracked Device", typeof(TrackedDevice));
15051506

15061507
// Register processors.
15071508
processors.AddTypeRegistration("Invert", typeof(InvertProcessor));

Packages/com.unity.inputsystem/InputSystem/InputSystem.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2895,7 +2895,7 @@ private static void PerformDefaultPluginInitialization()
28952895
Switch.SwitchSupportHID.Initialize();
28962896
#endif
28972897

2898-
#if (UNITY_EDITOR || UNITY_STANDALONE || UNITY_ANDROID || UNITY_IOS || UNITY_WSA || UNITY_LUMIN) && UNITY_INPUT_SYSTEM_ENABLE_XR
2898+
#if (UNITY_EDITOR || UNITY_STANDALONE || UNITY_ANDROID || UNITY_IOS || UNITY_WSA) && ENABLE_VR
28992899
XR.XRSupport.Initialize();
29002900
#endif
29012901

Packages/com.unity.inputsystem/InputSystem/Plugins/XR/Devices.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
#if ENABLE_VR && !DISABLE_BUILTIN_INPUT_SYSTEM_GOOGLEVR && !PACKAGE_DOCS_GENERATION
2+
using UnityEngine.InputSystem.Controls;
3+
using UnityEngine.InputSystem.Layouts;
4+
using UnityEngine.InputSystem.XR;
5+
using UnityEngine.Scripting;
6+
7+
namespace Unity.XR.GoogleVr
8+
{
9+
/// <summary>
10+
/// A head-mounted display powered by Google Daydream.
11+
/// </summary>
12+
[InputControlLayout]
13+
[Preserve]
14+
public class DaydreamHMD : XRHMD
15+
{
16+
}
17+
18+
/// <summary>
19+
/// An XR controller powered by Google Daydream.
20+
/// </summary>
21+
[InputControlLayout(commonUsages = new[] { "LeftHand", "RightHand" })]
22+
[Preserve]
23+
public class DaydreamController : XRController
24+
{
25+
[InputControl]
26+
[Preserve]
27+
public Vector2Control touchpad { get; private set; }
28+
[InputControl]
29+
[Preserve]
30+
public ButtonControl volumeUp { get; private set; }
31+
[InputControl]
32+
[Preserve]
33+
public ButtonControl recentered { get; private set; }
34+
[InputControl]
35+
[Preserve]
36+
public ButtonControl volumeDown { get; private set; }
37+
[InputControl]
38+
[Preserve]
39+
public ButtonControl recentering { get; private set; }
40+
[InputControl]
41+
[Preserve]
42+
public ButtonControl app { get; private set; }
43+
[InputControl]
44+
[Preserve]
45+
public ButtonControl home { get; private set; }
46+
[InputControl]
47+
[Preserve]
48+
public ButtonControl touchpadClicked { get; private set; }
49+
[InputControl]
50+
[Preserve]
51+
public ButtonControl touchpadTouched { get; private set; }
52+
[InputControl(noisy = true)]
53+
[Preserve]
54+
public Vector3Control deviceVelocity { get; private set; }
55+
[InputControl(noisy = true)]
56+
[Preserve]
57+
public Vector3Control deviceAcceleration { get; private set; }
58+
59+
protected override void FinishSetup()
60+
{
61+
base.FinishSetup();
62+
63+
touchpad = GetChildControl<Vector2Control>("touchpad");
64+
volumeUp = GetChildControl<ButtonControl>("volumeUp");
65+
recentered = GetChildControl<ButtonControl>("recentered");
66+
volumeDown = GetChildControl<ButtonControl>("volumeDown");
67+
recentering = GetChildControl<ButtonControl>("recentering");
68+
app = GetChildControl<ButtonControl>("app");
69+
home = GetChildControl<ButtonControl>("home");
70+
touchpadClicked = GetChildControl<ButtonControl>("touchpadClicked");
71+
touchpadTouched = GetChildControl<ButtonControl>("touchpadTouched");
72+
deviceVelocity = GetChildControl<Vector3Control>("deviceVelocity");
73+
deviceAcceleration = GetChildControl<Vector3Control>("deviceAcceleration");
74+
}
75+
}
76+
}
77+
#endif

0 commit comments

Comments
 (0)