Author Topic: NGUI touch support on Wii U  (Read 5298 times)

Teku Studios

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 13
    • View Profile
    • Teku Studios
NGUI touch support on Wii U
« on: September 17, 2013, 06:52:38 AM »
Hi there!

So, we are developing a game on Unity and we are now porting it to Wii U. Since its gamepad has touch control on its screen, we want to take advantage of NGUI's tactile option, but we are experiencing trouble when dealing with it. We disable the "Use mouse" option and enable the "Use touch" and "Allow Multitouch" options. Want we want to do is to simply touch on each button to activate it, but everything messes up and it does not work properly.

At this moment, we have an inventory for which we create several buttons at runtime (each time we open it) from prefabs (each button is a prefab), then we set the StartSelected property on the UIButtonKeys script to true only for the selected button, and UICamera.SelectedObject points to that one.

Then, when we touch a button through the touch screen it continues being pressed (we don't have the "Sticky Press" property actived), and the regular analog controls cease to work, we want to have them actived no matter if the player uses touch or axis input. But also, the buttons do not always work when touched, since it takes us a few tries to make them work.

Also (only happening on Wi U GamePad's touchscreen) the controls are inverted. Down goes up, Up goes down and to select a button we need to touch the opposite position on the screen. And one last thing is that, if we go to the UI Root camera and assign Submit Key 1 as Joystick 2 Button 'x', it breaks our controls if that key is also assigned to another use (e.g. jumping).

Is there anything we can tweak on NGUI's code to fit our needs? Maybe on the buttons' code to add a "OnTouch" function, or similar. We saw at the docs that there is a UICamera.MouseOrTouch class, but it would be great if you could give us some tips or guidelines about how to handle this problems.

Thanks a lot.
« Last Edit: September 17, 2013, 01:07:27 PM by Teku Studios »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: NGUI touch support on Wii U
« Reply #1 on: September 17, 2013, 02:52:41 PM »
You need to verify what kind of messages get sent out. If the button remains pressed after touching it, then the touch never ends. Debug the UICamera, see when the touches end. I don't have a WiiU to test any of this on.

Teku Studios

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 13
    • View Profile
    • Teku Studios
Re: NGUI touch support on Wii U
« Reply #2 on: September 18, 2013, 03:41:59 AM »
O)k, we'll do that, we'll keep you up to date.

optimisticmonkey

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 2
  • Posts: 15
    • View Profile
Re: NGUI touch support on Wii U
« Reply #3 on: February 18, 2015, 09:32:52 PM »
Having same issue - did you ever resolve it?


BehindTheStone

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 135
    • View Profile
Re: NGUI touch support on Wii U
« Reply #4 on: February 19, 2015, 04:03:41 AM »
Just wanted to emphasize that the WiiU Tablet-Controller is not capable of multi-touch!

ceng

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 3
    • View Profile
Re: NGUI touch support on Wii U
« Reply #5 on: April 13, 2015, 03:11:36 PM »
Bump for an update regarding the inverted vertical touch/drag behavior observed on the WiiU gamepad. In the meantime, I will be digging into the NGUI source to try to find a solution. If it matters, I am running Unity 4.3.7f1 and NGUI 3.6.1.

Thanks!
-Chris

ceng

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 3
    • View Profile
Re: NGUI touch support on Wii U
« Reply #6 on: April 14, 2015, 02:23:56 PM »
After contacting Unity, the inverted vertical touch input is due to a mismatch between the vertical coordinate systems of UnityEngine.Input.GetTouch and the WiiU GamePad touchscreen. The GamePad places (0,0) at the left-bottom corner of the screen, whereas GetTouch places (0,0) at the left-top. I have solved my use case by modifying UICamera.ProcessTouches as follows:

  1. // Note: this is NGUI 3.6.1.
  2.  
  3. public void ProcessTouches( )
  4. {
  5.         // ...omitted code...
  6.  
  7.         Touch touch = Input.GetTouch( i );
  8.  
  9.         // ...omitted code...
  10.  
  11.         #if UNITY_WIIU && !UNITY_EDITOR
  12.                 Vector2 touchPosFix = new Vector2( touch.position.x, cachedCamera.pixelHeight - touch.position.y );
  13.                 currentTouch.delta  = pressed ? Vector2.zero : touchPosFix - currentTouch.pos;
  14.                 currentTouch.pos    = touchPosFix;
  15.         #else // !UNITY_WIIU || UNITY_EDITOR
  16.                 currentTouch.delta = pressed ? Vector2.zero : touch.position - currentTouch.pos;
  17.                 currentTouch.pos   = touch.position;
  18.         #endif // !UNITY_WIIU || UNITY_EDITOR
  19.  
  20.         // ...omitted code...
  21. }
  22.  

I hope this helps anyone else who has encountered this problem!
-Chris