Skip to content

ISX-2228: Add OrientationSensor (device orientation parity) - #2468

Open
K-Tone wants to merge 4 commits into
im-parity/stagingfrom
anthony/im-parity-orientation
Open

ISX-2228: Add OrientationSensor (device orientation parity)#2468
K-Tone wants to merge 4 commits into
im-parity/stagingfrom
anthony/im-parity-orientation

Conversation

@K-Tone

@K-Tone K-Tone commented Aug 7, 2026

Copy link
Copy Markdown
Collaborator

Summary

Adds an OrientationSensor to the Input System package, giving feature parity with the legacy UnityEngine.Input.deviceOrientation (ISX-2228, part of the IM API parity epic ISX-2108).

The Input System had every raw motion sensor but no discrete physical-orientation value. This adds one, modeled on the existing sensor + enum-control patterns.

What's in this PR (managed / package side)

  • DeviceOrientation enum (UnityEngine.InputSystem) — package-local, values identical to the legacy UnityEngine.DeviceOrientation (Unknown=0 … FaceDown=6). Kept independent of the legacy input module so the package stays self-contained.
  • OrientationControl : InputControl<DeviceOrientation> — enum-backed control, modeled on TouchPhaseControl.
  • OrientationSensor : Sensor + OrientationState (FourCC 'ORNT', int orientation). Reports the raw physical orientation — deliberately not run through screen-orientation compensation.
  • Registered the "Orientation" control and "OrientationSensor" device layouts.
  • Platform layout matchers: iOS and Android map their native orientation device (deviceClass "Orientation") to OrientationSensor. WebGL/UWP match by layout name directly (no matcher needed).
  • Unity Remote: handle the existing DeviceOrientation message (type 4) — no Remote-app change required — and surface an OrientationSensor while connected.

Tests

  • Devices_CanGetDeviceOrientationReading (mock runtime) + OrientationSensor added to Devices_CanCreateDevice.
  • Remote_CanReceiveDeviceOrientationFromUnityRemote.

Companion PR

Native per-platform producers that feed this device live in unity.git (trunk): ISX-2228 native device orientation producers. Both are needed end-to-end; this managed side also gets mirrored into unity.git/ShadowPackages at publish time.

Notes

  • Usage: OrientationSensor.current.orientation.ReadValue() (enable the device first, like any sensor).
  • Consumers with both using UnityEngine; and using UnityEngine.InputSystem; disambiguate DeviceOrientation with a using alias — the same established pattern as Gyroscope/TouchPhase.

🤖 Generated with Claude Code

K-Tone and others added 4 commits August 7, 2026 14:34
Add an OrientationSensor device to the Input System package that reports
the physical device orientation as a discrete value, providing feature
parity with the legacy UnityEngine.Input.deviceOrientation property.

- Add package-local UnityEngine.InputSystem.DeviceOrientation enum
  (values identical to the legacy enum, kept independent of the legacy
  input module).
- Add OrientationControl : InputControl<DeviceOrientation>, modeled on
  TouchPhaseControl.
- Add OrientationState (FourCC 'ORNT') and OrientationSensor : Sensor.
  The reported value is deliberately not compensated for screen
  orientation.
- Register the "Orientation" control and "OrientationSensor" device
  layouts.
- Add a mock-runtime unit test and cover OrientationSensor in
  Devices_CanCreateDevice.

Native producers (per-platform) and docs/changelog follow in later
changes.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Add a layout matcher so the native iOS orientation device (interface
"iOS", deviceClass "Orientation") resolves to the OrientationSensor
layout, following the same convention as the Gravity/Attitude/
LinearAcceleration sensors.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Add a layout matcher so the native Android orientation device (interface
"Android", deviceClass "Orientation") resolves to the OrientationSensor
layout. Unlike the other Android sensors it is not an ASensor, so it maps
directly to the base layout rather than an AndroidSensor variant.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Surface an OrientationSensor when connected to the Unity Remote so device
orientation can be tested in the Editor.

- Handle the existing MessageType.DeviceOrientation message (the Remote app
  already sends it) and queue it to an OrientationSensor added on connect.
  No change to the Remote app is required.
- Add a DeviceOrientationMessage struct matching HandleOrientationMessage in
  GenericRemote.cpp (header + int32 orientation, same enum values as ours).
- Remove the device on disconnect and clear it on manual removal.
- Add Remote_CanReceiveDeviceOrientationFromUnityRemote test.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

@u-pr u-pr Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Harness Review

LGTM

The runtime integration follows the existing sensor and Unity Remote patterns, but the PR leaves the documented migration path inaccurate and adds an unrelated project-wide dependency.

P2

The shipped documentation still says Input.deviceOrientation has “No corresponding API yet” in Documentation~/corresponding-old-new-api.md, and Documentation~/supported-sensors-reference.md omits the new sensor. Users following the migration guide or support matrix will therefore conclude this feature is unavailable. Update those references to point to OrientationSensor.current.orientation.ReadValue() and document its supported platforms.

Reviewed commit 732016b

🤖 Helpful? 👍/👎

Comment thread Packages/manifest.json
"com.unity.ide.rider": "3.0.39",
"com.unity.ide.visualstudio": "2.0.27",
"com.unity.multiplayer.center": "1.0.0",
"com.unity.pipeline": "0.4.0-exp.1",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2

com.unity.pipeline is not referenced anywhere else in this checkout, so this root-manifest entry is unrelated to the orientation feature. Every developer and CI checkout will now resolve and install this experimental package (and any transitive dependencies), expanding the project's dependency surface for no implementation benefit. Please remove this accidental manifest change or move an intentional pipeline integration to its own documented change.

🤖 Helpful? 👍/👎

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment is because the wrong base was picked by claude when opening pr, I fixed that

@K-Tone
K-Tone changed the base branch from develop to im-parity/staging August 7, 2026 14:08
@codecov-github-com

codecov-github-com Bot commented Aug 7, 2026

Copy link
Copy Markdown

Codecov Report

Attention: Patch coverage is 88.05970% with 8 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...InputSystem/Runtime/Controls/OrientationControl.cs 66.66% 4 Missing ⚠️
...sets/Tests/InputSystem/Plugins/UnityRemoteTests.cs 80.00% 3 Missing ⚠️
...m/Editor/Plugins/UnityRemote/UnityRemoteSupport.cs 91.66% 1 Missing ⚠️
@@                 Coverage Diff                  @@
##             im-parity/staging    #2468   +/-   ##
====================================================
  Coverage                     ?   78.96%           
====================================================
  Files                        ?      768           
  Lines                        ?   140874           
  Branches                     ?        0           
====================================================
  Hits                         ?   111242           
  Misses                       ?    29632           
  Partials                     ?        0           
Flag Coverage Δ
inputsystem_MacOS_6000.0_project 77.50% <88.05%> (?)
inputsystem_MacOS_6000.3_project 77.50% <88.05%> (?)
inputsystem_MacOS_6000.5_project 77.55% <88.05%> (?)
inputsystem_MacOS_6000.6_project 77.55% <88.05%> (?)
inputsystem_MacOS_6000.7_project 77.55% <88.05%> (?)
inputsystem_Ubuntu_6000.0_project 77.41% <88.05%> (?)
inputsystem_Ubuntu_6000.3_project 77.40% <88.05%> (?)
inputsystem_Ubuntu_6000.5_project 77.46% <88.05%> (?)
inputsystem_Ubuntu_6000.6_project 77.47% <88.05%> (?)
inputsystem_Ubuntu_6000.7_project 77.46% <88.05%> (?)
inputsystem_Windows_6000.0_project 77.57% <88.05%> (?)
inputsystem_Windows_6000.3_project 77.56% <88.05%> (?)
inputsystem_Windows_6000.5_project 77.63% <88.05%> (?)
inputsystem_Windows_6000.6_project 77.63% <88.05%> (?)
inputsystem_Windows_6000.7_project 77.63% <88.05%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
Assets/Tests/InputSystem/CoreTests_Devices.cs 98.24% <100.00%> (ø)
....inputsystem/InputSystem/Runtime/Devices/Sensor.cs 99.56% <100.00%> (ø)
...ty.inputsystem/InputSystem/Runtime/InputManager.cs 89.02% <100.00%> (ø)
...utSystem/Runtime/Plugins/Android/AndroidSupport.cs 94.00% <100.00%> (ø)
...stem/InputSystem/Runtime/Plugins/iOS/iOSSupport.cs 76.47% <100.00%> (ø)
...m/Editor/Plugins/UnityRemote/UnityRemoteSupport.cs 91.92% <91.66%> (ø)
...sets/Tests/InputSystem/Plugins/UnityRemoteTests.cs 95.48% <80.00%> (ø)
...InputSystem/Runtime/Controls/OrientationControl.cs 66.66% <66.66%> (ø)

ℹ️ Need help interpreting these results?

/// </example>
/// </remarks>
[InputControlLayout(stateType = typeof(OrientationState), displayName = "Orientation")]
public class OrientationSensor : Sensor

@MorganHoarau MorganHoarau Aug 7, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like mentioned in this thread: https://unity.slack.com/archives/C0BKX81LUNL/p1785848600476409?thread_ts=1785835628.354409&cid=C0BKX81LUNL

Need to name the sensor: DeviceOrientationSensor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants