Author Topic: Can you declare static bool UICamera:Raycast() public?  (Read 9118 times)

Asse

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 70
    • View Profile
Can you declare static bool UICamera:Raycast() public?
« 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.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Can you declare static bool UICamera:Raycast() public?
« Reply #1 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.

Asse

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 70
    • View Profile
Re: Can you declare static bool UICamera:Raycast() public?
« Reply #2 on: May 18, 2012, 08:08:03 AM »
Great, thanks man. Next time I'll have a closer look!

Asse

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 70
    • View Profile
Re: Can you declare static bool UICamera:Raycast() public?
« Reply #3 on: May 18, 2012, 10:01:51 AM »
.currentTouch is always null when I check it
.lastHit is of course always a valid object.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Can you declare static bool UICamera:Raycast() public?
« Reply #4 on: May 18, 2012, 04:50:54 PM »
currentTouch is valid while you are inside UI callback such as OnDrag, OnPress, etc.

Asse

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 70
    • View Profile
Re: Can you declare static bool UICamera:Raycast() public?
« Reply #5 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).

rgonzalezVW

  • Guest
Re: Can you declare static bool UICamera:Raycast() public?
« Reply #6 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

riffraff

  • Guest
Re: Can you declare static bool UICamera:Raycast() public?
« Reply #7 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.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Can you declare static bool UICamera:Raycast() public?
« Reply #8 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);

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Can you declare static bool UICamera:Raycast() public?
« Reply #9 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).

Asse

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 70
    • View Profile
Re: Can you declare static bool UICamera:Raycast() public?
« Reply #10 on: June 26, 2012, 10:18:48 AM »
Now we are talking!  :) This works!

Asse

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 70
    • View Profile
Re: Can you declare static bool UICamera:Raycast() public?
« Reply #11 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..
« Last Edit: June 28, 2012, 03:46:06 AM by Asse »