diff --git a/Assets/Samples/GamepadMouseCursor/GamepadMouseCursorSample.unity b/Assets/Samples/GamepadMouseCursor/GamepadMouseCursorSample.unity index 78f4d748c0..40c5de21eb 100644 --- a/Assets/Samples/GamepadMouseCursor/GamepadMouseCursorSample.unity +++ b/Assets/Samples/GamepadMouseCursor/GamepadMouseCursorSample.unity @@ -13,7 +13,7 @@ OcclusionCullingSettings: --- !u!104 &2 RenderSettings: m_ObjectHideFlags: 0 - serializedVersion: 9 + serializedVersion: 10 m_Fog: 0 m_FogColor: {r: 0.5, g: 0.5, b: 0.5, a: 1} m_FogMode: 3 @@ -42,8 +42,8 @@ RenderSettings: --- !u!157 &3 LightmapSettings: m_ObjectHideFlags: 0 - serializedVersion: 12 - m_GIWorkflowMode: 1 + serializedVersion: 13 + m_BakeOnSceneLoad: 0 m_GISettings: serializedVersion: 2 m_BounceScale: 1 @@ -66,9 +66,6 @@ LightmapSettings: m_LightmapParameters: {fileID: 0} m_LightmapsBakeMode: 1 m_TextureCompression: 1 - m_FinalGather: 0 - m_FinalGatherFiltering: 1 - m_FinalGatherRayCount: 256 m_ReflectionCompression: 2 m_MixedBakeMode: 2 m_BakeBackend: 1 @@ -977,10 +974,10 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 0cd44c1031e13a943bb63640046fad76, type: 3} m_Name: m_EditorClassIdentifier: - m_UiScaleMode: 0 + m_UiScaleMode: 1 m_ReferencePixelsPerUnit: 100 m_ScaleFactor: 1 - m_ReferenceResolution: {x: 800, y: 600} + m_ReferenceResolution: {x: 1920, y: 1080} m_ScreenMatchMode: 0 m_MatchWidthOrHeight: 0 m_PhysicalUnit: 3 @@ -1100,15 +1097,14 @@ Light: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 832288260} m_Enabled: 1 - serializedVersion: 10 + serializedVersion: 12 m_Type: 1 - m_Shape: 0 m_Color: {r: 1, g: 0.95686275, b: 0.8392157, a: 1} m_Intensity: 1 m_Range: 10 m_SpotAngle: 30 m_InnerSpotAngle: 21.80208 - m_CookieSize: 10 + m_CookieSize2D: {x: 10, y: 10} m_Shadows: m_Type: 2 m_Resolution: -1 @@ -1152,8 +1148,12 @@ Light: m_BoundingSphereOverride: {x: 0, y: 0, z: 0, w: 0} m_UseBoundingSphereOverride: 0 m_UseViewFrustumForShadowCasterCull: 1 + m_ForceVisible: 0 m_ShadowRadius: 0 m_ShadowAngle: 0 + m_LightUnit: 1 + m_LuxAtDistance: 1 + m_EnableSpotReflector: 1 --- !u!4 &832288262 Transform: m_ObjectHideFlags: 0 diff --git a/Packages/com.unity.inputsystem/CHANGELOG.md b/Packages/com.unity.inputsystem/CHANGELOG.md index 7aa64ec2d8..fb7dbba1bb 100644 --- a/Packages/com.unity.inputsystem/CHANGELOG.md +++ b/Packages/com.unity.inputsystem/CHANGELOG.md @@ -20,6 +20,7 @@ however, it has to be formatted properly to pass verification tests. - Fixed the `Auto-Save` toggle button with some extra pixels to align the text in the window better. - Align title font size with toolbar style in `Input Action` window. - Updated Action Properties headers to use colors consistent with GameObject component headers. +- Fixed misaligned Virtual Cursor when changing resolution [ISXB-1119](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-1119) ### Added diff --git a/Packages/com.unity.inputsystem/InputSystem/Plugins/UI/VirtualMouseInput.cs b/Packages/com.unity.inputsystem/InputSystem/Plugins/UI/VirtualMouseInput.cs index cb8aea5535..5a3c39a8f8 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Plugins/UI/VirtualMouseInput.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Plugins/UI/VirtualMouseInput.cs @@ -14,8 +14,6 @@ ////TODO: add support for acceleration -////TODO: automatically scale mouse speed to resolution such that it stays constant regardless of resolution - ////TODO: make it work with PlayerInput such that it will automatically look up actions in the actual PlayerInput instance it is used with (based on the action IDs it has) ////REVIEW: should we default the SW cursor position to the center of the screen? @@ -291,7 +289,10 @@ protected void OnEnable() // Add mouse device. if (m_VirtualMouse == null) + { m_VirtualMouse = (Mouse)InputSystem.AddDevice("VirtualMouse"); + TryFindCanvas(); + } else if (!m_VirtualMouse.added) InputSystem.AddDevice(m_VirtualMouse); @@ -370,6 +371,7 @@ protected void OnDisable() private void TryFindCanvas() { m_Canvas = m_CursorGraphic?.GetComponentInParent(); + m_CanvasScaler = m_CursorGraphic?.GetComponentInParent(); } private void TryEnableHardwareCursor() @@ -421,6 +423,14 @@ private void UpdateMotion() } else { + var resolutionXScale = 1f; + var resolutionYScale = 1f; + if (m_CanvasScaler != null) + { + resolutionXScale = m_Canvas.pixelRect.xMax / m_CanvasScaler.referenceResolution.x; + resolutionYScale = m_Canvas.pixelRect.yMax / m_CanvasScaler.referenceResolution.y; + } + var currentTime = InputState.currentTime; if (Mathf.Approximately(0, m_LastStickValue.x) && Mathf.Approximately(0, m_LastStickValue.y)) { @@ -430,7 +440,7 @@ private void UpdateMotion() // Compute delta. var deltaTime = (float)(currentTime - m_LastTime); - var delta = new Vector2(m_CursorSpeed * stickValue.x * deltaTime, m_CursorSpeed * stickValue.y * deltaTime); + var delta = new Vector2(m_CursorSpeed * resolutionXScale * stickValue.x * deltaTime, m_CursorSpeed * resolutionYScale * stickValue.y * deltaTime); // Update position. var currentPosition = m_VirtualMouse.position.value; @@ -454,7 +464,9 @@ private void UpdateMotion() if (m_CursorTransform != null && (m_CursorMode == CursorMode.SoftwareCursor || (m_CursorMode == CursorMode.HardwareCursorIfAvailable && m_SystemMouse == null))) - m_CursorTransform.anchoredPosition = newPosition; + { + m_CursorTransform.anchoredPosition = m_CanvasScaler == null ? newPosition : new Vector2(newPosition.x / resolutionXScale, newPosition.y / resolutionYScale); + } m_LastStickValue = stickValue; m_LastTime = currentTime; @@ -508,6 +520,7 @@ private void UpdateMotion() [SerializeField] private InputActionProperty m_ScrollWheelAction; private Canvas m_Canvas; // Canvas that gives the motion range for the software cursor. + private CanvasScaler m_CanvasScaler; private Mouse m_VirtualMouse; private Mouse m_SystemMouse; private Action m_AfterInputUpdateDelegate;