Beispiel #1
0
    private bool GetRect_sub(string name, int[] forceSize, out Vector2 perfectSize, out Vector2[] uvs, out RECTPATTERN pattern, out int[] size, out StrechMode mode) // size[]{top,bot,left,right};
    {
        perfectSize = Vector2.zero;
        uvs         = null; pattern = RECTPATTERN.ONE;
        size        = new int[] { 0, 0, 0, 0 };
        mode        = StrechMode.STRECH_CENTER;

        int topPx = 0, botPx = 0, leftPx = 0, rightPx = 0;

        DATA fd = null;

        for (int i = 0; i < list.Length; i++)
        {
            DATA d = list[i];
            if (d.texname == name)
            {
                fd          = d;
                mode        = fd.mode;
                perfectSize = new Vector2(fd.rect.width * width, fd.rect.height * height);
                if (forceSize != null && forceSize.Length == 4)
                {
                    topPx = forceSize[0]; botPx = forceSize[1]; leftPx = forceSize[2]; rightPx = forceSize[3];
                }
                else
                {
                    topPx = fd.topPx; botPx = fd.botPx; leftPx = fd.leftPx; rightPx = fd.rightPx;
                }
                break;
            }
        }
        if (fd == null)
        {
            return(false);
        }

        Rect r = fd.rect;

        if (fd.cutEdge)
        {
            r       = new Rect((fd.rect.xMin * width + 0.5f) / width, (fd.rect.yMin * height + 0.5f) / height, (fd.rect.width * width - 1) / width, (fd.rect.height * height - 1) / height);
            pattern = RECTPATTERN.ONE;
            uvs     = new Vector2[]
            {
                /*0*/ new Vector2(r.xMin, r.yMax),
                /*1*/ new Vector2(r.xMax, r.yMax),
                /*2*/ new Vector2(r.xMin, r.yMin),
                /*3*/ new Vector2(r.xMax, r.yMin)
            };
            return(true);
        }
        float tx = (float)topPx / height;
        float bx = (float)botPx / height;
        float lx = (float)leftPx / width;
        float rx = (float)rightPx / width;

        /*
         *  y [0][1]
         | [2][3]
         |  o--x
         */
        Vector2[] uvsBase = new Vector2[]
        {
            /*0*/ new Vector2(r.xMin, r.yMax),
            /*1*/ new Vector2(r.xMax, r.yMax),
            /*2*/ new Vector2(r.xMin, r.yMin),
            /*3*/ new Vector2(r.xMax, r.yMin)
        };
        pattern = RECTPATTERN.ONE;
        uvs     = uvsBase;
        if (tx == 0 && bx == 0 && rx == 0 && lx == 0)
        {
            return(true);
        }
        if (rx < 0 || lx < 0 || rx + lx > r.width)
        {
            return(false);
        }
        if (tx < 0 || bx < 0 || tx + bx > r.height)
        {
            return(false);
        }
        if (tx == 0 && bx == 0)
        {
            pattern = RECTPATTERN.THREEHORIZON;

            /*
             * y [0][1][2][3]
             | [4][5][6][7]
             | o--x
             */
            uvs = new Vector2[]
            {
                /*0*/ uvsBase[0],
                /*1*/ uvsBase[0] + lx * Vector2.right,
                /*2*/ uvsBase[1] - rx * Vector2.right,
                /*3*/ uvsBase[1],
                /*4*/ uvsBase[2],
                /*5*/ uvsBase[2] + lx * Vector2.right,
                /*6*/ uvsBase[3] - rx * Vector2.right,
                /*7*/ uvsBase[3]
            };

            size = new int[]
            {
                0, 0,
                leftPx, rightPx
            };
            return(true);
        }
        if (lx == 0 && rx == 0)
        {
            pattern = RECTPATTERN.THREEVERTIACAL;

            /*
             *  y [0][1]
             | [2][3]
             | [4][5]
             | [6][7]
             |  o--x
             */
            uvs = new Vector2[]
            {
                /*0*/ uvsBase[0],
                /*1*/ uvsBase[1],
                /*2*/ uvsBase[0] - tx * Vector2.up,
                /*3*/ uvsBase[1] - tx * Vector2.up,
                /*4*/ uvsBase[2] + bx * Vector2.up,
                /*5*/ uvsBase[3] + bx * Vector2.up,
                /*6*/ uvsBase[2],
                /*7*/ uvsBase[3],
            };
            size = new int[] {
                topPx, botPx,
                0, 0
            };
            return(true);
        }

        /*
         *  y [00][01][02][03]
         | [04][05][06][07]
         | [08][09][10][11]
         | [12][13][14][15]
         |  o--x
         */

        pattern = RECTPATTERN.NINE;
        uvs     = new Vector2[]
        {
            /*00*/ uvsBase[0],
            /*01*/ uvsBase[0] + lx * Vector2.right,
            /*02*/ uvsBase[1] - rx * Vector2.right,
            /*03*/ uvsBase[1],

            /*04*/ uvsBase[0] - tx * Vector2.up,
            /*05*/ uvsBase[0] + lx * Vector2.right - tx * Vector2.up,
            /*06*/ uvsBase[1] - rx * Vector2.right - tx * Vector2.up,
            /*07*/ uvsBase[1] - tx * Vector2.up,

            /*08*/ uvsBase[2] + bx * Vector2.up,
            /*09*/ uvsBase[2] + lx * Vector2.right + bx * Vector2.up,
            /*10*/ uvsBase[3] - lx * Vector2.right + bx * Vector2.up,
            /*11*/ uvsBase[3] + bx * Vector2.up,

            /*12*/ uvsBase[2],
            /*13*/ uvsBase[2] + lx * Vector2.right,
            /*14*/ uvsBase[3] - lx * Vector2.right,
            /*15*/ uvsBase[3]
        };
        size = new int[] {
            topPx, leftPx,
            leftPx, rightPx
        };

        return(true);
    }
Beispiel #2
0
 public DATA()
 {
     cutEdge = false; mode = StrechMode.STRECH_CENTER; topPx = botPx = leftPx = rightPx = 0;
 }
Beispiel #3
0
 public bool GetRect(string name, out Vector2 perfectSize, out Vector2[] uvs, out RECTPATTERN pattern, out int[] size, out StrechMode mode) // size[]{top,bot,left,right};
 {
     return(GetRect_sub(name, null, out perfectSize, out uvs, out pattern, out size, out mode));
 }