Author Topic: How do you reset UIDraggablePanel position when UIGrid's children change?  (Read 7754 times)

Thurinus

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 27
    • View Profile
Hi all,

I'm implementing a mobile-based drag panel (no scrollbars), with a UIGrid under a UIDraggablePanel. the UIGrid's children change in number at certain points in the game, and I'm seeing an issue where the children will sometimes be out of the draggable panel window range, and will only come into range when the panel gets scrolled. The children will stay within sight thereafter. Is there a way to reset the panel after children get replaced? I've setting UIGrid's repositionNow field to "true" and calling Reposition() directly after the children replacement, but no dice.

Edit: I also tried calling UIDraggablePanel.ResetPosition(), but that didn't help

Thanks for any help!
« Last Edit: January 18, 2013, 06:59:12 PM by Thurinus »

pretender

  • Full Member
  • ***
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 155
    • View Profile
i think grid's repositionNow is what you are looking for

Thurinus

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 27
    • View Profile
I thought so too, as mentioned in my original post, but that didn't seem to do the trick :(

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
UIDraggablePanel.UpdateScrollbars(true)

Thurinus

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 27
    • View Profile
Thanks for the response, but UpdateScrollbars didn't seem to work either :( Here's the flow I currently have going, in semi-pseudocode, of it matters:

  1. ...
  2.  
  3. // remove all children from UIGrid
  4. foreach(Transform child in grid.transform)
  5. {
  6. Destroy(child.gameObject);
  7. }
  8.  
  9. // populate the grid
  10. foreach(Item item in items)
  11. {
  12. CreateItemCellInGrid(item);
  13. }
  14.  
  15. // reset positions
  16. grid.Reposition();
  17. draggablePanel.UpdateScrollbars(true);
  18.  
  19. ...
  20.  

Should this work?

Edit: I also noticed that UpdateScrollbars(true) has already been called in Reposition(), so that wouldn't have worked anyway. Is there some sort of race condition between population and repositioning that's causing this to not work as expected?
« Last Edit: January 22, 2013, 03:50:22 PM by Thurinus »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
You need to use NGUITools.Destroy, not just Destroy. This is because NGUITools unparents the game object it destroys. Simply calling Destroy doesn't actually remove this object from the hierarchy.

Thurinus

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 27
    • View Profile
NGUITools.Destroy didn't actually do any unparenting (I might have an older version?), but that gave me the clue to try explicitly unparenting in my loop before calling NGUITools.Destroy. Looks like it worked, thanks!