Author Topic: Widget depth inherit from the children  (Read 2737 times)

malo88

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 9
    • View Profile
Widget depth inherit from the children
« on: July 11, 2017, 09:08:59 AM »
Hi, I have this situation at the moment: a UISprite which must hide some widgets behind it, so it's like when you can click on a widget it goes in front of the Sprite and if it is not clickable it goes behind. The widgets and this sprite are under the same panel, so what I'm trying to do is: when a widget should be visible (clickable) I take the depth of the sprite, which for instance is 100, and put the widget depth to 101. When a widget must be hidden, i decrease its depth so that is behind the sprite. The problem is that the widgets contain child elements, like labels and other sprites, and changing the depth of the widget does not change the depth of the children, which remains hidden under the panel! Now, since I wanted to avoid taking all the components of the children of a widget and modify their depth every time (a bit expensive and error prone), is there a way to make the depth of the widget parent inherit from the children? NOTE also that in my situation I cannot afford having multiple panels (since one panel is one draw call and I have really a lot of widgets here).
Many thanks

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Widget depth inherit from the children
« Reply #1 on: July 15, 2017, 06:19:40 AM »
I know you said you can't afford multiple panels, but this very situation is what panels excel at. Panels group widgets. You're trying to adjust the depth of a group of widgets. This is what panels do by default. Without using panels, you're effectively stuck doing it by hand one sprite at a time. Fortunately NGUI does have a handy function for you: NGUITools.AdjustDepth(rootObject, adjustment), where "rootObject" is what you're trying to adjust (your widget that may or may not contain children), and adjustment is how much to adjust by. For example -1000 will move everything forward by 1000, while +1000 will move everything back.

malo88

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 9
    • View Profile
Re: Widget depth inherit from the children
« Reply #2 on: July 17, 2017, 04:37:13 AM »
Thanks man! That solved my problem! :D