-
Notifications
You must be signed in to change notification settings - Fork 341
ISX-2228: Add OrientationSensor (device orientation parity) #2468
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: im-parity/staging
Are you sure you want to change the base?
Changes from all commits
86d1342
9da5486
2bbf38b
732016b
c0e2796
50955a9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| using UnityEngine.InputSystem.Layouts; | ||
| using UnityEngine.InputSystem.LowLevel; | ||
|
|
||
| namespace UnityEngine.InputSystem.Controls | ||
| { | ||
| /// <summary> | ||
| /// A control reading a <see cref="DeviceOrientation"/> value. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// This is used by <see cref="DeviceOrientationSensor"/> to report the physical orientation of the device | ||
| /// (see <see cref="DeviceOrientationSensor.orientation"/>). It provides feature parity with the legacy | ||
| /// <c>UnityEngine.Input.deviceOrientation</c> property. | ||
| /// </remarks> | ||
| /// <seealso cref="DeviceOrientationSensor"/> | ||
| [InputControlLayout(hideInUI = true)] | ||
| public class OrientationControl : InputControl<DeviceOrientation> | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't it be renamed |
||
| { | ||
| /// <summary> | ||
| /// Default-initialize the control. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// Format of the control is <see cref="InputStateBlock.FormatInt"/> | ||
| /// by default. | ||
| /// </remarks> | ||
| public OrientationControl() | ||
| { | ||
| m_StateBlock.format = InputStateBlock.FormatInt; | ||
| } | ||
|
|
||
| /// <inheritdoc /> | ||
| public override unsafe DeviceOrientation ReadUnprocessedValueFromState(void* statePtr) | ||
| { | ||
| var intValue = stateBlock.ReadInt(statePtr); | ||
| return (DeviceOrientation)intValue; | ||
| } | ||
|
|
||
| /// <inheritdoc /> | ||
| public override unsafe void WriteValueIntoState(DeviceOrientation value, void* statePtr) | ||
| { | ||
| var valuePtr = (byte*)statePtr + (int)m_StateBlock.byteOffset; | ||
| *(int*)valuePtr = (int)value; | ||
| } | ||
| } | ||
| } | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -60,6 +60,18 @@ internal struct LinearAccelerationState : IInputStateTypeInfo | |||||
|
|
||||||
| public FourCC format => kFormat; | ||||||
| } | ||||||
|
|
||||||
| internal struct DeviceOrientationState : IInputStateTypeInfo | ||||||
| { | ||||||
| public static FourCC kFormat => new FourCC('O', 'R', 'N', 'T'); | ||||||
|
|
||||||
| // Note: unlike the other sensors this value is *not* compensated for screen orientation. It reports | ||||||
| // the physical orientation of the device and thus must be independent of how the content is rendered. | ||||||
| [InputControl(name = "orientation", displayName = "Orientation", layout = "Orientation")] | ||||||
| public int orientation; | ||||||
|
|
||||||
| public FourCC format => kFormat; | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| namespace UnityEngine.InputSystem | ||||||
|
|
@@ -694,4 +706,109 @@ protected override void FinishSetup() | |||||
| base.FinishSetup(); | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| /// <summary> | ||||||
| /// Enum describing the physical orientation of a device as reported by <see cref="DeviceOrientationSensor"/>. | ||||||
| /// </summary> | ||||||
| /// <remarks> | ||||||
| /// The values mirror the legacy <c>UnityEngine.DeviceOrientation</c> enum so that content migrating from | ||||||
| /// <c>UnityEngine.Input.deviceOrientation</c> to the Input System observes identical semantics. Note that this | ||||||
| /// is a package-local enum, kept independent of the legacy input module. | ||||||
| /// </remarks> | ||||||
| /// <seealso cref="DeviceOrientationSensor"/> | ||||||
| public enum DeviceOrientation | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As pointed by Hakan on the Location PR, long term we will need to move it to module side and make the command use it. |
||||||
| { | ||||||
| /// <summary>The orientation of the device cannot be determined.</summary> | ||||||
| Unknown = 0, | ||||||
|
|
||||||
| /// <summary>The device is in portrait mode, with the device held upright and the home button at the bottom.</summary> | ||||||
| Portrait = 1, | ||||||
|
|
||||||
| /// <summary>The device is in portrait mode but upside down, with the device held upright and the home button at the top.</summary> | ||||||
| PortraitUpsideDown = 2, | ||||||
|
|
||||||
| /// <summary>The device is in landscape mode, with the device held upright and the home button on the right side.</summary> | ||||||
| LandscapeLeft = 3, | ||||||
|
|
||||||
| /// <summary>The device is in landscape mode, with the device held upright and the home button on the left side.</summary> | ||||||
| LandscapeRight = 4, | ||||||
|
|
||||||
| /// <summary>The device is held parallel to the ground with the screen facing upwards.</summary> | ||||||
| FaceUp = 5, | ||||||
|
|
||||||
| /// <summary>The device is held parallel to the ground with the screen facing downwards.</summary> | ||||||
| FaceDown = 6, | ||||||
| } | ||||||
|
|
||||||
| /// <summary> | ||||||
| /// Input device representing the physical orientation of the device playing the content. | ||||||
| /// </summary> | ||||||
| /// <remarks> | ||||||
| /// The orientation sensor reports the physical orientation of the device (for example, whether it is held in | ||||||
| /// portrait or landscape, or lying face up or face down) as a discrete <see cref="DeviceOrientation"/> value. | ||||||
| /// It provides feature parity with the legacy <c>UnityEngine.Input.deviceOrientation</c> property. | ||||||
| /// | ||||||
| /// Unlike the other motion sensors, the reported value is not compensated for screen orientation; it always | ||||||
| /// describes the physical orientation of the hardware. | ||||||
| /// | ||||||
| /// <example> | ||||||
| /// <code> | ||||||
| /// class MyBehavior : MonoBehaviour | ||||||
| /// { | ||||||
| /// protected void OnEnable() | ||||||
| /// { | ||||||
| /// InputSystem.EnableDevice(DeviceOrientationSensor.current); | ||||||
| /// } | ||||||
| /// | ||||||
| /// protected void OnDisable() | ||||||
| /// { | ||||||
| /// InputSystem.DisableDevice(DeviceOrientationSensor.current); | ||||||
| /// } | ||||||
| /// | ||||||
| /// protected void Update() | ||||||
| /// { | ||||||
| /// var orientation = DeviceOrientationSensor.current.orientation.ReadValue(); | ||||||
| /// //... | ||||||
| /// } | ||||||
| /// } | ||||||
| /// </code> | ||||||
| /// </example> | ||||||
| /// </remarks> | ||||||
| [InputControlLayout(stateType = typeof(DeviceOrientationState), displayName = "Orientation")] | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| public class DeviceOrientationSensor : Sensor | ||||||
| { | ||||||
| /// <summary> | ||||||
| /// The physical orientation of the device. | ||||||
| /// </summary> | ||||||
| /// <value>Control reporting the current <see cref="DeviceOrientation"/>.</value> | ||||||
| public OrientationControl orientation { get; protected set; } | ||||||
|
|
||||||
| /// <summary> | ||||||
| /// The orientation sensor that was last added or had activity last. | ||||||
| /// </summary> | ||||||
| /// <value>Current orientation sensor or <c>null</c>.</value> | ||||||
| public static DeviceOrientationSensor current { get; private set; } | ||||||
|
|
||||||
| /// <inheritdoc /> | ||||||
| public override void MakeCurrent() | ||||||
| { | ||||||
| base.MakeCurrent(); | ||||||
| current = this; | ||||||
| } | ||||||
|
|
||||||
| /// <inheritdoc /> | ||||||
| protected override void OnRemoved() | ||||||
| { | ||||||
| base.OnRemoved(); | ||||||
| if (current == this) | ||||||
| current = null; | ||||||
| } | ||||||
|
|
||||||
| /// <inheritdoc /> | ||||||
| protected override void FinishSetup() | ||||||
| { | ||||||
| orientation = GetChildControl<OrientationControl>("orientation"); | ||||||
| base.FinishSetup(); | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -2053,6 +2053,7 @@ internal void InitializeData() | |||||
| RegisterControlLayout("Touch", typeof(TouchControl)); | ||||||
| RegisterControlLayout("TouchPhase", typeof(TouchPhaseControl)); | ||||||
| RegisterControlLayout("TouchPress", typeof(TouchPressControl)); | ||||||
| RegisterControlLayout("Orientation", typeof(OrientationControl)); | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
|
||||||
| RegisterControlLayout("Gamepad", typeof(Gamepad)); // Devices. | ||||||
| RegisterControlLayout("Joystick", typeof(Joystick)); | ||||||
|
|
@@ -2073,6 +2074,7 @@ internal void InitializeData() | |||||
| RegisterControlLayout("HumiditySensor", typeof(HumiditySensor)); | ||||||
| RegisterControlLayout("AmbientTemperatureSensor", typeof(AmbientTemperatureSensor)); | ||||||
| RegisterControlLayout("StepCounter", typeof(StepCounter)); | ||||||
| RegisterControlLayout("DeviceOrientationSensor", typeof(DeviceOrientationSensor)); | ||||||
| RegisterControlLayout("TrackedDevice", typeof(TrackedDevice)); | ||||||
|
|
||||||
| // Precompiled layouts. | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -111,6 +111,13 @@ public static void Initialize() | |||||
| .WithDeviceClass("AndroidSensor") | ||||||
| .WithCapability("sensorType", AndroidSensorType.HingeAngle)); | ||||||
|
|
||||||
| // Device orientation is not an Android hardware sensor; it is reported as its own device | ||||||
| // class and maps directly to the base DeviceOrientationSensor layout. | ||||||
| InputSystem.RegisterLayoutMatcher("DeviceOrientationSensor", | ||||||
| new InputDeviceMatcher() | ||||||
| .WithInterface(kAndroidInterface) | ||||||
| .WithDeviceClass("Orientation")); | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Assuming it refers to |
||||||
|
|
||||||
| InputSystem.onFindLayoutForDevice += OnFindLayoutForDevice; | ||||||
| } | ||||||
|
|
||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -55,6 +55,10 @@ public static void Initialize() | |||||
| new InputDeviceMatcher() | ||||||
| .WithInterface("iOS") | ||||||
| .WithDeviceClass("LinearAcceleration")); | ||||||
| InputSystem.RegisterLayoutMatcher("DeviceOrientationSensor", | ||||||
| new InputDeviceMatcher() | ||||||
| .WithInterface("iOS") | ||||||
| .WithDeviceClass("Orientation")); | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| #if UNITY_EDITOR || UNITY_IOS | ||||||
| InputSystem.RegisterLayout<iOSStepCounter>(); | ||||||
| // Don't add devices for InputTestRuntime | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not familiar with Unity Remote. Is that something we support for IM parity? It looks like a new feature? It look correct when compared with other implementation though. Testing also been added so I'm fine with it, just curious about the context for it.