unity关于横屏适配--个人学习记录

最近做2D项目,遇见了ipa的屏幕,4:3,结果UI适配之后UI出现在游戏区域,不得不适配游戏区域,直接上代码:

//设计所用的尺寸    

 const float devHeight = 1080f;

    const float devWeight = 1920f;

    private void Start()
    {
        float screenHeight = Screen.height;


        float orthographicSize = this.GetComponent<Camera>().orthographicSize;


        float aspectRatio = Screen.width * 1.0f / Screen.height;//得到宽高比


        //实际的宽高比和摄像机的size来计算摄像机的宽
        float cameraWidth = orthographicSize * 2 * aspectRatio;
        if (cameraWidth < devHeight)
        {
            orthographicSize = devHeight / (2 * aspectRatio);
            this.GetComponent<Camera>().orthographicSize = orthographicSize / 50;
        }

    }


是根据大佬自己改了点,还是没明白,但是实现了。

猜你喜欢

转载自blog.csdn.net/Edision_li/article/details/80844823