Author Topic: Grid and Tables deactivating at runtime...  (Read 2877 times)

Xomanowar

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 2
    • View Profile
Grid and Tables deactivating at runtime...
« on: March 09, 2015, 07:47:36 AM »
Hi, I'm having the following problem...

Everytime I start my game, my Grid and Tables components start deactivated, And when I use Ngui.AddChild to my "Grid" GameObject (with UIGrid script), the itens appear one over another.

Only when I activate  manually the Grid component in my GridGameObject, that the itens go to correct position.

Why my Grid and Tables components deactivate itself when I start the game?

Nicki

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 33
  • -Receive: 141
  • Posts: 1,768
    • View Profile
Re: Grid and Tables deactivating at runtime...
« Reply #1 on: March 09, 2015, 12:01:33 PM »
Because once they've been place, there's no reason to run an update constantly anymore.

You can call Reposition() on it to force an update.

Andresfdezb

  • Newbie
  • *
  • Thank You
  • -Given: 10
  • -Receive: 0
  • Posts: 23
    • View Profile
Re: Grid and Tables deactivating at runtime...
« Reply #2 on: March 10, 2015, 03:36:14 AM »
So I have a problem that might be related to this. In my hierarchy there are these elements:

-Panel
--Header (some sprites)
--Background
--Scrollbar
--ScrollView
---Table

The panel gets enabled/disabled (as it is just a part of the UI). The table has a certain amount of elements, which get activated/deactivated to show the elements I need, but when I do that, the table appears in the middle of the Scrollview instead of at the pivot point (which is set to TopLeft in inspector). As according to the docs on UIScrollView and UITable, I reposition the table after populating its contents and then I reposition the ScrollView:

  1. // activate/deactivate desired table elements...
  2. // and then sort the table and reposition the scrollview
  3. mTable.sorting = UITable.Sorting.Alphabetic;
  4. mTable.pivot = UIWidget.Pivot.TopLeft;
  5. mTable.Reposition();
  6. mTable.transform.GetComponentInParent<UIScrollView>().contentPivot = UIWidget.Pivot.TopLeft;
  7. mTable.transform.GetComponentInParent<UIScrollView>().ResetPosition();

Curiously enought, this only happens the first time the panel that contains the scrollview and the table is enabled. Once I disable the panel and reenable it, everything gets to its position.
I have tried all the combinations with populating the table, repositioning the table and resetting scrollview's position but it doesn't work as I think it should (which is setting the contents of the table to the top left and the table also to the top left of the scrollview). Am I doing something wrong with my code or am I expecting a different behaviour than the intended?

I have attached two images showing what I think I shoud get and another showing what happens.

Thanks

[EDIT Also tried getting the scrollview component using NGUITools:

  1. UIScrollView sv = NGUITools.FindInParents<UIScrollView>(mTable.gameObject);
  2. if (sv != null) {
  3.         sv.contentPivot = UIWidget.Pivot.TopLeft;
  4.         sv.ResetPosition();
  5. }

And I just debugged it and made sure it does go through that piece of code. Still nothing. Seems like calling either UITable.ResetPosition() or UIScrollView.ResetPosition() (or both) does nothing...
« Last Edit: March 10, 2015, 03:52:31 AM by Andresfdezb »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Grid and Tables deactivating at runtime...
« Reply #3 on: March 10, 2015, 08:26:29 PM »
You are likely doing this before widgets actually had a chance to get added to their managing panels.

Change the script execution of your script to ensure that it will be executed last.