Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - seanb

Pages: [1]
1
NGUI 3 Documentation / Re: UIGrid
« on: February 01, 2014, 08:16:01 PM »
What is the correct way to reposition a vertical grid after loading dynamic data? I used to have this working correctly before UIDraggablePanel was converted to UIScrollView, but I can't seem to get it working since the change. I have searched the forum thoroughly and tried all advice you and others have given. My (condensed) old way of doing it:

  1.  
  2. public GameObject myGrid;
  3. public GameObject myCellPrefab;
  4.  
  5. IEnumerator loadGrid(ArrayList data){
  6.        
  7.         //Empty Grid
  8.         foreach(Transform child in myGrid.transform){
  9.                 NGUITools.Destroy(child.gameObject);
  10.         }
  11.        
  12.         //Load New Data
  13.         foreach(string item_name in data){
  14.                 GameObject item = NGUITools.AddChild(myGrid, myCellPrefab);
  15.                 item.FindChild("Label").GetComponent<UILabel>().text = item_name;
  16.         }
  17.  
  18.         //Adding WaitForEndOfFrame() used to work, now does not help
  19.         //yield return new WaitForEndOfFrame();
  20.  
  21.         myGrid.GetComponent<UIGrid>().Reposition();
  22.  
  23. }
  24.  

I've tried the following with no luck:
- Adding "yield return new WaitForEndOfFrame();" after each block
- Adding "repositionNow=true" after emptying the grid, after loading the grid, or both
- Adding "Reposition()" after emptying the grid, after loading the grid, or both
- Adding "ResetPosition()" to the UIScrollView.
- Using DestroyImmediate instead of Destroy

It looks find on the first load, but after the second load everything is misaligned because the cells are not being destroyed before Reposition() is called. Each load doubles the entries because the items are not being destroyed at all.

-edit-
After struggling with this for days, I found that the only way to get this working correctly is to use Unity's Destroy() to destroy all old entries, followed by WaitForEndOfFrame() . NGUITools.Destroy() does not work in my case, no matter what I try it retains old entries that were supposed to be destroyed.

Pages: [1]