예제 #1
0
    private void GenerateFilledSprite(List <UIVertex> vbo, bool preserveAspect)
    {
        if ((double)base.get_fillAmount() < 0.001)
        {
            return;
        }
        Vector4 drawingDimensions = this.GetDrawingDimensions(preserveAspect, Image2.s_sizeScaling[(int)this.alphaTexLayout]);
        Vector2 zero   = Vector2.zero;
        Vector4 vector = Vector4.zero;

        if (base.get_overrideSprite() != null)
        {
            vector = Image2.GetOuterUV(base.get_overrideSprite(), this.alphaTexLayout, out zero);
        }
        UIVertex simpleVert = UIVertex.simpleVert;

        simpleVert.color = base.get_color();
        float num  = vector.x;
        float num2 = vector.y;
        float num3 = vector.z;
        float num4 = vector.w;

        if (base.get_fillMethod() == null || base.get_fillMethod() == 1)
        {
            if (base.get_fillMethod() == null)
            {
                float num5 = (num3 - num) * base.get_fillAmount();
                if (base.get_fillOrigin() == 1)
                {
                    drawingDimensions.x = drawingDimensions.z - (drawingDimensions.z - drawingDimensions.x) * base.get_fillAmount();
                    num = num3 - num5;
                }
                else
                {
                    drawingDimensions.z = drawingDimensions.x + (drawingDimensions.z - drawingDimensions.x) * base.get_fillAmount();
                    num3 = num + num5;
                }
            }
            else if (base.get_fillMethod() == 1)
            {
                float num6 = (num4 - num2) * base.get_fillAmount();
                if (base.get_fillOrigin() == 1)
                {
                    drawingDimensions.y = drawingDimensions.w - (drawingDimensions.w - drawingDimensions.y) * base.get_fillAmount();
                    num2 = num4 - num6;
                }
                else
                {
                    drawingDimensions.w = drawingDimensions.y + (drawingDimensions.w - drawingDimensions.y) * base.get_fillAmount();
                    num4 = num2 + num6;
                }
            }
        }
        Image2.s_Xy[0] = new Vector2(drawingDimensions.x, drawingDimensions.y);
        Image2.s_Xy[1] = new Vector2(drawingDimensions.x, drawingDimensions.w);
        Image2.s_Xy[2] = new Vector2(drawingDimensions.z, drawingDimensions.w);
        Image2.s_Xy[3] = new Vector2(drawingDimensions.z, drawingDimensions.y);
        Image2.s_Uv[0] = new Vector2(num, num2);
        Image2.s_Uv[1] = new Vector2(num, num4);
        Image2.s_Uv[2] = new Vector2(num3, num4);
        Image2.s_Uv[3] = new Vector2(num3, num2);
        if ((double)base.get_fillAmount() < 1.0)
        {
            if (base.get_fillMethod() == 2)
            {
                if (!Image2.RadialCut(Image2.s_Xy, Image2.s_Uv, base.get_fillAmount(), base.get_fillClockwise(), base.get_fillOrigin()))
                {
                    return;
                }
                for (int i = 0; i < 4; i++)
                {
                    simpleVert.position = Image2.s_Xy[i];
                    simpleVert.uv0      = Image2.s_Uv[i];
                    simpleVert.uv1      = simpleVert.uv0 + zero;
                    vbo.Add(simpleVert);
                }
                return;
            }
            else
            {
                if (base.get_fillMethod() == 3)
                {
                    for (int j = 0; j < 2; j++)
                    {
                        int   num7 = (base.get_fillOrigin() <= 1) ? 0 : 1;
                        float t;
                        float t2;
                        float t3;
                        float t4;
                        if (base.get_fillOrigin() == 0 || base.get_fillOrigin() == 2)
                        {
                            t  = 0f;
                            t2 = 1f;
                            if (j == num7)
                            {
                                t3 = 0f;
                                t4 = 0.5f;
                            }
                            else
                            {
                                t3 = 0.5f;
                                t4 = 1f;
                            }
                        }
                        else
                        {
                            t3 = 0f;
                            t4 = 1f;
                            if (j == num7)
                            {
                                t  = 0.5f;
                                t2 = 1f;
                            }
                            else
                            {
                                t  = 0f;
                                t2 = 0.5f;
                            }
                        }
                        Image2.s_Xy[0].x = Mathf.Lerp(drawingDimensions.x, drawingDimensions.z, t3);
                        Image2.s_Xy[1].x = Image2.s_Xy[0].x;
                        Image2.s_Xy[2].x = Mathf.Lerp(drawingDimensions.x, drawingDimensions.z, t4);
                        Image2.s_Xy[3].x = Image2.s_Xy[2].x;
                        Image2.s_Xy[0].y = Mathf.Lerp(drawingDimensions.y, drawingDimensions.w, t);
                        Image2.s_Xy[1].y = Mathf.Lerp(drawingDimensions.y, drawingDimensions.w, t2);
                        Image2.s_Xy[2].y = Image2.s_Xy[1].y;
                        Image2.s_Xy[3].y = Image2.s_Xy[0].y;
                        Image2.s_Uv[0].x = Mathf.Lerp(num, num3, t3);
                        Image2.s_Uv[1].x = Image2.s_Uv[0].x;
                        Image2.s_Uv[2].x = Mathf.Lerp(num, num3, t4);
                        Image2.s_Uv[3].x = Image2.s_Uv[2].x;
                        Image2.s_Uv[0].y = Mathf.Lerp(num2, num4, t);
                        Image2.s_Uv[1].y = Mathf.Lerp(num2, num4, t2);
                        Image2.s_Uv[2].y = Image2.s_Uv[1].y;
                        Image2.s_Uv[3].y = Image2.s_Uv[0].y;
                        float value = (!base.get_fillClockwise()) ? (base.get_fillAmount() * 2f - (float)(1 - j)) : (base.get_fillAmount() * 2f - (float)j);
                        if (Image2.RadialCut(Image2.s_Xy, Image2.s_Uv, Mathf.Clamp01(value), base.get_fillClockwise(), (j + base.get_fillOrigin() + 3) % 4))
                        {
                            for (int k = 0; k < 4; k++)
                            {
                                simpleVert.position = Image2.s_Xy[k];
                                simpleVert.uv0      = Image2.s_Uv[k];
                                simpleVert.uv1      = simpleVert.uv0 + zero;
                                vbo.Add(simpleVert);
                            }
                        }
                    }
                    return;
                }
                if (base.get_fillMethod() == 4)
                {
                    for (int l = 0; l < 4; l++)
                    {
                        float t5;
                        float t6;
                        if (l < 2)
                        {
                            t5 = 0f;
                            t6 = 0.5f;
                        }
                        else
                        {
                            t5 = 0.5f;
                            t6 = 1f;
                        }
                        float t7;
                        float t8;
                        if (l == 0 || l == 3)
                        {
                            t7 = 0f;
                            t8 = 0.5f;
                        }
                        else
                        {
                            t7 = 0.5f;
                            t8 = 1f;
                        }
                        Image2.s_Xy[0].x = Mathf.Lerp(drawingDimensions.x, drawingDimensions.z, t5);
                        Image2.s_Xy[1].x = Image2.s_Xy[0].x;
                        Image2.s_Xy[2].x = Mathf.Lerp(drawingDimensions.x, drawingDimensions.z, t6);
                        Image2.s_Xy[3].x = Image2.s_Xy[2].x;
                        Image2.s_Xy[0].y = Mathf.Lerp(drawingDimensions.y, drawingDimensions.w, t7);
                        Image2.s_Xy[1].y = Mathf.Lerp(drawingDimensions.y, drawingDimensions.w, t8);
                        Image2.s_Xy[2].y = Image2.s_Xy[1].y;
                        Image2.s_Xy[3].y = Image2.s_Xy[0].y;
                        Image2.s_Uv[0].x = Mathf.Lerp(num, num3, t5);
                        Image2.s_Uv[1].x = Image2.s_Uv[0].x;
                        Image2.s_Uv[2].x = Mathf.Lerp(num, num3, t6);
                        Image2.s_Uv[3].x = Image2.s_Uv[2].x;
                        Image2.s_Uv[0].y = Mathf.Lerp(num2, num4, t7);
                        Image2.s_Uv[1].y = Mathf.Lerp(num2, num4, t8);
                        Image2.s_Uv[2].y = Image2.s_Uv[1].y;
                        Image2.s_Uv[3].y = Image2.s_Uv[0].y;
                        float value2 = (!base.get_fillClockwise()) ? (base.get_fillAmount() * 4f - (float)(3 - (l + base.get_fillOrigin()) % 4)) : (base.get_fillAmount() * 4f - (float)((l + base.get_fillOrigin()) % 4));
                        if (Image2.RadialCut(Image2.s_Xy, Image2.s_Uv, Mathf.Clamp01(value2), base.get_fillClockwise(), (l + 2) % 4))
                        {
                            for (int m = 0; m < 4; m++)
                            {
                                simpleVert.position = Image2.s_Xy[m];
                                simpleVert.uv0      = Image2.s_Uv[m];
                                simpleVert.uv1      = simpleVert.uv0 + zero;
                                vbo.Add(simpleVert);
                            }
                        }
                    }
                    return;
                }
            }
        }
        for (int n = 0; n < 4; n++)
        {
            simpleVert.position = Image2.s_Xy[n];
            simpleVert.uv0      = Image2.s_Uv[n];
            simpleVert.uv1      = simpleVert.uv0 + zero;
            vbo.Add(simpleVert);
        }
    }
예제 #2
0
    private void GenerateTiledSprite(List <UIVertex> vbo)
    {
        Vector2 zero;
        Vector4 vector;
        Vector4 vector2;
        Vector4 a;
        Vector2 vector3;

        if (base.get_overrideSprite() != null)
        {
            Vector2 sizeScaling = Image2.s_sizeScaling[(int)this.alphaTexLayout];
            vector     = Image2.GetOuterUV(base.get_overrideSprite(), this.alphaTexLayout, out zero);
            vector2    = Image2.GetInnerUV(base.get_overrideSprite(), sizeScaling);
            a          = base.get_overrideSprite().border;
            vector3    = base.get_overrideSprite().rect.size;
            vector3.x *= sizeScaling.x;
            vector3.y *= sizeScaling.y;
        }
        else
        {
            vector  = Vector4.zero;
            vector2 = Vector4.zero;
            a       = Vector4.zero;
            vector3 = Vector2.one * 100f;
            zero    = Vector2.zero;
        }
        Rect  pixelAdjustedRect = base.GetPixelAdjustedRect();
        float num  = (vector3.x - a.x - a.z) / base.get_pixelsPerUnit();
        float num2 = (vector3.y - a.y - a.w) / base.get_pixelsPerUnit();

        a = this.GetAdjustedBorders(a / base.get_pixelsPerUnit(), pixelAdjustedRect);
        Vector2  uvMin      = new Vector2(vector2.x, vector2.y);
        Vector2  vector4    = new Vector2(vector2.z, vector2.w);
        UIVertex simpleVert = UIVertex.simpleVert;

        simpleVert.color = base.get_color();
        float x    = a.x;
        float num3 = pixelAdjustedRect.width - a.z;
        float y    = a.y;
        float num4 = pixelAdjustedRect.height - a.w;

        if ((double)num3 - (double)x > (double)num * 100.0 || (double)num4 - (double)y > (double)num2 * 100.0)
        {
            num  = (float)(((double)num3 - (double)x) / 100.0);
            num2 = (float)(((double)num4 - (double)y) / 100.0);
        }
        Vector2 uvMax = vector4;

        if (base.get_fillCenter())
        {
            float num5 = y;
            while ((double)num5 < (double)num4)
            {
                float num6 = num5 + num2;
                if ((double)num6 > (double)num4)
                {
                    uvMax.y = uvMin.y + (float)(((double)vector4.y - (double)uvMin.y) * ((double)num4 - (double)num5) / ((double)num6 - (double)num5));
                    num6    = num4;
                }
                uvMax.x = vector4.x;
                float num7 = x;
                while ((double)num7 < (double)num3)
                {
                    float num8 = num7 + num;
                    if ((double)num8 > (double)num3)
                    {
                        uvMax.x = uvMin.x + (float)(((double)vector4.x - (double)uvMin.x) * ((double)num3 - (double)num7) / ((double)num8 - (double)num7));
                        num8    = num3;
                    }
                    this.AddQuad(vbo, simpleVert, new Vector2(num7, num5) + pixelAdjustedRect.position, new Vector2(num8, num6) + pixelAdjustedRect.position, uvMin, uvMax, zero);
                    num7 += num;
                }
                num5 += num2;
            }
        }
        if (!base.get_hasBorder())
        {
            return;
        }
        Vector2 vector5 = vector4;
        float   num9    = y;

        while ((double)num9 < (double)num4)
        {
            float num10 = num9 + num2;
            if ((double)num10 > (double)num4)
            {
                vector5.y = uvMin.y + (float)(((double)vector4.y - (double)uvMin.y) * ((double)num4 - (double)num9) / ((double)num10 - (double)num9));
                num10     = num4;
            }
            this.AddQuad(vbo, simpleVert, new Vector2(0f, num9) + pixelAdjustedRect.position, new Vector2(x, num10) + pixelAdjustedRect.position, new Vector2(vector.x, uvMin.y), new Vector2(uvMin.x, vector5.y), zero);
            this.AddQuad(vbo, simpleVert, new Vector2(num3, num9) + pixelAdjustedRect.position, new Vector2(pixelAdjustedRect.width, num10) + pixelAdjustedRect.position, new Vector2(vector4.x, uvMin.y), new Vector2(vector.z, vector5.y), zero);
            num9 += num2;
        }
        vector5 = vector4;
        float num11 = x;

        while ((double)num11 < (double)num3)
        {
            float num12 = num11 + num;
            if ((double)num12 > (double)num3)
            {
                vector5.x = uvMin.x + (float)(((double)vector4.x - (double)uvMin.x) * ((double)num3 - (double)num11) / ((double)num12 - (double)num11));
                num12     = num3;
            }
            this.AddQuad(vbo, simpleVert, new Vector2(num11, 0f) + pixelAdjustedRect.position, new Vector2(num12, y) + pixelAdjustedRect.position, new Vector2(uvMin.x, vector.y), new Vector2(vector5.x, uvMin.y), zero);
            this.AddQuad(vbo, simpleVert, new Vector2(num11, num4) + pixelAdjustedRect.position, new Vector2(num12, pixelAdjustedRect.height) + pixelAdjustedRect.position, new Vector2(uvMin.x, vector4.y), new Vector2(vector5.x, vector.w), zero);
            num11 += num;
        }
        this.AddQuad(vbo, simpleVert, new Vector2(0f, 0f) + pixelAdjustedRect.position, new Vector2(x, y) + pixelAdjustedRect.position, new Vector2(vector.x, vector.y), new Vector2(uvMin.x, uvMin.y), zero);
        this.AddQuad(vbo, simpleVert, new Vector2(num3, 0f) + pixelAdjustedRect.position, new Vector2(pixelAdjustedRect.width, y) + pixelAdjustedRect.position, new Vector2(vector4.x, vector.y), new Vector2(vector.z, uvMin.y), zero);
        this.AddQuad(vbo, simpleVert, new Vector2(0f, num4) + pixelAdjustedRect.position, new Vector2(x, pixelAdjustedRect.height) + pixelAdjustedRect.position, new Vector2(vector.x, vector4.y), new Vector2(uvMin.x, vector.w), zero);
        this.AddQuad(vbo, simpleVert, new Vector2(num3, num4) + pixelAdjustedRect.position, new Vector2(pixelAdjustedRect.width, pixelAdjustedRect.height) + pixelAdjustedRect.position, new Vector2(vector4.x, vector4.y), new Vector2(vector.z, vector.w), zero);
    }
예제 #3
0
 private void GenerateSlicedSprite(List <UIVertex> vbo)
 {
     if (!base.get_hasBorder())
     {
         this.GenerateSimpleSprite(vbo, false);
     }
     else
     {
         Vector2 zero = Vector2.zero;
         Vector4 vector;
         Vector4 vector2;
         Vector4 a;
         Vector4 a2;
         if (base.get_overrideSprite() != null)
         {
             vector  = Image2.GetOuterUV(base.get_overrideSprite(), this.alphaTexLayout, out zero);
             vector2 = Image2.GetInnerUV(base.get_overrideSprite(), Image2.s_sizeScaling[(int)this.alphaTexLayout]);
             a       = DataUtility.GetPadding(base.get_overrideSprite());
             a2      = base.get_overrideSprite().border;
         }
         else
         {
             vector  = Vector4.zero;
             vector2 = Vector4.zero;
             a       = Vector4.zero;
             a2      = Vector4.zero;
         }
         Rect    pixelAdjustedRect = base.GetPixelAdjustedRect();
         Vector4 adjustedBorders   = this.GetAdjustedBorders(a2 / base.get_pixelsPerUnit(), pixelAdjustedRect);
         Vector4 vector3           = a / base.get_pixelsPerUnit();
         Image2.s_VertScratch[0]   = new Vector2(vector3.x, vector3.y);
         Image2.s_VertScratch[3]   = new Vector2(pixelAdjustedRect.width - vector3.z, pixelAdjustedRect.height - vector3.w);
         Image2.s_VertScratch[1].x = adjustedBorders.x;
         Image2.s_VertScratch[1].y = adjustedBorders.y;
         Image2.s_VertScratch[2].x = pixelAdjustedRect.width - adjustedBorders.z;
         Image2.s_VertScratch[2].y = pixelAdjustedRect.height - adjustedBorders.w;
         for (int i = 0; i < 4; i++)
         {
             Vector2[] array = Image2.s_VertScratch;
             int       num   = i;
             array[num].x = array[num].x + pixelAdjustedRect.x;
             Vector2[] array2 = Image2.s_VertScratch;
             int       num2   = i;
             array2[num2].y = array2[num2].y + pixelAdjustedRect.y;
         }
         Image2.s_UVScratch[0] = new Vector2(vector.x, vector.y);
         Image2.s_UVScratch[1] = new Vector2(vector2.x, vector2.y);
         Image2.s_UVScratch[2] = new Vector2(vector2.z, vector2.w);
         Image2.s_UVScratch[3] = new Vector2(vector.z, vector.w);
         UIVertex simpleVert = UIVertex.simpleVert;
         simpleVert.color = base.get_color();
         for (int j = 0; j < 3; j++)
         {
             int num3 = j + 1;
             for (int k = 0; k < 3; k++)
             {
                 if (base.get_fillCenter() || j != 1 || k != 1)
                 {
                     int num4 = k + 1;
                     this.AddQuad(vbo, simpleVert, new Vector2(Image2.s_VertScratch[j].x, Image2.s_VertScratch[k].y), new Vector2(Image2.s_VertScratch[num3].x, Image2.s_VertScratch[num4].y), new Vector2(Image2.s_UVScratch[j].x, Image2.s_UVScratch[k].y), new Vector2(Image2.s_UVScratch[num3].x, Image2.s_UVScratch[num4].y), zero);
                 }
             }
         }
     }
 }