diff --git a/Assets/Samples/GamepadMouseCursor/GamepadMouseCursorUIActions.inputactions b/Assets/Samples/GamepadMouseCursor/GamepadMouseCursorUIActions.inputactions index fcec675666..64d4e7c143 100644 --- a/Assets/Samples/GamepadMouseCursor/GamepadMouseCursorUIActions.inputactions +++ b/Assets/Samples/GamepadMouseCursor/GamepadMouseCursorUIActions.inputactions @@ -34,7 +34,7 @@ { "name": "", "id": "39af39e2-c75c-421e-84bf-1e4ff9793ab4", - "path": "/position", + "path": "/position", "interactions": "", "processors": "", "groups": "", @@ -45,7 +45,7 @@ { "name": "", "id": "f9d5a98e-68a3-44c8-a096-a1a30237ca81", - "path": "/leftButton", + "path": "/leftButton", "interactions": "", "processors": "", "groups": "", @@ -56,7 +56,7 @@ { "name": "", "id": "7ffd960c-11ef-4fc0-b91b-4cbd02eba1b8", - "path": "/scroll", + "path": "/scroll", "interactions": "", "processors": "", "groups": "", diff --git a/Assets/Samples/GamepadMouseCursor/README.md b/Assets/Samples/GamepadMouseCursor/README.md index 1b9a255f1e..54ddcca2fb 100644 --- a/Assets/Samples/GamepadMouseCursor/README.md +++ b/Assets/Samples/GamepadMouseCursor/README.md @@ -7,10 +7,11 @@ This sample demonstrates how to set this up with the input system. 1) It uses a custom [actions file](./GamepadMouseCursorUIActions.inputactions) for feeding input to the UI as the default actions are set up for gamepad navigation – something we don't want here as it would conflict with gamepad input being used for virtual cursor navigation. 2) Note how `InputSystemUIInputModule` on the `EventSystem` GameObject is set up to reference actions from that file. 3) The key component to take a look at is `VirtualMouseInput` on `Canvas >> Cursor`. The component is set up to receive input from the gamepad and translates it into motion on the `RectTransform` it is given. When going into play mode, you should also see a `Virtual Mouse` being added to the devices by the component. -4) Note how the anchor position on the `RectTransform` is set to bottom left. This way the coordinate system responds to how mouse screen space operates. -5) Note how `Cursor` is the last child of `Canvas` so that it draws on top of everything else. -6) Note that `Raycast Target` on the `Image` component of the cursor is turned off to avoid raycasts from the mouse cursor hitting the cursor itself. -7) Note that `Cursor Mode` on the `VirtualMouseInput` component is set to `Hardware Cursor If Available`. This will cause the component to look for a system mouse. If present, the system mouse is disabled and the system mouse cursor is warped to the virtual mouse position using `Mouse.WarpCursorPosition`. If no system mouse is present, `Cursor Graphic` will be used as a software mouse cursor. +4) Note how `Cursor` is the last child of `Canvas` so that it draws on top of everything else. +5) Note that `Raycast Target` on the `Image` component of the cursor is turned off to avoid raycasts from the mouse cursor hitting the cursor itself. +6) Note that `Cursor Mode` on the `VirtualMouseInput` component is set to `Hardware Cursor If Available`. This will cause the component to look for a system mouse. If present, the system mouse is disabled and the system mouse cursor is warped to the virtual mouse position using `Mouse.WarpCursorPosition`. If no system mouse is present, `Cursor Graphic` will be used as a software mouse cursor. + +>NOTE: The `VirtualMouseInput` component currently does not work correctly with world-space canvases. # Licenses diff --git a/Assets/Samples/GamepadMouseCursor/VirtualMouseInput.cs b/Assets/Samples/GamepadMouseCursor/VirtualMouseInput.cs index 3eabd5b980..1d52a931a1 100644 --- a/Assets/Samples/GamepadMouseCursor/VirtualMouseInput.cs +++ b/Assets/Samples/GamepadMouseCursor/VirtualMouseInput.cs @@ -4,6 +4,8 @@ ////TODO: respect cursor lock mode +////TODO: find a way to automatically turn the gamepad cursor on/off based on gamepad use + ////TODO: investigate how driving the HW cursor behaves when FPS drops low //// (also, maybe we can add support where we turn the gamepad mouse on and off automatically based on whether the system mouse is used) @@ -13,6 +15,8 @@ ////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) +////FIXME: make this work with world-space canvases + ////REVIEW: should we default the SW cursor position to the center of the screen? ////REVIEW: consider this for inclusion directly in the input system @@ -74,9 +78,10 @@ public float cursorSpeed /// that is made to correspond to the position of . If this is set to and there is a native device present, /// the component will take over that mouse device and disable it (so as for it to not also generate position - /// updates). It will then use to move the system mouse cursor to - /// correspond to the position of the . In this case, - /// will be disabled and will not be updated. + /// updates) except when this is explicitly disabled via . It will then use + /// to move the system mouse cursor to correspond to the position of the + /// . In this case, will be disabled and + /// will not be updated. /// /// Whether the system mouse cursor (if present) should be made to correspond with the virtual mouse position. /// @@ -96,7 +101,8 @@ public CursorMode cursorMode // If we're turning it off, make sure we re-enable the system mouse. if (m_CursorMode == CursorMode.HardwareCursorIfAvailable && m_SystemMouse != null) { - InputSystem.EnableDevice(m_SystemMouse); + if (m_DisableSystemMouse) + InputSystem.EnableDevice(m_SystemMouse); m_SystemMouse = null; } @@ -153,11 +159,51 @@ public float scrollSpeed /// public Mouse virtualMouse => m_VirtualMouse; + /// + /// If is set to , whether to + /// disable the system mouse, if present. This is on by default. + /// + /// If true, the system mouse will be disabled if present and while the VirtualMouseInput component is active. + /// + /// If the component drives the system mouse cursor rather than using a software cursor, the system mouse cursor position will + /// get warped around using . This, however, has the side-effect of generating input + /// on the system device. In other words, mouse motion from the gamepad will come in through both + /// the VirtualMouse created for the gamepad and the added by the system (with a one frame lag for + /// the latter). + /// + /// To avoid this, the system mouse will by default get disabled while the VirtualMouseInput component is enabled. Thus, + /// the system will not receive input while the VirtualMouseInput component is enabled. The idea here + /// is that the application should determine when the gamepad is used and only turn on the gamepad cursor while this is + /// the case. One possible approach is to set up a control scheme for gamepads and enable the gamepad mouse cursor only + /// while the gamepad scheme is active. + /// + /// However, by setting this property to false, the disabling of the system device can be suppressed. + /// This means the system mouse will stay fully functional. You will, however, see concurrent input on both the VirtualMouse + /// and the system mouse. This may, for example, interfere with automatic control scheme switching (which is why the disabling + /// is on by default). + /// + public bool disableSystemMouse + { + get => m_DisableSystemMouse; + set + { + if (value == m_DisableSystemMouse) + return; + m_DisableSystemMouse = value; + + if (m_SystemMouse != null) + { + if (value) + InputSystem.DisableDevice(m_SystemMouse); + else + InputSystem.EnableDevice(m_SystemMouse); + } + } + } + /// /// The Vector2 stick input that drives the mouse cursor, i.e. on - /// and the anchoredPosition - /// on (if set). + /// and the position on (if set). /// /// Stick input that drives cursor position. /// @@ -290,7 +336,7 @@ protected void OnEnable() // Set initial cursor position. if (m_CursorTransform != null) { - var position = m_CursorTransform.anchoredPosition; + var position = m_CursorTransform.position; InputState.Change(m_VirtualMouse.position, position); m_SystemMouse?.WarpCursorPosition(position); } @@ -384,7 +430,8 @@ private void TryEnableHardwareCursor() return; } - InputSystem.DisableDevice(m_SystemMouse); + if (m_DisableSystemMouse) + InputSystem.DisableDevice(m_SystemMouse); // Sync position. if (m_VirtualMouse != null) @@ -446,7 +493,7 @@ private void UpdateMotion() if (m_CursorTransform != null && (m_CursorMode == CursorMode.SoftwareCursor || (m_CursorMode == CursorMode.HardwareCursorIfAvailable && m_SystemMouse == null))) - m_CursorTransform.anchoredPosition = newPosition; + m_CursorTransform.position = newPosition; m_LastStickValue = stickValue; m_LastTime = currentTime; @@ -468,8 +515,16 @@ private void UpdateMotion() } [Header("Cursor")] + [Tooltip("Whether to use the system mouse cursor, if available. Or whether to use a pure software cursor only.")] [SerializeField] private CursorMode m_CursorMode; + [Tooltip("With 'Cursor Mode' set to 'Hardware Cursor If Available', whether to disable the system mouse. The cursor warping that is used " + + "to drive the HW cursor will generate input on the mouse device which mirrors the input on the virtual mouse. By enabling this flag, " + + "this input can be suppressed by disabling the system mouse altogether. Note that this will make *no* input from the system mouse come " + + "through while the VirtualMouseInput component is active.")] + [SerializeField] private bool m_DisableSystemMouse = true; + [Tooltip("The UI graphic that represents the software cursor.")] [SerializeField] private Graphic m_CursorGraphic; + [Tooltip("The UI transform for the UI object that represents the software cursor.")] [SerializeField] private RectTransform m_CursorTransform; [Header("Motion")] diff --git a/Packages/com.unity.inputsystem/CHANGELOG.md b/Packages/com.unity.inputsystem/CHANGELOG.md index acede27819..8f6148f1f5 100755 --- a/Packages/com.unity.inputsystem/CHANGELOG.md +++ b/Packages/com.unity.inputsystem/CHANGELOG.md @@ -11,7 +11,8 @@ however, it has to be formatted properly to pass verification tests. ### Fixed -- `VirtualMouseInput` not moving the software cursor when set to `HardwareCursorIsAvailable` but not having a hardware cursor () +- `VirtualMouseInput` not moving the software cursor when set to `HardwareCursorIsAvailable` but not having a hardware cursor. +- `VirtualMouseInput` not working correctly with `CanvasScaler` settings other than `ConstantPixelSize`. Fix contributed by [ad-walker](https://github.com/ad-walker) in [#1078](https://github.com/Unity-Technologies/InputSystem/pull/1078). - Can now override built-in Android gamepad layouts. Previously, the input system would always choose its default defaults even after registering more specific layouts using `InputSystem.RegisterLayout`. - `InputControlPath.TryGetControlLayout` no longer throws `NotImplementedException` for `/scroll/x` and similar paths where the layout is modifying a control it inherited from its base layout ([thread](https://forum.unity.com/threads/notimplementedexception-when-using-inputcontrolpath-trygetcontrollayout-on-mouse-controls.847129/)). - Fixed compilation errors when disabling built-in VR and XR packages. ([case 1214248](https://issuetracker.unity3d.com/issues/enable-input-system-symbol-is-not-being-updated-when-the-input-system-is-changed-in-player-settings/)). @@ -40,6 +41,10 @@ however, it has to be formatted properly to pass verification tests. - `InputDevice.all` has been deprecated due to the confusion it creates with other getters like `Gamepad.all`. Use `InputSystem.devices` instead ([case 1231216](https://issuetracker.unity3d.com/issues/joystick-dot-all-lists-more-than-just-joysticks)). * In the same vein, we added a new `Joystick.all` getter that works the same as `Gamepad.all`. +### Added + +- Added an explicit `Disable System Mouse` setting to `VirtualMouseInput` to allow toggling the default behavior off which makes the component turn off the system mouse while it is enabled (so as to suppress the system mouse doubling the input activity on the VirtualMouse). + ## [1.0.0-preview.6] - 2020-03-06 ### Changed diff --git a/Packages/com.unity.inputsystem/InputSystem/Devices/Remote/RemoteInputPlayerConnection.cs b/Packages/com.unity.inputsystem/InputSystem/Devices/Remote/RemoteInputPlayerConnection.cs index 3a54743345..5e4dab19d4 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Devices/Remote/RemoteInputPlayerConnection.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Devices/Remote/RemoteInputPlayerConnection.cs @@ -31,7 +31,7 @@ internal class RemoteInputPlayerConnection : { public static readonly Guid kNewDeviceMsg = new Guid("fcd9651ded40425995dfa6aeb78f1f1c"); public static readonly Guid kNewLayoutMsg = new Guid("fccfec2b7369466d88502a9dd38505f4"); - public static readonly Guid kNewEventsMsg = new Guid("34d9b47f923142ff847c0d1f8b0554d9"); + public static readonly Guid kNewEventsMsg = new Guid("53546641df1347bc8aa315278a603586"); public static readonly Guid kRemoveDeviceMsg = new Guid("e5e299b2d9e44255b8990bb71af8922d"); public static readonly Guid kChangeUsagesMsg = new Guid("b9fe706dfc854d7ca109a5e38d7db730"); public static readonly Guid kStartSendingMsg = new Guid("0d58e99045904672b3ef34b8797d23cb");