본문 바로가기
{Programing}/Game Engine

Unity - 모바일 해상도 고정 대응.

by 탱타로케이 2020. 6. 12.

Screen.SetResolution( width, Height, fullscreen)

으로 픽셀 해상도 고정 가능.

풀스크린 모드의 차이는 true 일때 화면 아래에 나오는 뒤로가기 홈버튼 이 나오지 않고

false일 때는 표시함.

 

void ResolutionFix()
    {

        float targetWidthAps = 16.0f;
        float targetHeightAps = 9.0f;

        Camera.main.aspect = targetWidthAps / targetHeightAps;

        float widthRatio = (float)Screen.width / targetWidthAps;
        float heightRatio = (float)Screen.height / targetHeightAps;

        float widthadd = ((heightRatio / (widthRatio / 100)) - 100) / 200;
        float heightadd = ((widthRatio / (heightRatio / 100)) - 100) / 200;

        if(heightRatio>widthRatio)
        {
            widthRatio = 0.0f;
        }
        else
        {
            heightRatio = 0.0f;
        }

        Camera.main.rect = new Rect(
            Camera.main.rect.x + Mathf.Abs(widthadd),
            Camera.main.rect.x + Mathf.Abs(heightadd),
            Camera.main.rect.width + (widthadd * 2),
            Camera.main.rect.height + (heightadd * 2));
    }

위 함수 같이 비율 계산을 통해 카메라에 보이는 화면을 잘라내어 비율 고정.

 

UI를 제외한 모든 화면비율을 자르는 것.

 

'{Programing} > Game Engine' 카테고리의 다른 글

unity - transform  (0) 2021.05.17
unity - key input 관련 내용  (0) 2021.05.12
Unity - Particle  (0) 2020.06.12
Unity - GameObject Find  (0) 2020.06.09
Unity - 매니저 클래스를 위한 singleton  (0) 2020.06.09

댓글