Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Packages/com.unity.inputsystem/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ however, it has to be formatted properly to pass verification tests.
- Replaced "Look" rebinding button for "Keyboard" control scheme with a mouse sensitivity slider in `RebindingUISample` to illustrate how to support customizing scaling of mouse deltas and how to reapply the persisted setting between runs.
- Changed: Input System no longer depends the obsolete com.unity.modules.vr package.
- Removed code that had to do with Unity versions older than Unity 2021.3 LTS.
- Removed code that had to do with Unity versions older than Unity 2022.3 LTS.

### Added
- Added an example of how to swap two similar controls to the `RebindingUISample`. This is accessible via a button with two arrows at the right hand-side of the screen. Pressing the button allows swapping the current bindings of the "Move" and "Look" gamepad bindings via the new `RebindActionUI.SwapBinding(RebindActionUI other)` method.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
internal Touchscreen SimulatorTouchscreen;

private bool m_InputSystemEnabled;
private bool m_Quitting;
private List<InputDevice> m_DisabledDevices;

public override string title => "Input System";
Expand All @@ -22,9 +21,6 @@
m_InputSystemEnabled = EditorPlayerSettingHelpers.newSystemBackendsEnabled;
if (m_InputSystemEnabled)
{
// Monitor whether the editor is quitting to avoid risking unsafe EnableDevice while quitting
UnityEditor.EditorApplication.quitting += OnQuitting;

m_DisabledDevices = new List<InputDevice>();

// deviceSimulator is never null when the plugin is instantiated by a simulator window, but it can be null during unit tests
Expand Down Expand Up @@ -99,27 +95,15 @@
deviceSimulator.touchScreenInput -= OnTouchEvent;
InputSystem.onDeviceChange -= OnDeviceChange;

UnityEditor.EditorApplication.quitting -= OnQuitting;

if (SimulatorTouchscreen != null)
InputSystem.RemoveDevice(SimulatorTouchscreen);
foreach (var device in m_DisabledDevices)
{
// Note that m_Quitting is used here to mitigate the problem reported in issue tracker:
// https://issuetracker.unity3d.com/product/unity/issues/guid/UUM-10774.
// Enabling a device will call into IOCTL of backend which will (may) be destroyed prior
// to this callback on Unity version <= 2022.2. This is not a fix for the actual problem
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This change is a rollback of 7d53de2, for which we hopefully have a native-side solution in 2022 LTS now

Copy link
Collaborator

Choose a reason for hiding this comment

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

How is that solved now?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@ekcoh would know better

// of shutdown order but a package fix to mitigate this problem.
if (device.added && !m_Quitting)
if (device.added)

Check warning on line 102 in Packages/com.unity.inputsystem/InputSystem/Editor/DeviceSimulator/InputSystemPlugin.cs

View check run for this annotation

Codecov GitHub.com / codecov/patch

Packages/com.unity.inputsystem/InputSystem/Editor/DeviceSimulator/InputSystemPlugin.cs#L102

Added line #L102 was not covered by tests
InputSystem.EnableDevice(device);
}
}
}

private void OnQuitting()
{
m_Quitting = true;
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,8 @@ private static void CheckForExtension()
BuildTarget.tvOS,
BuildTarget.LinuxHeadlessSimulation,
BuildTarget.EmbeddedLinux,
#if UNITY_2022_1_OR_NEWER
BuildTarget.QNX,
#endif
#if UNITY_2022_3_OR_NEWER
BuildTarget.VisionOS,
#endif
(BuildTarget)49,
BuildTarget.NoTarget
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,7 @@ public override string ToString()
stringBuilder.AppendLine("azimuthAngle: " + azimuthAngle);
stringBuilder.AppendLine("altitudeAngle: " + altitudeAngle);
stringBuilder.AppendLine("twist: " + twist);
#if UNITY_2022_3_OR_NEWER
stringBuilder.AppendLine("displayIndex: " + displayIndex);
#endif
return stringBuilder.ToString();
}

Expand Down Expand Up @@ -138,27 +136,21 @@ internal void ReadDeviceState()
azimuthAngle = (pen.tilt.value.x + 1) * Mathf.PI / 2;
altitudeAngle = (pen.tilt.value.y + 1) * Mathf.PI / 2;
twist = pen.twist.value * Mathf.PI * 2;
#if UNITY_2022_3_OR_NEWER
displayIndex = pen.displayIndex.ReadValue();
#endif
}
else if (control.parent is TouchControl touchControl)
{
uiToolkitPointerId = GetTouchPointerId(touchControl);
pressure = touchControl.pressure.magnitude;
radius = touchControl.radius.value;
#if UNITY_2022_3_OR_NEWER
displayIndex = touchControl.displayIndex.ReadValue();
#endif
}
else if (control.parent is Touchscreen touchscreen)
{
uiToolkitPointerId = GetTouchPointerId(touchscreen.primaryTouch);
pressure = touchscreen.pressure.magnitude;
radius = touchscreen.radius.value;
#if UNITY_2022_3_OR_NEWER
displayIndex = touchscreen.displayIndex.ReadValue();
#endif
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -579,9 +579,8 @@ private void ProcessPointerMovement(ExtendedPointerEventData eventData, GameObje
if (!sendPointerHoverToParent && current == pointerParent)
break;

#if UNITY_2021_3_OR_NEWER
eventData.fullyExited = current != commonRoot && eventData.pointerEnter != currentPointerTarget;
#endif

ExecuteEvents.Execute(current.gameObject, eventData, ExecuteEvents.pointerExitHandler);
eventData.hovered.Remove(current.gameObject);

Expand All @@ -605,12 +604,10 @@ private void ProcessPointerMovement(ExtendedPointerEventData eventData, GameObje
Transform current = currentPointerTarget.transform;
while (current != null && !PointerShouldIgnoreTransform(current))
{
#if UNITY_2021_3_OR_NEWER
eventData.reentered = current == commonRoot && current != oldPointerEnter;
// if we are sending the event to parent, they are already in hover mode at that point. No need to bubble up the event.
if (sendPointerHoverToParent && eventData.reentered)
break;
#endif

ExecuteEvents.Execute(current.gameObject, eventData, ExecuteEvents.pointerEnterHandler);
if (wasMoved)
Expand Down Expand Up @@ -1926,9 +1923,7 @@ private int GetPointerStateIndexFor(InputControl control, bool createIfNotExists
eventData.pointerType = pointerType;
eventData.pointerId = pointerId;
eventData.touchId = touchId;
#if UNITY_2022_3_OR_NEWER
eventData.displayIndex = displayIndex;
#endif

// Make sure these don't linger around when we switch to a different kind of pointer.
eventData.trackedDeviceOrientation = default;
Expand Down Expand Up @@ -2031,9 +2026,7 @@ private int AllocatePointer(int pointerId, int displayIndex, int touchId, UIPoin
eventData = new ExtendedPointerEventData(eventSystem);

eventData.pointerId = pointerId;
#if UNITY_2022_3_OR_NEWER
eventData.displayIndex = displayIndex;
#endif
eventData.touchId = touchId;
eventData.pointerType = pointerType;
eventData.control = control;
Expand Down Expand Up @@ -2164,9 +2157,7 @@ private void OnPointCallback(InputAction.CallbackContext context)

ref var state = ref GetPointerStateForIndex(index);
state.screenPosition = context.ReadValue<Vector2>();
#if UNITY_2022_3_OR_NEWER
state.eventData.displayIndex = GetDisplayIndexFor(context.control);
#endif
}

// NOTE: In the click events, we specifically react to the Canceled phase to make sure we do NOT perform
Expand Down Expand Up @@ -2195,9 +2186,7 @@ private void OnLeftClickCallback(InputAction.CallbackContext context)
state.changedThisFrame = true;
if (IgnoreNextClick(ref context, wasPressed))
state.leftButton.ignoreNextClick = true;
#if UNITY_2022_3_OR_NEWER
state.eventData.displayIndex = GetDisplayIndexFor(context.control);
#endif
}

private void OnRightClickCallback(InputAction.CallbackContext context)
Expand All @@ -2212,9 +2201,7 @@ private void OnRightClickCallback(InputAction.CallbackContext context)
state.changedThisFrame = true;
if (IgnoreNextClick(ref context, wasPressed))
state.rightButton.ignoreNextClick = true;
#if UNITY_2022_3_OR_NEWER
state.eventData.displayIndex = GetDisplayIndexFor(context.control);
#endif
}

private void OnMiddleClickCallback(InputAction.CallbackContext context)
Expand All @@ -2229,9 +2216,7 @@ private void OnMiddleClickCallback(InputAction.CallbackContext context)
state.changedThisFrame = true;
if (IgnoreNextClick(ref context, wasPressed))
state.middleButton.ignoreNextClick = true;
#if UNITY_2022_3_OR_NEWER
state.eventData.displayIndex = GetDisplayIndexFor(context.control);
#endif
}

private bool CheckForRemovedDevice(ref InputAction.CallbackContext context)
Expand Down Expand Up @@ -2261,9 +2246,7 @@ private void OnScrollCallback(InputAction.CallbackContext context)
// ISXB-704: convert input value to BaseInputModule convention.
state.scrollDelta = (scrollDelta / InputSystem.scrollWheelDeltaPerTick) * scrollDeltaPerTick;

#if UNITY_2022_3_OR_NEWER
state.eventData.displayIndex = GetDisplayIndexFor(context.control);
#endif
}

private void OnMoveCallback(InputAction.CallbackContext context)
Expand All @@ -2286,9 +2269,7 @@ private void OnTrackedDeviceOrientationCallback(InputAction.CallbackContext cont

ref var state = ref GetPointerStateForIndex(index);
state.worldOrientation = context.ReadValue<Quaternion>();
#if UNITY_2022_3_OR_NEWER
state.eventData.displayIndex = GetDisplayIndexFor(context.control);
#endif
}

private void OnTrackedDevicePositionCallback(InputAction.CallbackContext context)
Expand All @@ -2299,9 +2280,7 @@ private void OnTrackedDevicePositionCallback(InputAction.CallbackContext context

ref var state = ref GetPointerStateForIndex(index);
state.worldPosition = context.ReadValue<Vector3>();
#if UNITY_2022_3_OR_NEWER
state.eventData.displayIndex = GetDisplayIndexFor(context.control);
#endif
}

private void OnControlsChanged(object obj)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,6 @@ public enum Button
RightThumbstickPress = 15,
}

// IL2CPP on 2021 doesn't respect the FieldOffsets - as such, we need some padding fields
#if UNITY_2021 && ENABLE_IL2CPP
[FieldOffset(0)]
private uint padding;
#endif

[InputControl(name = "buttonSouth", bit = (uint)Button.A, displayName = "A")]
[InputControl(name = "buttonEast", bit = (uint)Button.B, displayName = "B")]
[InputControl(name = "buttonWest", bit = (uint)Button.X, displayName = "X")]
Expand All @@ -154,20 +148,9 @@ public enum Button
[InputControl(name = "leftTrigger", format = "BYTE")]
[FieldOffset(6)] public byte leftTrigger;

#if UNITY_2021 && ENABLE_IL2CPP
[FieldOffset(7)]
private byte triggerPadding;
#endif

[InputControl(name = "rightTrigger", format = "BYTE")]
[FieldOffset(8)] public byte rightTrigger;

#if UNITY_2021 && ENABLE_IL2CPP
[FieldOffset(9)]
private byte triggerPadding2;
#endif


[InputControl(name = "leftStick", layout = "Stick", format = "VC2S")]
[InputControl(name = "leftStick/x", offset = 0, format = "SHRT", parameters = "")]
[InputControl(name = "leftStick/left", offset = 0, format = "SHRT", parameters = "")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -587,26 +587,26 @@ protected virtual void SetLocalTransform(Vector3 newPosition, Quaternion newRota
var positionValid = m_IgnoreTrackingState || (m_CurrentTrackingState & TrackingStates.Position) != 0;
var rotationValid = m_IgnoreTrackingState || (m_CurrentTrackingState & TrackingStates.Rotation) != 0;

#if HAS_SET_LOCAL_POSITION_AND_ROTATION
if (m_TrackingType == TrackingType.RotationAndPosition && rotationValid && positionValid)
switch (m_TrackingType)
{
transform.SetLocalPositionAndRotation(newPosition, newRotation);
return;
}
#endif

if (rotationValid &&
(m_TrackingType == TrackingType.RotationAndPosition ||
m_TrackingType == TrackingType.RotationOnly))
{
transform.localRotation = newRotation;
}

if (positionValid &&
(m_TrackingType == TrackingType.RotationAndPosition ||
m_TrackingType == TrackingType.PositionOnly))
{
transform.localPosition = newPosition;
case TrackingType.RotationAndPosition:
if (rotationValid && positionValid)
transform.SetLocalPositionAndRotation(newPosition, newRotation);
else if (rotationValid)
transform.localRotation = newRotation;
else if (positionValid)
transform.localPosition = newPosition;
break;

case TrackingType.PositionOnly:
if (positionValid)
transform.localPosition = newPosition;
break;

case TrackingType.RotationOnly:
if (rotationValid)
transform.localRotation = newRotation;
break;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This code is still logically the same as on the left, I just rephrased it to be more explicit in 2022 LTS+

}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,21 +52,6 @@
"expression": "1.0.0",
"define": "UNITY_INPUT_SYSTEM_ENABLE_UI"
},
{
"name": "Unity",
"expression": "[2021.3.11,2022.1)",
"define": "HAS_SET_LOCAL_POSITION_AND_ROTATION"
},
{
"name": "Unity",
"expression": "[2022.1.19,2022.2)",
"define": "HAS_SET_LOCAL_POSITION_AND_ROTATION"
},
{
"name": "Unity",
"expression": "2022.2",
"define": "HAS_SET_LOCAL_POSITION_AND_ROTATION"
},
{
"name": "Unity",
"expression": "2022.3",
Expand Down