Author Topic: Increase/Decrease depth of all widgets in a panel  (Read 4544 times)

justinISO

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 52
    • View Profile
Increase/Decrease depth of all widgets in a panel
« on: October 22, 2013, 01:04:28 PM »
Hello,

I have a card type game I am using NGUI for and the cards are set up as follows:

Card One - Panel
-- BG - Sprite
-- Info - Label
-- Title - Label

All cards are laid out like this.

What I need is when I hover over a single card, I increase it's size to make it look like it is coming forward (this is already working), but I also need to bring the depth of everything (labels and sprites) of that single card ahead of all of the other cards on the table at the same time.

Any thoughts?

Thanks,
Justin

NaxIonz

  • Jr. Member
  • **
  • Thank You
  • -Given: 3
  • -Receive: 0
  • Posts: 70
    • View Profile
Re: Increase/Decrease depth of all widgets in a panel
« Reply #1 on: October 22, 2013, 01:58:35 PM »
Bring them all forward:

  1. UIWidget[] widgets = gameObject.GetComponentsInChildren<UIWidget>();
  2. foreach (UIWidget widget in widgets) {
  3.   widget.depth += 1;
  4. }

justinISO

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 52
    • View Profile
Re: Increase/Decrease depth of all widgets in a panel
« Reply #2 on: October 22, 2013, 03:17:02 PM »
Thank you!

Interesting note. I was trying to do the GetComponentsInChildren in the line of the foreach

  1. foreach(UIWidget widget in gameObject.GetComponentsInChildren<UIWidget>()){
  2. .
  3. .
  4. .

And that was throwing an error saying UIWidget was not Enumeratable or something along those lines. Which is why I brought this to the forums.

Your way works though so thanks!

~Justin