通过使用SafeArea,修改stretch适配类型的UI画布的Top偏移,适应安卓异型屏幕文章来源地址https://www.toymoban.com/news/detail-778755.html
/// <summary>
/// 适配safeArea
/// </summary>
void FitSafeArea(Transform obj)
{
Rect safeArea = Screen.safeArea;
float y = Screen.height - safeArea.height;
RectTransform rectTrans = obj.GetComponent<RectTransform>();
SafeAreaOffect(rectTrans, y);
}
/// <summary>
/// 设置便宜
/// </summary>
/// <param name="rectTrans"></param>
/// <param name="size"></param>
void SafeAreaOffect(RectTransform rectTrans, float size)
{
rectTrans.offsetMax = new Vector2(rectTrans.offsetMax.x, -size);
}
文章来源:https://www.toymoban.com/news/detail-778755.html
到了这里,关于【Unity】SafeArea适配大小的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!