Author Topic: What is effective way to get Rect of GUI component ?  (Read 3464 times)

Kichang Kim

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 17
    • View Profile
What is effective way to get Rect of GUI component ?
« on: August 25, 2012, 08:57:11 PM »
Hi, I'm working to develop mobile RTS game.

I'm using NGUI for main GUI system (build button, upgrade button, and so on). Additionally, I used Input.touch for picking building or units (using raycasting).

In this case, what is best way to get Rect of NGUI component (label, button, background ...) for ignore picking event on GUI component? I think that checking rect of gui component may be solution. Is there another way to check whether touch point is on gui component?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: What is effective way to get Rect of GUI component ?
« Reply #1 on: August 25, 2012, 09:25:33 PM »
It's generally better if you let NGUI take care of touch detection. It can be used both on your UI camera and your game camera. You can also use it only on the UI camera, but set a UICamera.genericEventHandler -- and it will receive a copy of all the events if you want to handle them from your own manager.

UICamera.lastHit tells you the result of the last raycast, so UICamera.lastHit.collider can be checked -- is it on the UI layer? If so, then the UI is handling the event. If not, then it's an event for your game.

Kichang Kim

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 17
    • View Profile
Re: What is effective way to get Rect of GUI component ?
« Reply #2 on: August 25, 2012, 11:25:42 PM »
Thanks for reply. It looks better using NGUI's inernal touch event system than my own touch system except multiple touch recognition. Can NGUI touch event handle multiple touch and touch phase? (for determine short/long touch, multiple touch for zoom in/out)

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: What is effective way to get Rect of GUI component ?
« Reply #3 on: August 25, 2012, 11:33:27 PM »
UICamera.currentTouchID tells you the ID of the touch, so you can do what you want.

Kichang Kim

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 17
    • View Profile
Re: What is effective way to get Rect of GUI component ?
« Reply #4 on: August 25, 2012, 11:44:06 PM »
UICamera.currentTouchID tells you the ID of the touch, so you can do what you want.
Great. I'll try to merge my own touch manager to NGUI. Thanks for quick reply :)