Skip to content

Commit 393d9ae

Browse files
author
Rene Damm
authored
FIX: Non-functional 'view' and 'menu' buttons on XInputController (#784).
1 parent ca3f46c commit 393d9ae

File tree

14 files changed

+233
-36
lines changed

14 files changed

+233
-36
lines changed

Assets/Tests/InputSystem/CoreTests_Layouts.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1059,6 +1059,24 @@ public void Layouts_RegisteringLayoutType_UsesBaseTypeAsBaseLayout()
10591059
Assert.That(layout.baseLayouts, Is.EquivalentTo(new[] {new InternedString("Pointer")}));
10601060
}
10611061

1062+
class DeviceWithControlProperties : InputDevice
1063+
{
1064+
public ButtonControl propertyWithoutAttribute { get; set; }
1065+
[InputControl]
1066+
public ButtonControl propertyWithAttribute { get; set; }
1067+
}
1068+
1069+
[Test]
1070+
[Category("Layouts")]
1071+
public void Layouts_RegisteringLayoutType_OnlyAddsPropertiesWithExplicitAttribute()
1072+
{
1073+
var device = InputSystem.AddDevice<DeviceWithControlProperties>();
1074+
1075+
Assert.That(device.TryGetChildControl("propertyWithoutAttribute"), Is.Null);
1076+
Assert.That(device.TryGetChildControl("propertyWithAttribute"), Is.Not.Null);
1077+
Assert.That(device.TryGetChildControl("propertyWithAttribute"), Is.TypeOf<ButtonControl>());
1078+
}
1079+
10621080
// We consider layouts built by layout builders as being auto-generated. We want them to
10631081
// be overridable by layouts built specifically for a device so we boost the score of
10641082
// of type and JSON layouts such that they will override auto-generated layouts even if
@@ -1378,6 +1396,7 @@ public void Layouts_CanSpecifyMinAndMaxValuesForControlInJson()
13781396

13791397
class BaseClassWithControl : InputDevice
13801398
{
1399+
[InputControl]
13811400
public AxisControl controlFromBase { get; set; }
13821401
}
13831402

Assets/Tests/InputSystem/Plugins/XRTests.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,9 @@ public void Layouts_ButtonsArePackedByTheByte_WhileLargerStructuresAreFourByteAl
358358
[InputControlLayout(updateBeforeRender = true)]
359359
private class TestHMD : InputDevice
360360
{
361+
[InputControl]
361362
public QuaternionControl quaternion { get; private set; }
363+
[InputControl]
362364
public Vector3Control vector3 { get; private set; }
363365
protected override void FinishSetup()
364366
{

Packages/com.unity.inputsystem/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ however, it has to be formatted properly to pass verification tests.
1111

1212
### Fixed
1313

14+
- `XInputController` and `XboxOneGamepad` no longer have two extraneous, non-functional "menu" and "view" buttons.
1415
- Fixed `InputUser.onUnpairedDeviceUser` ignoring input on controls that do not support `EvaluateMagnitude`.
1516
* This led to situations, for example, where `PlayerInput` would not initialize a control scheme switch from a `<Mouse>/delta` binding as the delta X and Y axes do not have min&max limits and thus return -1 from `EvaluateMagnitude`.
1617
- Fixed available processor list not updated right away when changing the action type in the Input Action editor window.

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -759,6 +759,13 @@ private static void AddControlItemsFromMembers(MemberInfo[] members, List<Contro
759759
{
760760
if (valueType == null || !typeof(InputControl).IsAssignableFrom(valueType))
761761
continue;
762+
763+
// On properties, we require explicit [InputControl] attributes to
764+
// pick them up. Doing it otherwise has proven to lead too easily to
765+
// situations where you inadvertently add new controls to a layout
766+
// just because you added an InputControl-type property to a class.
767+
if (member is PropertyInfo)
768+
continue;
762769
}
763770

764771
AddControlItemsFromMember(member, attributes, controlItems, layoutName);

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,13 @@ public class QuaternionControl : InputControl<Quaternion>
1616
// Also, it allows putting processors on the individual components which may be necessary
1717
// to properly convert the source data.
1818

19+
[InputControl]
1920
public AxisControl x { get; private set; }
21+
[InputControl]
2022
public AxisControl y { get; private set; }
23+
[InputControl]
2124
public AxisControl z { get; private set; }
25+
[InputControl]
2226
public AxisControl w { get; private set; }
2327

2428
public QuaternionControl()

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,27 +13,40 @@ namespace UnityEngine.InputSystem.Controls
1313
[InputControlLayout(stateType = typeof(TouchState))]
1414
public class TouchControl : InputControl<TouchState>
1515
{
16+
[InputControl]
1617
public TouchPressControl press { get; private set; }
1718

1819
/// <summary>
1920
/// The ID of the touch contact as reported by the underlying system.
2021
/// </summary>
22+
[InputControl]
2123
public IntegerControl touchId { get; private set; }
2224

2325
/// <summary>
2426
/// Absolute position on the touch surface.
2527
/// </summary>
28+
[InputControl]
2629
public Vector2Control position { get; private set; }
2730

31+
[InputControl]
2832
public Vector2Control delta { get; private set; }
33+
[InputControl]
2934
public AxisControl pressure { get; private set; }
35+
[InputControl]
3036
public Vector2Control radius { get; private set; }
37+
[InputControl]
3138
public TouchPhaseControl phase { get; private set; }
39+
[InputControl]
3240
public IntegerControl displayIndex { get; private set; }
41+
[InputControl]
3342
public ButtonControl indirectTouch { get; private set; }
43+
[InputControl]
3444
public ButtonControl tap { get; private set; }
45+
[InputControl]
3546
public IntegerControl tapCount { get; private set; }
47+
[InputControl]
3648
public DoubleControl startTime { get; private set; }
49+
[InputControl]
3750
public Vector2Control startPosition { get; private set; }
3851

3952
public bool isInProgress

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

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,7 @@ internal struct AccelerometerState : IInputStateTypeInfo
1919
[InputControl(processors = "CompensateDirection", noisy = true)]
2020
public Vector3 acceleration;
2121

22-
public FourCC format
23-
{
24-
get { return kFormat; }
25-
}
22+
public FourCC format => kFormat;
2623
}
2724

2825
internal struct GyroscopeState : IInputStateTypeInfo
@@ -32,10 +29,7 @@ internal struct GyroscopeState : IInputStateTypeInfo
3229
[InputControl(processors = "CompensateDirection", noisy = true)]
3330
public Vector3 angularVelocity;
3431

35-
public FourCC format
36-
{
37-
get { return kFormat; }
38-
}
32+
public FourCC format => kFormat;
3933
}
4034

4135
internal struct GravityState : IInputStateTypeInfo
@@ -45,10 +39,7 @@ internal struct GravityState : IInputStateTypeInfo
4539
[InputControl(processors = "CompensateDirection", noisy = true)]
4640
public Vector3 gravity;
4741

48-
public FourCC format
49-
{
50-
get { return kFormat; }
51-
}
42+
public FourCC format => kFormat;
5243
}
5344

5445
internal struct AttitudeState : IInputStateTypeInfo
@@ -58,10 +49,7 @@ internal struct AttitudeState : IInputStateTypeInfo
5849
[InputControl(processors = "CompensateRotation", noisy = true)]
5950
public Quaternion attitude;
6051

61-
public FourCC format
62-
{
63-
get { return kFormat; }
64-
}
52+
public FourCC format => kFormat;
6553
}
6654

6755
internal struct LinearAccelerationState : IInputStateTypeInfo
@@ -71,10 +59,7 @@ internal struct LinearAccelerationState : IInputStateTypeInfo
7159
[InputControl(processors = "CompensateDirection", noisy = true)]
7260
public Vector3 acceleration;
7361

74-
public FourCC format
75-
{
76-
get { return kFormat; }
77-
}
62+
public FourCC format => kFormat;
7863
}
7964
}
8065

@@ -315,6 +300,7 @@ public class MagneticFieldSensor : Sensor
315300
/// <remarks>
316301
/// Values are in micro-Tesla (uT) and measure the ambient magnetic field in the X, Y and Z axis.
317302
/// </remarks>
303+
[InputControl]
318304
public Vector3Control magneticField { get; private set; }
319305

320306
public static MagneticFieldSensor current { get; private set; }
@@ -348,6 +334,7 @@ public class LightSensor : Sensor
348334
/// <summary>
349335
/// Light level in SI lux units.
350336
/// </summary>
337+
[InputControl]
351338
public AxisControl lightLevel { get; private set; }
352339

353340
public static LightSensor current { get; private set; }
@@ -381,6 +368,7 @@ public class PressureSensor : Sensor
381368
/// <summary>
382369
/// Atmospheric pressure in hPa (millibar).
383370
/// </summary>
371+
[InputControl]
384372
public AxisControl atmosphericPressure { get; private set; }
385373

386374
public static PressureSensor current { get; private set; }
@@ -417,6 +405,7 @@ public class ProximitySensor : Sensor
417405
/// <summary>
418406
/// Proximity sensor distance measured in centimeters.
419407
/// </summary>
408+
[InputControl]
420409
public AxisControl distance { get; private set; }
421410

422411
public static ProximitySensor current { get; private set; }
@@ -450,6 +439,7 @@ public class HumiditySensor : Sensor
450439
/// <summary>
451440
/// Relative ambient air humidity in percent.
452441
/// </summary>
442+
[InputControl]
453443
public AxisControl relativeHumidity { get; private set; }
454444

455445
public static HumiditySensor current { get; private set; }
@@ -483,6 +473,7 @@ public class AmbientTemperatureSensor : Sensor
483473
/// <summary>
484474
/// Temperature in degree Celsius.
485475
/// </summary>
476+
[InputControl]
486477
public AxisControl ambientTemperature { get; private set; }
487478

488479
public static AmbientTemperatureSensor current { get; private set; }
@@ -516,6 +507,7 @@ public class StepCounter : Sensor
516507
/// <summary>
517508
/// The number of steps taken by the user since the last reboot while activated.
518509
/// </summary>
510+
[InputControl]
519511
public IntegerControl stepCounter { get; private set; }
520512

521513
public static StepCounter current { get; private set; }

Packages/com.unity.inputsystem/InputSystem/Plugins/Android/AndroidSensors.cs

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -105,25 +105,19 @@ internal unsafe struct AndroidSensorState : IInputStateTypeInfo
105105
public AndroidSensorState WithData(params float[] data)
106106
{
107107
if (data == null)
108-
throw new System.ArgumentNullException(nameof(data));
108+
throw new ArgumentNullException(nameof(data));
109109

110-
fixed(float* dataPtr = this.data)
111-
{
112-
for (var i = 0; i < data.Length && i < 16; i++)
113-
dataPtr[i] = data[i];
110+
for (var i = 0; i < data.Length && i < 16; i++)
111+
this.data[i] = data[i];
114112

115-
// Fill the rest with zeroes
116-
for (var i = data.Length; i < 16; i++)
117-
dataPtr[i] = 0.0f;
118-
}
113+
// Fill the rest with zeroes
114+
for (var i = data.Length; i < 16; i++)
115+
this.data[i] = 0.0f;
119116

120117
return this;
121118
}
122119

123-
public FourCC format
124-
{
125-
get { return kFormat; }
126-
}
120+
public FourCC format => kFormat;
127121
}
128122

129123
internal class AndroidCompensateDirectionProcessor : CompensateDirectionProcessor

Packages/com.unity.inputsystem/InputSystem/Plugins/DualShock/DualShockGamepad.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ namespace UnityEngine.InputSystem.DualShock
1111
[InputControlLayout(displayName = "PS4 Controller")]
1212
public class DualShockGamepad : Gamepad, IDualShockHaptics
1313
{
14+
[InputControl]
1415
public ButtonControl touchpadButton { get; private set; }
1516

1617
[InputControl(name = "start", displayName = "Options")]

Packages/com.unity.inputsystem/InputSystem/Plugins/XR/Daydream.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,25 @@ namespace UnityEngine.InputSystem.XR
99
[InputControlLayout]
1010
public class DaydreamHMD : XRHMD
1111
{
12+
[InputControl]
1213
public IntegerControl trackingState { get; private set; }
14+
[InputControl]
1315
public ButtonControl isTracked { get; private set; }
16+
[InputControl]
1417
public Vector3Control devicePosition { get; private set; }
18+
[InputControl]
1519
public QuaternionControl deviceRotation { get; private set; }
20+
[InputControl]
1621
public Vector3Control leftEyePosition { get; private set; }
22+
[InputControl]
1723
public QuaternionControl leftEyeRotation { get; private set; }
24+
[InputControl]
1825
public Vector3Control rightEyePosition { get; private set; }
26+
[InputControl]
1927
public QuaternionControl rightEyeRotation { get; private set; }
28+
[InputControl]
2029
public Vector3Control centerEyePosition { get; private set; }
30+
[InputControl]
2131
public QuaternionControl centerEyeRotation { get; private set; }
2232

2333
protected override void FinishSetup()
@@ -43,21 +53,36 @@ protected override void FinishSetup()
4353
[InputControlLayout(commonUsages = new[] { "LeftHand", "RightHand" })]
4454
public class DaydreamController : XRController
4555
{
56+
[InputControl]
4657
public Vector2Control touchpad { get; private set; }
58+
[InputControl]
4759
public ButtonControl volumeUp { get; private set; }
60+
[InputControl]
4861
public ButtonControl recentered { get; private set; }
62+
[InputControl]
4963
public ButtonControl volumeDown { get; private set; }
64+
[InputControl]
5065
public ButtonControl recentering { get; private set; }
66+
[InputControl]
5167
public ButtonControl app { get; private set; }
68+
[InputControl]
5269
public ButtonControl home { get; private set; }
70+
[InputControl]
5371
public ButtonControl touchpadClicked { get; private set; }
72+
[InputControl]
5473
public ButtonControl touchpadTouched { get; private set; }
5574

75+
[InputControl]
5676
public IntegerControl trackingState { get; private set; }
77+
[InputControl]
5778
public ButtonControl isTracked { get; private set; }
79+
[InputControl]
5880
public Vector3Control devicePosition { get; private set; }
81+
[InputControl]
5982
public QuaternionControl deviceRotation { get; private set; }
83+
[InputControl]
6084
public Vector3Control deviceVelocity { get; private set; }
85+
[InputControl]
6186
public Vector3Control deviceAcceleration { get; private set; }
6287

6388
protected override void FinishSetup()

0 commit comments

Comments
 (0)