Author Topic: NGUITools.AddChild Question  (Read 9780 times)

Harsul

  • Guest
NGUITools.AddChild Question
« on: July 21, 2012, 04:26:33 PM »
Hi.

Is it possible to use SetActiveRecursively when using NGUITools.AddChild?.
If so how would you do that?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: NGUITools.AddChild Question
« Reply #1 on: July 21, 2012, 04:32:35 PM »
I don't understand what the two have to do with each other?

Harsul

  • Guest
Re: NGUITools.AddChild Question
« Reply #2 on: July 21, 2012, 05:03:24 PM »
I don't understand what the two have to do with each other?

I wanted to deactivate the child i Instantiate. But i did this and its working:
  1. NGUITools.AddChild(parentObject, prefab);
  2. parentItem.SetActiveRecursively(false);

But i got another strange problem. The object I'm Instantiating is a child in a table for a scrollbar.
When i activate the menu using SetActiveRecursively(true) all the items(the Instantiated child's) is sorted.
But if i use SetActiveRecursively(true) and then SetActiveRecursively(false) and then Instantiating the items and do
SetActiveRecursively(true) they isn't getting sorted?

Trying to explain better:
If i Instantiate the child before using the menu(with the scrollbar) and
activate the menu every child is sorted (like i want).
But if i activate and deactivate the menu a couple of times before Instantiating the child(s),
the child(s) doesn't get sorted?.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: NGUITools.AddChild Question
« Reply #3 on: July 21, 2012, 08:24:21 PM »
Use NGUITools.SetActive instead. SetActiveRecursively doesn't activate/deactivate objects in a proper order.

Harsul

  • Guest
Re: NGUITools.AddChild Question
« Reply #4 on: July 22, 2012, 09:58:51 AM »
Use NGUITools.SetActive instead. SetActiveRecursively doesn't activate/deactivate objects in a proper order.

That didn't help, still got the same problem. What could be causing this?

EDIT:

I'm using this:
  1. NGUITools.AddChild(parentItem, itemTable);
  2. UITable reposition = parentItem.GetComponent<UITable>();
  3. reposition.repositionNow = true;
  4. NGUITools.SetActive(parentItem, false);
But the scrollbar doesn't get updated?
« Last Edit: July 22, 2012, 10:53:32 AM by Harsul »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: NGUITools.AddChild Question
« Reply #5 on: July 22, 2012, 01:57:48 PM »
You set the 'repositionNow' flag which is delayed until the next update, and then you disable the game object so it will never get the Update call.

Harsul

  • Guest
Re: NGUITools.AddChild Question
« Reply #6 on: July 22, 2012, 02:44:30 PM »
You set the 'repositionNow' flag which is delayed until the next update, and then you disable the game object so it will never get the Update call.

I really appreciate you trying to help me :).
But i don't understand?, are you saying im doing this wrong:
  1. NGUITools.AddChild(parentItem, itemTable);
  2. UITable reposition = parentItem.GetComponent<UITable>();
  3. reposition.repositionNow = true;
  4. NGUITools.SetActive(parentItem, false); // if i delete this it's the same

I don't understand why it doesn't work. If i just spawn them before open the menu it all works fine..
If i open/close the menu before using this code above it doesn't work the scrollbar isn't there to use when i open the menu  :o

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: NGUITools.AddChild Question
« Reply #7 on: July 22, 2012, 04:01:22 PM »
In order to update a draggable panel that draws the table, the panel must have a UIDraggablePanel on it, and in order to update the scroll bar, UIDraggablePanel must reference a scroll bar.

Make sure that your draggable panel isn't marked as "static" (on the UIPanel, not on the game object). If it's marked as "static", you won't be able to add anything to it as its geometry is static.

Harsul

  • Guest
Re: NGUITools.AddChild Question
« Reply #8 on: July 22, 2012, 08:46:33 PM »
Thank you so much for taking time to help me with this i really appreciate it :)!
The problem was that i didn't have keepWithinPanel set to true on the UIPanel. It all works now!