When we have many symmetrical graphs in our project, we can use the mirror to achieve the same effect display. and reduces the size footprint of the atlas. On the one hand, the resource consumption is reduced, while the running memory decreases.
Add our code to the UIBasicSprite.cs script:
<span style= "White-space:pre" ></span>public enum type{simple,sliced,tiled,filled,advanced,mirrored,}
Call Method:
protected void Fill (betterlist<vector3> verts, betterlist<vector2> Uvs, betterlist<color32> cols, RECT outer, rect inner) {mouteruv = Outer;minneruv = Inner;switch (type) {case Type.Simple:SimpleFill (Verts, Uvs, cols); Bre Ak;case Type.Sliced:SlicedFill (Verts, Uvs, cols); Break;case Type.Filled:FilledFill (Verts, Uvs, cols); break;case Type.Tiled:TiledFill (Verts, Uvs, cols); Break;case Type.Advanced:AdvancedFill (Verts, Uvs, cols); break;case Type.Mirrored:MirroredFill (Verts, Uvs, cols); break;}}
Specific implementation code:
void Mirroredfill (betterlist<vector3> verts, betterlist<vector2> Uvs, betterlist<color32> cols) { Texture tex = maintexture;if (Tex = = null) return; Vector2 size = new Vector2 (Minneruv.width * tex.width, Minneruv.height * tex.height); size *= pixelsize;if (Tex = = NULL | | size.x < 2f | | Size.y < 2f) return; Color32 C = drawingcolor; Vector4 v = drawingdimensions; Vector4 u=new Vector4 (minneruv.xmin,minneruv.ymin,minneruv.xmax,minneruv.ymax); float x0 = v.x;float y0 = V.y;float u0 = u . x;float V0 = U.y;bool YB = true;while (Y0 < V.W) {x0 = V.x;float y1 = y0 + size.y;float v1 = u.w;if (Y1 > v.w) {v1 = Mathf.lerp (U.y, U.W, (v.w-y0)/size.y); y1 = V.W;} BOOL B=true;while (x0 < v.z) {float x1 = x0 + size.x;float u1 = u.z;if (X1 > v.z) {u1 = Mathf.lerp (u.x, U.z, (v.z-x0 )/size.x); x1 = v.z;} Float Offset=0.3f;verts. ADD (New Vector3 (X0-offset, Y0-offset)); Verts. ADD (New Vector3 (X0-offset, Y1+offset)); Verts. ADD (New Vector3 (X1+offset, Y1+offset)); Verts. ADD (New Vector3 (x1+Offset, y0-offset)); float Yoffset = size.y! = 1? 0.001f:0.0f;float Xoffset = size.x! = 1? 0.001f:0.0f;if (YB) {if (b) {Uvs. ADD (New Vector2 (U0-xoffset, V0)); Uvs. ADD (New Vector2 (U0-xoffset, V1+yoffset)); Uvs. ADD (New Vector2 (U1, V1+yoffset)); Uvs. ADD (New Vector2 (U1, V0));} Else{uvs. ADD (New Vector2 (U1, V0)); Uvs. ADD (New Vector2 (U1, V1+yoffset)); Uvs. ADD (New Vector2 (U0-xoffset, V1+yoffset)); Uvs. ADD (New Vector2 (U0-xoffset, V0));}} Else{if (b) {Uvs. ADD (New Vector2 (U0-xoffset, V1+yoffset)); Uvs. ADD (New Vector2 (U0-xoffset, V0)); Uvs. ADD (New Vector2 (U1, V0)); Uvs. ADD (New Vector2 (U1, V1+yoffset));} Else{uvs. ADD (New Vector2 (U1, V1+yoffset)); Uvs. ADD (New Vector2 (U1, V0)); Uvs. ADD (New Vector2 (U0-xoffset, V0)); Uvs. ADD (New Vector2 (U0-xoffset, V1+yoffset));}} Cols. ADD (c); cols. ADD (c); cols. ADD (c); cols. ADD (c); x0 + = size.x;b=!b;} Yb=!yb;y0 + = Size.y;}}
After the expansion, the mirror effect can be realized.
Ngui-sprite Extended mirroring feature