void GenerateGrids(Rect gridRect, Rect uvRect)
{
float sx = uvRect.width / (float)_texture.width;
float sy = uvRect.height / (float)_texture.height;
gridTexX[0] = uvRect.xMin;
gridTexX[1] = uvRect.xMin + gridRect.xMin * sx;
gridTexX[2] = uvRect.xMin + gridRect.xMax * sx;
gridTexX[3] = uvRect.xMax;
gridTexY[0] = uvRect.yMax;
gridTexY[1] = uvRect.yMax - gridRect.yMin * sy;
gridTexY[2] = uvRect.yMax - gridRect.yMax * sy;
gridTexY[3] = uvRect.yMin;
if (_contentRect.width >= (_texture.width - gridRect.width))
{
gridX[1] = gridRect.xMin;
gridX[2] = _contentRect.width - (_texture.width - gridRect.xMax);
gridX[3] = _contentRect.width;
}
else
{
float tmp = gridRect.xMin / (_texture.width - gridRect.xMax);
tmp = _contentRect.width * tmp / (1 + tmp);
gridX[1] = tmp;
gridX[2] = tmp;
gridX[3] = _contentRect.width;
}
if (_contentRect.height >= (_texture.height - gridRect.height))
{
gridY[1] = gridRect.yMin;
gridY[2] = _contentRect.height - (_texture.height - gridRect.yMax);
gridY[3] = _contentRect.height;
}
else
{
float tmp = gridRect.yMin / (_texture.height - gridRect.yMax);
tmp = _contentRect.height * tmp / (1 + tmp);
gridY[1] = tmp;
gridY[2] = tmp;
gridY[3] = _contentRect.height;
}
}