Scrollview 2000 items do not card

Source: Internet
Author: User
Using unityengine; using system. collections. generic; public class uiwrapgrid: monobehaviour {transform mtrans; uipanel mpanel; uiscrollview mscroll; bool mhorizontal = false; bool mfirsttime = true; list <transform> mchildren = new list <transform> (); /// <summary> // initialize everything and register a callback with the uipanel to be notified when the Clipping Region moves. /// </Summary> protected virtual Void start () {initgrid (); mfirsttime = false;} // <summary> // cache the scroll view and return 'false' if the scroll view is not found. /// </Summary> Public void initgrid () {mtrans = transform; mpanel = nguitools. findinparents <uipanel> (gameobject); mscroll = mpanel. getcomponent <uiscrollview> (); If (mscroll! = NULL) {mscroll. getcomponent <uipanel> (). onclipmove = onmove;} mchildren. clear (); For (INT I = 0; I <mtrans. childcount; ++ I) mchildren. add (mtrans. getchild (I); // sort the list of children so that they are in order mchildren. sort (uigrid. sortbyname); If (mscroll = NULL) return; If (mscroll. movement = uiscrollview. movement. horizontal) mhorizontal = true; else if (mscroll. movement = uiscrollview. Movement. vertical) mhorizontal = false; wrapcontent ();} /// <summary> // callback triggered by the uipanel when its Clipping Region moves (for example when it's being scrolled ). /// </Summary> protected virtual void onmove (uipanel panel) {wrapcontent ();} void wrapcontent () {vector3 [] Corners = mpanel. worldcorners; For (INT I = 0; I <4; ++ I) {vector3 v = corners [I]; V = mtrans. inversetransform Point (V); corners [I] = V;} vector3 center = vector3.lerp (corners [0], corners [2], 0.5f); If (mhorizontal) {// horizontal for (INT I = 0, IMAX = mchildren. count; I <IMAX; ++ I) {transform T = mchildren [I]; float distance = T. localposition. x-center. x; float min = corners [0]. *-100; float max = corners [2]. X + 100; distance + = mpanel. clipoffset. x-mtrans. localposition. x; If (! Uicamera. ispressed (T. gameobject) {nguitools. setactive (T. gameobject, (distance> min & distance <max), false) ;}} else {// vertical for (INT I = 0, IMAX = mchildren. count; I <IMAX; ++ I) {transform T = mchildren [I]; float distance = T. localposition. y-center. y; float min = corners [0]. y-100; float max = corners [2]. Y + 100; distance + = mpanel. clipoffset. y-mtrans. localposition. y; If (! Uicamera. ispressed (T. gameobject) {bool active = T. gameobject. activeself; bool willactive = distance> min & distance <Max; If (active = willactive) continue; nguitools. setactive (T. gameobject, willactive, false );}}}}}

  

Scrollview 2000 items do not card

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.