Author Topic: Table reposition after populating prefab with anchors  (Read 1109 times)

TypoStraw

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 19
    • View Profile
Table reposition after populating prefab with anchors
« on: April 03, 2015, 10:57:46 AM »
I'm currently populating a table with a prefabs created through simple code like this:

  1. Elev[] students = DatabaseManagement.Instance.GetStudentsInRoom(references.Id);
  2.  
  3. for (int i = 0; i < students.Length; i++)
  4. {
  5.         PoolManager.Instance.CreateNameTagPrefab(students[i], InfoPanelTable);
  6. }
  7.  
  8. StartCoroutine(DelayedReposition());

The method CreateNameTagPrefab instantiates a prefab using NGUITools.AddChild and adds it to the table. The prefab's labels are all updated with the values of the given student.

The coroutine consist of this:

  1. yield return null;
  2. InfoPanelTable.GetComponent<UITable>().Reposition();
  3. InfoPanelTable.transform.parent.GetComponent<UIScrollView>().ResetPosition();

The problem is that I have to delay the reposition by one frame in order to wait for anchors to update in the name prefab.

The ingame view looks like this.
This picture is an example of how it looks like with minimal info, but if the note is longer it will stretch a bit and look like this - so far, nothing is wrong.

The problem is that since it waits one frame it will flicker a bit: http://i.imgur.com/1GqZzNW.gif (primarily text overlapping due it them all being created in one place).

If I remove the frame delay it will reposition it to the original prefab size (before the anchors have been recalculated) and look like this (I'm not really sure why it goes all wonky either...)

Is there any way to force anchors to update instead of having to wait a frame?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Table reposition after populating prefab with anchors
« Reply #1 on: April 04, 2015, 04:16:43 AM »
You can force an immediate refresh by using NGUITools.ImmediatelyCreateDrawCalls.

TypoStraw

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 19
    • View Profile
Re: Table reposition after populating prefab with anchors
« Reply #2 on: April 04, 2015, 08:21:48 AM »
Many thanks, it has completely fixed the issue.

Also, I noticed that it says "This message is awaiting approval by a moderator" at the top of my post - is this something I should be worried about?

Nicki

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 33
  • -Receive: 141
  • Posts: 1,768
    • View Profile
Re: Table reposition after populating prefab with anchors
« Reply #3 on: April 04, 2015, 12:24:46 PM »
re approval: The forum gets stuck some times, don't worry about it.