UnityEngine.UI.Image.GenerateTiledSprite C# (CSharp) Method

GenerateTiledSprite() private method

private GenerateTiledSprite ( VertexHelper toFill ) : void
toFill VertexHelper
return void
        private void GenerateTiledSprite(VertexHelper toFill)
        {
            Vector4 outerUV;
            Vector4 innerUV;
            Vector4 adjustedBorders;
            Vector2 size;
            if (this.activeSprite != null)
            {
                outerUV = DataUtility.GetOuterUV(this.activeSprite);
                innerUV = DataUtility.GetInnerUV(this.activeSprite);
                adjustedBorders = this.activeSprite.border;
                size = this.activeSprite.rect.size;
            }
            else
            {
                outerUV = Vector4.zero;
                innerUV = Vector4.zero;
                adjustedBorders = Vector4.zero;
                size = (Vector2) (Vector2.one * 100f);
            }
            Rect pixelAdjustedRect = base.GetPixelAdjustedRect();
            float num = ((size.x - adjustedBorders.x) - adjustedBorders.z) / this.pixelsPerUnit;
            float num2 = ((size.y - adjustedBorders.y) - adjustedBorders.w) / this.pixelsPerUnit;
            adjustedBorders = this.GetAdjustedBorders((Vector4) (adjustedBorders / this.pixelsPerUnit), pixelAdjustedRect);
            Vector2 uvMin = new Vector2(innerUV.x, innerUV.y);
            Vector2 a = new Vector2(innerUV.z, innerUV.w);
            float x = adjustedBorders.x;
            float num4 = pixelAdjustedRect.width - adjustedBorders.z;
            float y = adjustedBorders.y;
            float num6 = pixelAdjustedRect.height - adjustedBorders.w;
            toFill.Clear();
            Vector2 uvMax = a;
            if (num <= 0f)
            {
                num = num4 - x;
            }
            if (num2 <= 0f)
            {
                num2 = num6 - y;
            }
            if ((this.activeSprite != null) && ((this.hasBorder || this.activeSprite.packed) || (this.activeSprite.texture.wrapMode != TextureWrapMode.Repeat)))
            {
                int num7 = 0;
                int num8 = 0;
                if (this.m_FillCenter)
                {
                    num7 = (int) Math.Ceiling((double) ((num4 - x) / num));
                    num8 = (int) Math.Ceiling((double) ((num6 - y) / num2));
                    int num9 = 0;
                    if (this.hasBorder)
                    {
                        num9 = ((num7 + 2) * (num8 + 2)) * 4;
                    }
                    else
                    {
                        num9 = (num7 * num8) * 4;
                    }
                    if (num9 > 0xfde8)
                    {
                        double num11;
                        Debug.LogError("Too many sprite tiles on Image \"" + base.name + "\". The tile size will be increased. To remove the limit on the number of tiles, convert the Sprite to an Advanced texture, remove the borders, clear the Packing tag and set the Wrap mode to Repeat.", this);
                        double num10 = 16250.0;
                        if (this.hasBorder)
                        {
                            num11 = (num7 + 2.0) / (num8 + 2.0);
                        }
                        else
                        {
                            num11 = ((double) num7) / ((double) num8);
                        }
                        double d = Math.Sqrt(num10 / num11);
                        double num13 = d * num11;
                        if (this.hasBorder)
                        {
                            d -= 2.0;
                            num13 -= 2.0;
                        }
                        num7 = (int) Math.Floor(d);
                        num8 = (int) Math.Floor(num13);
                        num = (num4 - x) / ((float) num7);
                        num2 = (num6 - y) / ((float) num8);
                    }
                }
                else if (this.hasBorder)
                {
                    num7 = (int) Math.Ceiling((double) ((num4 - x) / num));
                    num8 = (int) Math.Ceiling((double) ((num6 - y) / num2));
                    int num14 = (((num8 + num7) + 2) * 2) * 4;
                    if (num14 > 0xfde8)
                    {
                        Debug.LogError("Too many sprite tiles on Image \"" + base.name + "\". The tile size will be increased. To remove the limit on the number of tiles, convert the Sprite to an Advanced texture, remove the borders, clear the Packing tag and set the Wrap mode to Repeat.", this);
                        double num15 = 16250.0;
                        double num16 = ((double) num7) / ((double) num8);
                        double num17 = (num15 - 4.0) / (2.0 * (1.0 + num16));
                        double num18 = num17 * num16;
                        num7 = (int) Math.Floor(num17);
                        num8 = (int) Math.Floor(num18);
                        num = (num4 - x) / ((float) num7);
                        num2 = (num6 - y) / ((float) num8);
                    }
                }
                else
                {
                    num8 = num7 = 0;
                }
                if (this.m_FillCenter)
                {
                    for (int i = 0; i < num8; i++)
                    {
                        float num20 = y + (i * num2);
                        float num21 = y + ((i + 1) * num2);
                        if (num21 > num6)
                        {
                            uvMax.y = uvMin.y + (((a.y - uvMin.y) * (num6 - num20)) / (num21 - num20));
                            num21 = num6;
                        }
                        uvMax.x = a.x;
                        for (int j = 0; j < num7; j++)
                        {
                            float num23 = x + (j * num);
                            float num24 = x + ((j + 1) * num);
                            if (num24 > num4)
                            {
                                uvMax.x = uvMin.x + (((a.x - uvMin.x) * (num4 - num23)) / (num24 - num23));
                                num24 = num4;
                            }
                            AddQuad(toFill, new Vector2(num23, num20) + pixelAdjustedRect.position, new Vector2(num24, num21) + pixelAdjustedRect.position, this.color, uvMin, uvMax);
                        }
                    }
                }
                if (this.hasBorder)
                {
                    uvMax = a;
                    for (int k = 0; k < num8; k++)
                    {
                        float num26 = y + (k * num2);
                        float num27 = y + ((k + 1) * num2);
                        if (num27 > num6)
                        {
                            uvMax.y = uvMin.y + (((a.y - uvMin.y) * (num6 - num26)) / (num27 - num26));
                            num27 = num6;
                        }
                        AddQuad(toFill, new Vector2(0f, num26) + pixelAdjustedRect.position, new Vector2(x, num27) + pixelAdjustedRect.position, this.color, new Vector2(outerUV.x, uvMin.y), new Vector2(uvMin.x, uvMax.y));
                        AddQuad(toFill, new Vector2(num4, num26) + pixelAdjustedRect.position, new Vector2(pixelAdjustedRect.width, num27) + pixelAdjustedRect.position, this.color, new Vector2(a.x, uvMin.y), new Vector2(outerUV.z, uvMax.y));
                    }
                    uvMax = a;
                    for (int m = 0; m < num7; m++)
                    {
                        float num29 = x + (m * num);
                        float num30 = x + ((m + 1) * num);
                        if (num30 > num4)
                        {
                            uvMax.x = uvMin.x + (((a.x - uvMin.x) * (num4 - num29)) / (num30 - num29));
                            num30 = num4;
                        }
                        AddQuad(toFill, new Vector2(num29, 0f) + pixelAdjustedRect.position, new Vector2(num30, y) + pixelAdjustedRect.position, this.color, new Vector2(uvMin.x, outerUV.y), new Vector2(uvMax.x, uvMin.y));
                        AddQuad(toFill, new Vector2(num29, num6) + pixelAdjustedRect.position, new Vector2(num30, pixelAdjustedRect.height) + pixelAdjustedRect.position, this.color, new Vector2(uvMin.x, a.y), new Vector2(uvMax.x, outerUV.w));
                    }
                    AddQuad(toFill, new Vector2(0f, 0f) + pixelAdjustedRect.position, new Vector2(x, y) + pixelAdjustedRect.position, this.color, new Vector2(outerUV.x, outerUV.y), new Vector2(uvMin.x, uvMin.y));
                    AddQuad(toFill, new Vector2(num4, 0f) + pixelAdjustedRect.position, new Vector2(pixelAdjustedRect.width, y) + pixelAdjustedRect.position, this.color, new Vector2(a.x, outerUV.y), new Vector2(outerUV.z, uvMin.y));
                    AddQuad(toFill, new Vector2(0f, num6) + pixelAdjustedRect.position, new Vector2(x, pixelAdjustedRect.height) + pixelAdjustedRect.position, this.color, new Vector2(outerUV.x, a.y), new Vector2(uvMin.x, outerUV.w));
                    AddQuad(toFill, new Vector2(num4, num6) + pixelAdjustedRect.position, new Vector2(pixelAdjustedRect.width, pixelAdjustedRect.height) + pixelAdjustedRect.position, this.color, new Vector2(a.x, a.y), new Vector2(outerUV.z, outerUV.w));
                }
            }
            else
            {
                Vector2 b = new Vector2((num4 - x) / num, (num6 - y) / num2);
                if (this.m_FillCenter)
                {
                    AddQuad(toFill, new Vector2(x, y) + pixelAdjustedRect.position, new Vector2(num4, num6) + pixelAdjustedRect.position, this.color, Vector2.Scale(uvMin, b), Vector2.Scale(a, b));
                }
            }
        }