Author Topic: Check, if GameObject is inside UIPanel  (Read 2433 times)

Oinobareion

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 14
    • View Profile
Check, if GameObject is inside UIPanel
« on: November 13, 2013, 08:28:15 AM »
Hello everyone,

May be a simple question: Can I somehow check, if a GameObject is inside a UIPanel? I want to do something with the GameObject, as soon as it enters the panel. Is this possible?

Otherwise I would have to make a collider box as trigger and work with onTriggerEnter and onTriggerExit. I am wondering, if there's an easier way to do this.

Thanks for help!

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Check, if GameObject is inside UIPanel
« Reply #1 on: November 13, 2013, 03:40:41 PM »
NGUIMath.Calculate series of functions can calculate the dimensions of a group of objects with UI elements on them, and you can then check it against the panel's clipping rect. NGUI does it to clip widgets (UIWidget.isVisible).

Oinobareion

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 14
    • View Profile
Re: Check, if GameObject is inside UIPanel
« Reply #2 on: November 19, 2013, 09:24:08 AM »
Thanks for the answer. I simply used the "isVisible" function to check, if a certain GameObject is inside the panel's bounds. I am sure there are more elaborate ways to achieve this, but at least it works :-) Here is my code:

  1.         private bool CheckVisibility (Transform t)
  2.         {
  3.                 if (panel.IsVisible(t.position) == true)
  4.                 {
  5.                         return true;
  6.                        
  7.                 }
  8.                 else return false;
  9.         }
  10.