-
유니티 화면 비율 고정 처리...23일지 2021. 12. 10. 20:12
전체 화면에서 비율 고정 처리
전체 화면(Alt + Enter)에 진입했을 때 화면이 모니터 모양으로 바뀌는 게 아닌 지정된 비율로 적용되도록 처리한다.
ResolutionController.cs
public class ResolutionController : MonoBehaviour { // 생략 private bool m_fullscreen; // 생략 /// <summary> /// 초기화 하며 필요한 값을 미리 가져온다. /// </summary> private void Initialize() { // 생략 m_hwnd = FindWindow(null, "FixedResolution_DetectByCursorIcon"); GetWindowRect(m_hwnd, out m_wndRect); m_updateState = UpdateState.Waiting; UpdateDebugText(); StartCoroutine(SetFixedResolution()); } private void Update() { IntPtr hCursor = GetCursor(); if (m_fullscreen != Screen.fullScreen) { m_fullscreen = Screen.fullScreen; if (m_fullscreen) { int width = Display.main.systemWidth; int height = Display.main.systemHeight; GetAdjustedSize(ref width, ref height, ResizeOption.Horizontal); Screen.SetResolution(width, height, true); } else { Screen.SetResolution(m_screenSizeX, m_screenSizeY, false); } } // 생략 }
기본적으로 전체화면으로전체 화면으로 전환했을 때 모니터의 물리적인 크기를 기준으로 비율을 정해서 전체 화면으로 전환시키게 했다. 추가로, 최초 실행 시 화면 비율을 적용하지 않는 것을 발견해서 최초 실행 시에 화면 비율을 변경하도록 처리했다.