GamePad Touch Screen Input

GamePad Touch Screen Input

There are three ways to get touch screen input.

  • As mouse input
  • As touch input
  • Using the Wii U API

The y-axis is inverted for the first two, so the coordinates for the top left corner of the touch screen are as follows:

  • As mouse input: (0, 480)
  • As touch input: (0, 480)
  • Using the Wii U API: (0, 0)

As Mouse Input

The easiest way is to treat touch screen input as mouse input, but the Wii Remote on channel 0 (the first player) also uses Input.GetMouseButton(0) (for the A button) and Input.mousePosition (for the pointer). However, Input.mousePosition returns the coordinates for the TV, not the GamePad, and in a different scale. You can disable the Wii Remote pointer with UnityEngine.WiiU.Remote.DisableDPD(). This will stop both Input.GetMouseButton(0) and Input.mousePosition from responding to Wii Remote input. Another option is to use one of the other methods to get touch input.

1
2
3
4
5
6
Vector3 touchPosition;
if (Input.GetMouseButton(0)) {
    // A touch was registered
    // Get the location of the touch
    touchPosition = Input.mousePosition;
}

As Touch Input

This is very similar to mouse input. The Wii U only supports one touch at a time, so you only ever need to check Input.touches[0].

1
2
3
4
5
6
Vector2 touchPosition;
if (Input.touchCount > 0){
    // A touch was registered
    // Get the location of the touch
    touchPosition = Input.touches[0].position;
}

Using the Wii U API

This method is slightly more complicated, but is easy to use if you are already using the Wii U API for the GamePad buttons, joysticks or sensors. After creating a GamePad object, you must get a new WiiU.GamePadState every time you want to read input.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
using UnityEngine;
using WiiU = UnityEngine.WiiU;
public class gamePadInputTest : MonoBehaviour
{
    WiiU.GamePad gamePad;
    void Start()
    {
        // Create a GamePad object
        gamePad = WiiU.GamePad.access;
    }
    void Update()
    {
        // Get the new state of the GamePad
        WiiU.GamePadState gamePadState = gamePad.state;
        if (gamePadState.gamePadErr == WiiU.GamePadError.None)
        {
             // Get the touch position
            Vector2 touchPosition;
            touchPosition.x = gamePadState.touch.x;
            touchPosition.y = gamePadState.touch.y;
        }
    }
}

 

 

 


CONFIDENTIAL