通过使用SafeArea,修改stretch适配类型的UI画布的Top偏移,适应安卓异型屏幕
/// <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);
}