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