FairyGUI.Image.TileFill C# (CSharp) Method

TileFill() private method

private TileFill ( Rect destRect, Rect uvRect, float sourceW, float sourceH, int vertIndex ) : int
destRect UnityEngine.Rect
uvRect UnityEngine.Rect
sourceW float
sourceH float
vertIndex int
return int
        int TileFill(Rect destRect, Rect uvRect, float sourceW, float sourceH, int vertIndex)
        {
            int hc = Mathf.CeilToInt(destRect.width / sourceW);
            int vc = Mathf.CeilToInt(destRect.height / sourceH);
            float tailWidth = destRect.width - (hc - 1) * sourceW;
            float tailHeight = destRect.height - (vc - 1) * sourceH;

            if (vertIndex == -1)
            {
                graphics.Alloc(hc * vc * 4);
                vertIndex = 0;
            }

            for (int i = 0; i < hc; i++)
            {
                for (int j = 0; j < vc; j++)
                {
                    graphics.FillVerts(vertIndex, new Rect(destRect.x + i * sourceW, destRect.y + j * sourceH,
                            i == (hc - 1) ? tailWidth : sourceW, j == (vc - 1) ? tailHeight : sourceH));
                    Rect uvTmp = uvRect;
                    if (i == hc - 1)
                        uvTmp.xMax = Mathf.Lerp(uvRect.xMin, uvRect.xMax, tailWidth / sourceW);
                    if (j == vc - 1)
                        uvTmp.yMin = Mathf.Lerp(uvRect.yMin, uvRect.yMax, 1 -tailHeight / sourceH);

                    graphics.FillUV(vertIndex, uvTmp);
                    vertIndex += 4;
                }
            }

            return vertIndex;
        }