Mobile Aspect Ratio - TeamCrazyPerformance/Game_study GitHub Wiki

준비

  • 빌드 세팅을 안드로이드로 설정
  • image
  • 모바일 해상도 조사 및 선정(2160 * 1080 Landscape)
  • canvas 설정
  • image
  • ProjectSetting에서 화면 회전 설정
  • image

CameraResolution

  • 모든 씬 카메라에 적용

public class CameraResolution : MonoBehaviour
{
    void Awake()
    {
        Camera camera = GetComponent();
        Rect rect = camera.rect;
        float scaleheight = ((float)Screen.width / Screen.height) / ((float)16 / 9); // (세로 / 가로)
        float scalewidth = 1f / scaleheight;
        if (scaleheight < 1)
        {
            rect.height = scaleheight;
            rect.y = (1f - scaleheight) / 2f;
        }
        else
        {
            rect.width = scalewidth;
            rect.x = (1f - scalewidth) / 2f;
        }
        camera.rect = rect;
    }

    void OnPreCull() => GL.Clear(true, true, Color.black);
}

참고

19오성혁

⚠️ **GitHub.com Fallback** ⚠️