Firstborn/Library/PackageCache/com.unity.inputsystem@1.5.1/Samples~/GamepadMouseCursor
Schaken-Mods 9092858a58 updated to the latest editor
I updated everything to the latest Unity Editor. Also realized I had the wrong shaders on my hairs, those are fixed and the hairs look MUCH better!
2023-05-07 17:43:11 -05:00
..
.sample.json updated to the latest editor 2023-05-07 17:43:11 -05:00
crosshair.png updated to the latest editor 2023-05-07 17:43:11 -05:00
crosshair.png.meta updated to the latest editor 2023-05-07 17:43:11 -05:00
GamepadMouseCursorSample.unity updated to the latest editor 2023-05-07 17:43:11 -05:00
GamepadMouseCursorSample.unity.meta updated to the latest editor 2023-05-07 17:43:11 -05:00
GamepadMouseCursorUIActions.inputactions updated to the latest editor 2023-05-07 17:43:11 -05:00
GamepadMouseCursorUIActions.inputactions.meta updated to the latest editor 2023-05-07 17:43:11 -05:00
README.md updated to the latest editor 2023-05-07 17:43:11 -05:00
README.md.meta updated to the latest editor 2023-05-07 17:43:11 -05:00
VirtualMouseInput.png updated to the latest editor 2023-05-07 17:43:11 -05:00
VirtualMouseInput.png.meta updated to the latest editor 2023-05-07 17:43:11 -05:00

Rather than adapting UIs for gamepad navigation/use, an oft-used alternative is to instead keep having UIs operated by pointer input but to drive the pointer from gamepad input.

This sample demonstrates how to set this up with the input system.

Virtual Mouse Input Component

  1. It uses a custom actions file 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.

Licenses

The cursor used in the example is from game-icons.net and made by Delapuite and released under the CC BY 3.0 license. It is used without modifications.