Author Topic: UICamera's touch API  (Read 8141 times)

ryan

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 90
    • View Profile
UICamera's touch API
« on: October 30, 2013, 02:09:38 PM »
I'm trying to integrate a project's input processing with the work NGUI's already doing in UICamera.  In the past, I've had a separate class that looks at Unity's Input.touches and just does a raycast to see if it's a UI touch and ignores it, but this seems wasteful since I should just be able to ask UICamera.  I see onCustomInput as a handy place to hook in after UICamera has done its work, but getting access to its MouseOrTouch instances is a little wonky.

There's no public access to the mMouse, so if I want to know if a mouse click was on a UI object, I have to figure it out myself.  This is in spite of the fact that mMouse is included in the calculations for touchCount and dragCount.  I do have access to the touches through GetTouch, but this potentially dirties the list of touches if I ask for a touch ID that has been removed.  Also, if I want to account for controller input, onCustomInput is called between mouse/touch processing and controller processing, so that could be problematic.

Of course I can make changes, but for now I'm trying to avoid any custom changes to NGUI to make updating easier.  Am I over-thinking/over-complicating things?  Is there an easier way to go about deciding whether or not to process a touch?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UICamera's touch API
« Reply #1 on: November 01, 2013, 08:37:08 AM »
GetTouch(-1) gives you the left mouse button. I assume this is what you're missing?

ryan

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 90
    • View Profile
Re: UICamera's touch API
« Reply #2 on: November 04, 2013, 01:20:06 PM »
I thought that was true at one point, and I see that ProcessMouse uses negative touch IDs, but it also goes directly to mMouse instead of calling GetTouch.  I don't see where the mouse inputs would ever end up in mTouches, and GetTouch never looks at mMouse.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UICamera's touch API
« Reply #3 on: November 05, 2013, 05:39:18 AM »
Ah yes true. The curse of local modifications and having too many projects... Well, just add this:

  1.         /// <summary>
  2.         /// Get the details of the specified mouse button.
  3.         /// </summary>
  4.  
  5.         static public MouseOrTouch GetMouse (int button) { return mMouse[button]; }

I've also added it locally so you will see it in a future update.