Projext/Assets/7.Other Code/System_Scripts/SettingResolution.cs
2026-01-30 18:27:44 +09:00

59 lines
1.6 KiB
C#

using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
public class SettingResolution : MonoBehaviour
{
[SerializeField] private TMP_Dropdown resDropDown;
private bool isFullScreen = true;
private List<Resolution> filteredResolutions = new List<Resolution>();
// 자주 쓰는 해상도 목록
private readonly Vector2Int[] commonResolutions =
{
new Vector2Int(1280, 720),
new Vector2Int(1280, 768),
new Vector2Int(1280, 800),
new Vector2Int(1360, 768),
new Vector2Int(1366, 768),
new Vector2Int(1680, 1050),
new Vector2Int(1920, 1080)
};
private void Start()
{
Resolution[] allResolutions = Screen.resolutions;
resDropDown.ClearOptions();
List<string> options = new List<string>();
foreach (var res in allResolutions)
{
foreach (var common in commonResolutions)
{
if (res.width == common.x && res.height == common.y)
{
// 중복 방지
if (!filteredResolutions.Exists(r => r.width == res.width && r.height == res.height))
{
filteredResolutions.Add(res);
options.Add($"{res.width} x {res.height}");
}
}
}
}
resDropDown.AddOptions(options);
}
public void ChangeResolution()
{
int index = resDropDown.value;
Resolution res = filteredResolutions[index];
Screen.SetResolution(res.width, res.height, isFullScreen);
}
}