Author Topic: Check if a GameObject is being clipped under a UIPanel  (Read 6853 times)

Fordeka

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 20
    • View Profile
Check if a GameObject is being clipped under a UIPanel
« on: April 14, 2012, 08:11:33 AM »
Is there a way to check if a GameObject is currently being clipped or not under a UIPanel with clipping box enabled?

Thanks.

Nicki

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 33
  • -Receive: 141
  • Posts: 1,768
    • View Profile
Re: Check if a GameObject is being clipped under a UIPanel
« Reply #1 on: April 14, 2012, 10:41:25 AM »
Not a game object, but you can do this on a widget:

Attach your own script that calls

  1. Debug.Log("My Panel is: " + GetComponent<UIWidget>().panel.name);
  2.  

on Start or Update or whenever.

That will output the name of the Panel that's drawing your widget. Then you just have to see if that panel has a clip or not.

If you're thinking of being able to check run-time whether it's clipped, I dunno, better call ArenMook.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Check if a GameObject is being clipped under a UIPanel
« Reply #2 on: April 14, 2012, 02:02:45 PM »
Take a look at UIDraggablePanel.shouldMove property. The code you need is there, just copy/paste it to where you need it, and provide the widget's bounds for the 'bounds' variable. To calculate the widget's bounds (or for a group of widgets for that matter), you can use NGUIMath.CalculateRelativeWidgetBounds(panelTransform, widgetTransform);