Ngui loading the item with Uigrid will have a partially vacated workaround

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.