ugui齐刘海,摄像头适配问题

https://zhuanlan.zhihu.com/p/124246847
https://blog.csdn.net/qq302756113/article/details/116134955

对于有齐刘海的手机,要单独做适配,具体代码:


public class XAdaptive
{
    public Vector2 left;
    public Vector2 right;
}

public ScreenOrientation m_currentOrientation = Screen.orientation;

public void CheckAdaptive()
    {
        if (Screen.orientation == m_currentOrientation) return;
        DebugLog.AddLog("CheckAdaptive:" + Screen.orientation);
        m_currentOrientation = Screen.orientation;
        CalAdaptive(ref m_xAdaptive);
        AdjustAdaptive(this.go);
    }

    private void CalAdaptive(ref XAdaptive adaptive)
    {
        DebugLog.AddLog("TimelineBaseUI Screen full:" + Screen.width + ":" + Screen.height);
        DebugLog.AddLog("TimelineBaseUI Screen Safearea:" + Screen.safeArea.width + ":" + Screen.safeArea.height + ":" + Screen.safeArea.min + ":" + Screen.safeArea.max);
        adaptive.left = new Vector2(Screen.safeArea.min.x / Screen.width * 1624, 0);
        adaptive.right = new Vector2((Screen.safeArea.max.x - Screen.width) / Screen.width * 1624, 0);
        DebugLog.AddLog("TimelineBaseUI adaptive:" + adaptive.left + ":" + adaptive.right);
    }
	//这里的1624可以去掉,直接用Screen.safeArea.min.x和Screen.safeArea.max.x - Screen.width即可
	
    public void AdjustAdaptive(GameObject go)
    {
        if (go == null) return;
        RectTransform rt = go.transform as RectTransform;
        if (rt == null) return;
        rt.offsetMin = m_xAdaptive.left;
        rt.offsetMax = m_xAdaptive.right;
        DebugLog.AddLog("AdjustAdaptive:" + rt.offsetMin + ":" + rt.offsetMax);
    }

这个要在Update中检测,手机翻转之后的样子:

在这里插入图片描述
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值