Skip to content

Commit 4c668b7

Browse files
committed
Merge branch 'develop' into bugfix/XR-10725-initial-focus-desync
2 parents 67f6c04 + d2d0b1a commit 4c668b7

7 files changed

Lines changed: 67 additions & 5 deletions

File tree

Assets/Tests/InputSystem/CoreTests_Controls.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1428,7 +1428,7 @@ public void Controls_OptimizedControls_TrivialControlsAreOptimized()
14281428
Assert.That(mouse.position.x.optimizedControlDataType, Is.EqualTo(InputStateBlock.FormatFloat));
14291429
Assert.That(mouse.position.y.optimizedControlDataType, Is.EqualTo(InputStateBlock.FormatFloat));
14301430
Assert.That(mouse.position.optimizedControlDataType, Is.EqualTo(InputStateBlock.FormatVector2));
1431-
Assert.That(mouse.leftButton.optimizedControlDataType, Is.EqualTo(InputStateBlock.FormatInvalid));
1431+
Assert.That(mouse.leftButton.optimizedControlDataType, Is.EqualTo(InputStateBlock.FormatBit));
14321432

14331433
InputSystem.settings.SetInternalFeatureFlag(InputFeatureNames.kUseOptimizedControls, false);
14341434
Assert.That(mouse.position.x.optimizedControlDataType, Is.EqualTo(InputStateBlock.FormatInvalid));

Assets/Tests/InputSystem/Plugins/XRTests.cs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1222,6 +1222,52 @@ public void Controls_OptimizedControls_PoseControl_IsOptimized()
12221222
Assert.That((device["posecontrol"] as PoseControl).optimizedControlDataType, Is.EqualTo(InputStateBlock.FormatPose));
12231223
}
12241224

1225+
[Test]
1226+
[Category("Controls")]
1227+
[TestCase(true)]
1228+
[TestCase(false)]
1229+
public void Controls_PoseControl_IsTracked_ReadsCorrectly(bool useOptimizedControls)
1230+
{
1231+
InputSystem.settings.SetInternalFeatureFlag(InputFeatureNames.kUseOptimizedControls, useOptimizedControls);
1232+
1233+
runtime.ReportNewInputDevice(PoseDeviceState.CreateDeviceDescription().ToJson());
1234+
1235+
InputSystem.Update();
1236+
1237+
var device = InputSystem.devices[0];
1238+
var poseControl = device["posecontrol"] as PoseControl;
1239+
1240+
// Queue state with isTracked = true (byte value 1)
1241+
InputSystem.QueueStateEvent(device, new PoseDeviceState
1242+
{
1243+
isTracked = 1,
1244+
trackingState = (uint)(InputTrackingState.Position | InputTrackingState.Rotation),
1245+
position = new Vector3(1, 2, 3),
1246+
rotation = Quaternion.identity,
1247+
});
1248+
InputSystem.Update();
1249+
1250+
// Reading isTracked as a ButtonControl should return true
1251+
Assert.That(poseControl.isTracked.isPressed, Is.True, "isTracked.isPressed should be true when tracked");
1252+
Assert.That(poseControl.isTracked.ReadValue(), Is.EqualTo(1.0f).Within(0.001f), "isTracked.ReadValue() should be 1.0f when tracked");
1253+
1254+
// Reading the full PoseState should also have isTracked = true
1255+
var poseState = poseControl.ReadValue();
1256+
Assert.That(poseState.isTracked, Is.True, "PoseState.isTracked should be true when tracked");
1257+
1258+
// Queue state with isTracked = false (byte value 0)
1259+
InputSystem.QueueStateEvent(device, new PoseDeviceState
1260+
{
1261+
isTracked = 0,
1262+
trackingState = 0,
1263+
});
1264+
InputSystem.Update();
1265+
1266+
Assert.That(poseControl.isTracked.isPressed, Is.False, "isTracked.isPressed should be false when not tracked");
1267+
Assert.That(poseControl.isTracked.ReadValue(), Is.EqualTo(0.0f).Within(0.001f), "isTracked.ReadValue() should be 0.0f when not tracked");
1268+
Assert.That(poseControl.ReadValue().isTracked, Is.False, "PoseState.isTracked should be false when not tracked");
1269+
}
1270+
12251271
// ISXB-405
12261272
[Test]
12271273
[Category("Devices")]

Packages/com.unity.inputsystem/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
3434
- Fixed `IndexOutOfRangeException` in `InputDeviceBuilder` when connecting an HID gamepad whose report descriptor declares a hat switch with Report Size 8 (e.g. ESP32-BLE-Gamepad). The HID layer now anchors the hat's directional sub-controls to the hat's own byte instead of letting the layout system auto-allocate a fresh byte for each [UUM-143659](https://jira.unity3d.com/browse/UUM-143659).
3535
- Fixed `OnMouseUpAsButton` and `OnMouseUp` being dropped in Play mode when the Game view's focus changes between a press and its release on Unity 6000.5.0a8 and newer. The legacy `SendMouseEvents` pipeline is no longer driven from `InputUpdateType.Editor` updates, which read the editor state buffer (position (0,0), not pressed) and produced a spurious mouse release that cleared the press target.
3636
- Fixed Input Debugger window's incorrect name. It is now called 'Input Debugger' instead of 'Input Debug' [UUM-137124](https://jira.unity3d.com/browse/UUM-137124).
37+
- Fixed `PoseControl.isTracked` always returning false when read through non-optimized code paths (e.g. Input Debugger) due to `sizeInBits = 8` causing the value to be normalized as `1/255` instead of `1.0`.
3738

3839
### Changed
3940
- Action-level `IsPressed`, `WasPressedThisFrame`, and `WasReleasedThisFrame` for bindings to `Vector2Control` / `StickControl` no longer consult a per-control `pressPoint` on the vector (that field was removed). Use a `Press` interaction to set a custom threshold, or rely on `defaultButtonPressPoint`.

Packages/com.unity.inputsystem/Documentation~/create-precompiled-layout.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,5 +90,3 @@ namepace MyNamespace
9090
{
9191
//...
9292
```
93-
94-
The namespace of the generated layout will correspond to the

Packages/com.unity.inputsystem/InputSystem/Runtime/Controls/AxisControl.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,7 @@ private float EvaluateMagnitude(float value)
310310
return NormalizeProcessor.Normalize(clampedValue, min, max, 0);
311311
}
312312

313+
/// <inheritdoc />
313314
protected override FourCC CalculateOptimizedControlDataType()
314315
{
315316
var noProcessingNeeded =

Packages/com.unity.inputsystem/InputSystem/Runtime/Controls/ButtonControl.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Runtime.CompilerServices;
33
using UnityEngine.InputSystem.LowLevel;
4+
using UnityEngine.InputSystem.Utilities;
45
using UnityEngine.Scripting;
56

67
////REVIEW: introduce separate base class for ButtonControl and AxisControl instead of deriving ButtonControl from AxisControl?
@@ -378,6 +379,21 @@ internal void UpdateWasPressedEditor()
378379

379380
#endif // UNITY_EDITOR
380381

382+
/// <inheritdoc />
383+
protected override FourCC CalculateOptimizedControlDataType()
384+
{
385+
if (clamp == Clamp.None &&
386+
invert == false &&
387+
normalize == false &&
388+
scale == false &&
389+
m_StateBlock.format == InputStateBlock.FormatBit &&
390+
m_StateBlock.sizeInBits == 1 &&
391+
m_StateBlock.bitOffset == 0)
392+
return InputStateBlock.FormatBit;
393+
394+
return base.CalculateOptimizedControlDataType();
395+
}
396+
381397
// We make the current global default button press point available as a static so that we don't have to
382398
// constantly make the hop from InputSystem.settings -> InputManager.m_Settings -> defaultButtonPressPoint.
383399
internal static float s_GlobalDefaultButtonPressPoint;

Packages/com.unity.inputsystem/InputSystem/Runtime/Plugins/XR/Controls/PoseControl.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public PoseState(bool isTracked, TrackingState trackingState, Vector3 position,
6060
/// <remarks>
6161
/// Fully tracked means that the pose is accurate and not using any simulated or extrapolated positions, and the system tracking this pose is able to confidently track this object.
6262
/// </remarks>
63-
[FieldOffset(0), InputControl(displayName = "Is Tracked", layout = "Button", sizeInBits = 8 /* needed to ensure optimization kicks-in */)]
63+
[FieldOffset(0), InputControl(displayName = "Is Tracked", layout = "Button", sizeInBits = 1)]
6464
public bool isTracked;
6565

6666
/// <summary>
@@ -252,7 +252,7 @@ protected override FourCC CalculateOptimizedControlDataType()
252252
if (
253253
m_StateBlock.sizeInBits == PoseState.kSizeInBytes * 8 &&
254254
m_StateBlock.bitOffset == 0 &&
255-
isTracked.optimizedControlDataType == InputStateBlock.kFormatByte &&
255+
isTracked.optimizedControlDataType == InputStateBlock.kFormatBit &&
256256
trackingState.optimizedControlDataType == InputStateBlock.kFormatInt &&
257257
position.optimizedControlDataType == InputStateBlock.kFormatVector3 &&
258258
rotation.optimizedControlDataType == InputStateBlock.kFormatQuaternion &&

0 commit comments

Comments
 (0)