Author Topic: How can I test touch input via Unity Remote?  (Read 13010 times)

calbar

  • Guest
How can I test touch input via Unity Remote?
« on: November 10, 2013, 05:13:24 PM »
I'm aware that Unity Remote sends both mouse and touch events as mentioned here and here, but I need the ability to debug touch events in the editor which means Unity Remote is a necessity.

What's happening is with Mouse and Touch Event Sources enabled on UICamera, UICamera.currentTouch.pos returns the average position of all active touch points and the OnDrag delta is the same for all OnDrag calls throughout a frame. That means fingers dragging in opposite directions report the same delta.

Unchecking Mouse as an Event Source kills touch functionality altogether, where I had hoped it would just ignore the mouse events sent by Unity Remote and allow touch events to work unhindered.

Digging around in UICamera I found this block of code:
  1. if (useTouch)
  2. {
  3.         if (mIsEditor)
  4.         {
  5.                 // Only process mouse events while in the editor
  6.                 ProcessMouse();
  7.         }
  8.         else
  9.         {
  10.                 // Process touch events first
  11.                 ProcessTouches();
  12.  
  13.                 // If we want to process mouse events, only do so if there are no active touch events,
  14.                 // otherwise there is going to be event duplication as Unity treats touch events as mouse events.
  15.                 if (useMouse && Input.touchCount == 0)
  16.                         ProcessMouse();
  17.         }
  18. }
  19.  

That looks like why disabling Mouse as an Event Source also kills touch functionality when using Unity Remote, which of course connects to the editor.

So how would you recommend fixing this? My guess involves removing the mIsEditor block, but of course I'm wary about editing NGUI source.

wom

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 34
    • View Profile
Re: How can I test touch input via Unity Remote?
« Reply #1 on: November 11, 2013, 03:22:48 AM »
Are you using 3.0.5?

Have a look at this topic: http://www.tasharen.com/forum/index.php?topic=6576.0

The work-around I posted in there might work for you (toggling the checkboxes during playtime).
It'd be annoying to have to do it each run though - maybe think about regressing to previous working version of 3.0.x if you can.

EDIT:
Or, you could try this hack I just came up with - it works for my personal use-case only (single touches, no dragging or anything fancy).
Attach the script to your UICamera and then drag your UICamera into the uiCamera field.
It works for me in my very limited testing of my own very limited usage of NGUI - no idea what it'll do for you.

  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class NguiTouchFix : MonoBehaviour {
  5.  
  6.   public UICamera uiCamera;
  7.  
  8.   void OnEnable() {
  9.     UICamera.onCustomInput = DoTheFunkyChicken;
  10.   }
  11.  
  12.   /// <summary tone="sarcastic">
  13.   /// A static delegate member accessing instance fields -
  14.   /// what could possibly go wrong?
  15.   /// </summary>
  16.   void DoTheFunkyChicken() {
  17.     uiCamera.ProcessTouches();
  18.   }
  19. }
  20.  
« Last Edit: November 11, 2013, 04:58:58 AM by wom »

calbar

  • Guest
Re: How can I test touch input via Unity Remote?
« Reply #2 on: November 11, 2013, 12:44:30 PM »
Hey, thanks wom - your thread was actually one of the two I linked up top. I am using 3.0.5 and although my issue is a bit different than yours, I tried your workaround without any luck.

Haha, as for the hack, my use-case specifically supports multi-touch, but that's an interesting idea I'll dig into if necessary.

ArenMook: Just a thought... you mention that Unity Remote sends both touch and mouse events and the trouble comes from sorting them out, but I'm wondering why NGUI would ever need to listen to both at the same time. There's never a real-world scenario where you have to respond to both on one device, so I'm wondering if it's possible to make mouse and touch mutually exclusive; enabling one disables the other. Maybe if you are only ever expecting and responding to one type of event (and ignoring the other) it would simplify things? I would gladly take that limitation to get better Unity Remote support.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: How can I test touch input via Unity Remote?
« Reply #3 on: November 11, 2013, 04:39:38 PM »
Windows 8 laptops can have a touch screen as well as a mouse, so unfortunately they are not mutually exclusive.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: How can I test touch input via Unity Remote?
« Reply #4 on: November 11, 2013, 04:48:57 PM »
In any case, I posted some code at the bottom of http://www.tasharen.com/forum/index.php?topic=6576.0