Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: Asse on May 18, 2012, 06:04:04 AM

Title: Can you declare static bool UICamera:Raycast() public?
Post by: Asse on May 18, 2012, 06:04:04 AM
Hey Michael,

can you declare the UICameras method static bool Raycast() as public? It'd be helpful to check for ui elements under the cursor/touch to invalided own clicks.
Title: Re: Can you declare static bool UICamera:Raycast() public?
Post by: ArenMook on May 18, 2012, 07:27:09 AM
UICamera.currentTouch.current gives you the game object under the mouse.

UICamera.lastHit gives you the result of the last raycast hit.
Title: Re: Can you declare static bool UICamera:Raycast() public?
Post by: Asse on May 18, 2012, 08:08:03 AM
Great, thanks man. Next time I'll have a closer look!
Title: Re: Can you declare static bool UICamera:Raycast() public?
Post by: Asse on May 18, 2012, 10:01:51 AM
.currentTouch is always null when I check it
.lastHit is of course always a valid object.
Title: Re: Can you declare static bool UICamera:Raycast() public?
Post by: ArenMook on May 18, 2012, 04:50:54 PM
currentTouch is valid while you are inside UI callback such as OnDrag, OnPress, etc.
Title: Re: Can you declare static bool UICamera:Raycast() public?
Post by: Asse on June 25, 2012, 03:30:15 AM
Exactly, during the callbacks. But I need to check in my own raycasting code if the user is above an UI element (I'm working on a 2d game so conceptionally everything is 2d).
Title: Re: Can you declare static bool UICamera:Raycast() public?
Post by: rgonzalezVW on June 25, 2012, 06:53:36 AM
I also would love some methods defined as public (Raycast, GetTouch, RemoveTouch, ProcessTouch) and a SendMessage added in the Update method so we can "extend" the inputs accepted by NGUI (Windows 7 multitouch, by example).
I've attached a patch with the changes, if you apply it, I'll be very happy :D
Title: Re: Can you declare static bool UICamera:Raycast() public?
Post by: riffraff on June 25, 2012, 10:44:37 AM
I'm using something like this:

  1. void Update()
  2. {
  3.         GameObject hovered_object = UICamera.hoveredObject;
  4.         if( null == hovered_object )
  5.         {
  6.                 m_mouse_over_ui = false;
  7.         }
  8.         else
  9.         {
  10.                 m_mouse_over_ui = true;
  11.         }
  12. }
  13.  

And it works fine for me.
Title: Re: Can you declare static bool UICamera:Raycast() public?
Post by: ArenMook on June 25, 2012, 12:41:39 PM
Just a note about:
  1. SendMessage("ProcessInput", null, SendMessageOptions.DontRequireReceiver);
Unity will treat this as if ProcessInput function should have no parameters. It's identical to:
  1. SendMessage("ProcessInput", SendMessageOptions.DontRequireReceiver);
Title: Re: Can you declare static bool UICamera:Raycast() public?
Post by: ArenMook on June 25, 2012, 12:44:36 PM
Exactly, during the callbacks. But I need to check in my own raycasting code if the user is above an UI element (I'm working on a 2d game so conceptionally everything is 2d).
Why? UICamera.hoveredObject tells you whether the mouse is over a UI element, and UICamera.inputHasFocus tells you whether an input field currently has focus (user is typing).
Title: Re: Can you declare static bool UICamera:Raycast() public?
Post by: Asse on June 26, 2012, 10:18:48 AM
Now we are talking!  :) This works!
Title: Re: Can you declare static bool UICamera:Raycast() public?
Post by: Asse on June 28, 2012, 03:26:50 AM
Hmm.. while this works great for clicks, I UICamera.hoveredObject is always null on mobile/touch. In both ways I check inside MonoBehaviour.Update()  :-\

Edit: NGUIs UpdateManager has script order -5, my scripts use the default order, so this shouldn't be the problem.

Ah yes, hovered :D Now I see ;) Too bad, I thought it will be set at least for one frame for touches..