FairyGUI.NGraphics.SetOneQuadMesh C# (CSharp) Method

SetOneQuadMesh() public method

public SetOneQuadMesh ( Rect drawRect, Rect uvRect, Color color, Color allColors = null ) : void
drawRect UnityEngine.Rect
uvRect UnityEngine.Rect
color UnityEngine.Color
allColors UnityEngine.Color
return void
        public void SetOneQuadMesh(Rect drawRect, Rect uvRect, Color color, Color[] allColors = null)
        {
            //当四边形发生形变时,只用两个三角面表达会造成图形的变形较严重,这里做一个优化,自动增加更多的面
            if (vertexMatrix != null)
            {
                Alloc(9);

                FillVerts(0, drawRect);
                FillUV(0, uvRect);

                Vector2 camPos = cameraPosition != null ? (Vector2)cameraPosition : Vector2.zero;
                if (camPos.x == 0)
                    camPos.x = drawRect.x + drawRect.width / 2;
                if (camPos.y == 0)
                    camPos.y = -(drawRect.y + drawRect.height / 2);
                float cx = uvRect.x + (camPos.x - drawRect.x) / drawRect.width * uvRect.width;
                float cy = uvRect.y - (camPos.y - drawRect.y) / drawRect.height * uvRect.height;

                vertices[4] = new Vector3(camPos.x, camPos.y, 0);
                vertices[5] = new Vector3(drawRect.xMin, camPos.y, 0);
                vertices[6] = new Vector3(camPos.x, -drawRect.yMin, 0);
                vertices[7] = new Vector3(drawRect.xMax, camPos.y, 0);
                vertices[8] = new Vector3(camPos.x, -drawRect.yMax, 0);

                uv[4] = new Vector2(cx, cy);
                uv[5] = new Vector2(uvRect.xMin, cy);
                uv[6] = new Vector2(cx, uvRect.yMax);
                uv[7] = new Vector2(uvRect.xMax, cy);
                uv[8] = new Vector2(cx, uvRect.yMin);

                this.triangles = TRIANGLES_4_GRID;
            }
            else
            {
                Alloc(4);
                FillVerts(0, drawRect);
                FillUV(0, uvRect);
                this.triangles = TRIANGLES;
            }

            if (allColors != null)
            {
                Color32[] arr = this.colors;
                int count = arr.Length;
                for (int i = 0; i < count; i++)
                    arr[i] = allColors[i % allColors.Length];
            }
            else
                FillColors(color);
            UpdateMesh();
        }

Usage Example

 static public int SetOneQuadMesh(IntPtr l)
 {
     try {
         FairyGUI.NGraphics self = (FairyGUI.NGraphics)checkSelf(l);
         UnityEngine.Rect   a1;
         checkValueType(l, 2, out a1);
         UnityEngine.Rect a2;
         checkValueType(l, 3, out a2);
         UnityEngine.Color a3;
         checkType(l, 4, out a3);
         self.SetOneQuadMesh(a1, a2, a3);
         pushValue(l, true);
         return(1);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }