Author Topic: How to check if a widget is visible by UICamera ?  (Read 6530 times)

Docteur Cox

  • Guest
How to check if a widget is visible by UICamera ?
« on: July 16, 2013, 07:25:13 AM »
Hello there !

So here's my problem. I have UITables with many widget on each item. While the performances are still decent on my PC (above 150 fps), I would like to make sure it works fine even on low-end machines. I noticed that disabling unseen objects in editor make game considerably faster (250 fps) so I'm looking for a performant way to check whether or not an UIWidget is visible on screen, and if so disable it.

Does someone know how to do that ?

Thanks in advance for your answers !

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: How to check if a widget is visible by UICamera ?
« Reply #1 on: July 16, 2013, 10:49:33 AM »
UIWidget.isVisible :P

Docteur Cox

  • Guest
Re: How to check if a widget is visible by UICamera ?
« Reply #2 on: July 17, 2013, 05:40:37 AM »
Erf, I just tried that but that does not seem to work for me. All widget are considered to be visible. I also tried UIPanel.isVisible(Widget w) and I get the same output. Do you know what I may have done wrong in my scene ?

Thanks in advance for your answer  :)

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: How to check if a widget is visible by UICamera ?
« Reply #3 on: July 17, 2013, 05:52:31 AM »
If your panels don't use clipping then the widgets may always be considered to be visible. What I generally do myself is move things off-screen then disable them all in one action. When using ActiveAnimation.Play, you can actually tell it to disable the object after the animation finished playing. If you can't use it, you can still check to see if something is off-screen by checking its rectangle against the screen width/height. NGUIMath.CalculateRelativeWidgetBounds will tell you the rect assuming you use the UI camera's object as parent.

Docteur Cox

  • Guest
Re: How to check if a widget is visible by UICamera ?
« Reply #4 on: July 18, 2013, 08:48:16 AM »
I will try that. Thanks ! :)