fix: 모바일 기기의 SafeArea에 맞춰 화면 비율 고정 로직 적용

This commit is contained in:
aube.lee
2025-03-06 00:08:03 +09:00
parent 8f69ecc429
commit 7fa43b35b4
22 changed files with 844 additions and 196 deletions

View File

@@ -0,0 +1,37 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace TON
{
public class CameraResolution : MonoBehaviour
{
private void Start()
{
SetResolution(); // 초기에 게임 해상도 고정
}
/* 해상도 설정하는 함수 */
public void SetResolution()
{
int setWidth = 1920; // 사용자 설정 너비
int setHeight = 1080; // 사용자 설정 높이
int deviceWidth = Screen.width; // 기기 너비 저장
int deviceHeight = Screen.height; // 기기 높이 저장
Screen.SetResolution(setWidth, (int)(((float)deviceHeight / deviceWidth) * setWidth), true); // SetResolution 함수 제대로 사용하기
if ((float)setWidth / setHeight < (float)deviceWidth / deviceHeight) // 기기의 해상도 비가 더 큰 경우
{
float newWidth = ((float)setWidth / setHeight) / ((float)deviceWidth / deviceHeight); // 새로운 너비
Camera.main.rect = new Rect((1f - newWidth) / 2f, 0f, newWidth, 1f); // 새로운 Rect 적용
}
else // 게임의 해상도 비가 더 큰 경우
{
float newHeight = ((float)deviceWidth / deviceHeight) / ((float)setWidth / setHeight); // 새로운 높이
Camera.main.rect = new Rect(0f, (1f - newHeight) / 2f, 1f, newHeight); // 새로운 Rect 적용
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: eadc9322e4859cf439f92413ff4636d9
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,32 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace TON
{
public class RectHelper : MonoBehaviour
{
Vector2 minAnchor;
Vector2 maxAnchor;
private void Start()
{
var Myrect = this.GetComponent<RectTransform>();
minAnchor = Screen.safeArea.min;
maxAnchor = Screen.safeArea.max;
minAnchor.x /= Screen.width;
minAnchor.y /= Screen.height;
maxAnchor.x /= Screen.width;
maxAnchor.y /= Screen.height;
Myrect.anchorMin = minAnchor;
Myrect.anchorMax = maxAnchor;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 196728227d77b9440af7a0e6102e7a6e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -38,7 +38,7 @@ namespace TON
if (index == guideList.Count - 1)
{
UIManager.Hide<GuideUI>(UIList.GuideUI);
UIManager.Show<LobbyUI>(UIList.LobbyUI);
return;
}

View File

@@ -145,6 +145,7 @@ namespace TON
public void OnClickGuideButton()
{
UIManager.Show<GuideUI>(UIList.GuideUI);
UIManager.Hide<LobbyUI>(UIList.LobbyUI);
}
}
}