NGUI loading the item with Uigrid will have a partially vacated workaround----------------NGUI 3.8.0
First describe the problem you encountered
My hierarchy.
The method of loading is created if the number of loaded data is greater than the number of item already in existence, and if less than the number of item already exists, hides the excess;
But what happens when you run it.
A part of it is empty;
I think that part of the empty out is the hidden part, so in each assignment to give Uigrid reposition a bit, but still no
Workaround:
There's an option under Uigrid hide Inactive, inactive hidden
After checking
Automatically squeezes out the space occupied by the hidden part.
Additional Load Code
-----> data More than the active item
1list<transform> list = FindAll ();//collection of all existing Item2 varListA = list. Where<transform> (s = = S.gameobject.activeself = =true);//Activation of3 varLISTD = list. Where<transform> (d = d.gameobject.activeself = =false);//Non-activated4 5 if(Itemlist.count>=lista.count ())//If the existing item is insufficient or just as much6 {7Transform[] TRS =Lista.toarray ();8 //Use the existing active item first9 for(inti =0; I < TRS. Length; i++)Ten { OneTrs[i]. Getcomponent<backpackitemcontroller> (). RawData =Itemlist[i]; A } - - the //not enough? The existing hidden item is activated to exploit -transform[] TRD =Listd.toarray (); - for(inti =0; I <mathf.min (TRD. Length,itemlist.count-trs. Length); i++) - { +Trd[i].gameobject.setactive (true); -Trd[i]. Getcomponent<backpackitemcontroller> (). RawData = Itemlist[i +TRS. Length]; + } A at - //It 's not enough, new. - for(inti =0; I < ITEMLIST.COUNT-TRD. Length-lista.count (); i++) - { -Gameobject Itempre = Resources.load ("Backpack/item") asGameobject; -Nguitools.addchild (Grid.gameobject, Itempre). Getcomponent<backpackitemcontroller> (). RawData = Itemlist[i + TRS. length+TRD. Length]; in } -}
-------> data is less than the active item, hide the unused item
Else if(Itemlist.count<lista.count ())//the existing item is more, the unused item is hidden . { for(inti =0; I <= lista.count (); i++) { if(i<itemlist.count) {lista.elementat (i). Getcomponent<BackpackItemController> (). RawData =Itemlist[i]; Print (2); } Else if(i>=itemlist.count) {Lista.elementat (i-1). Gameobject.setactive (false); Print (1); } Print (3); }} Grid.repositionnow=true;
View Code
Ngui loading the item with Uigrid will have a partially vacated workaround