private Vector2 ResetSize(float _width, float _height, float screenWidth = 1920, float screenHeight = 1080)
{
float tempWidth;
float tempHeight;
if (_width < screenWidth && _height < screenHeight)
{
tempWidth = _width;
tempHeight = _height;
}
else
{
if (_width > _height)//当图片(长>高)
{
if (_width / _height > screenWidth / screenHeight)//当图片比例大于屏幕比例
{
tempWidth = screenWidth;
if (screenWidth < _width)
tempHeight = _height * (screenWidth / _width);
else
tempHeight = _height / (screenWidth / _width);
}
else
{
tempHeight = screenHeight;
if (screenHeight < _height)
tempWidth = _width * (screenHeight / _height);
else
tempWidth = _width / (screenHeight / _height);
}
}
else//当图片(长<=高)
{
tempHeight = screenHeight;
if (screenHeight > _height)
tempWidth = _width / (screenHeight / _height);
else
tempWidth = _width * (screenHeight / _height);
}
}
return new Vector2(tempWidth, tempHeight);
}
Unity 图片等比例自适应缩放
最新推荐文章于 2024-07-22 17:33:11 发布

2万+

被折叠的 条评论
为什么被折叠?



