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:
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.
- public GameObject myGrid;
- public GameObject myCellPrefab;
- IEnumerator loadGrid(ArrayList data){
- //Empty Grid
- foreach(Transform child in myGrid.transform){
- NGUITools.Destroy(child.gameObject);
- }
- //Load New Data
- foreach(string item_name in data){
- GameObject item = NGUITools.AddChild(myGrid, myCellPrefab);
- item.FindChild("Label").GetComponent<UILabel>().text = item_name;
- }
- //Adding WaitForEndOfFrame() used to work, now does not help
- //yield return new WaitForEndOfFrame();
- myGrid.GetComponent<UIGrid>().Reposition();
- }
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.
