Projext/Assets/7.Other Code/System_Scripts/SettingResolution.cs

59 lines
1.6 KiB
C#
Raw Normal View History

2026-01-30 09:27:44 +00:00
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>();
// <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20>ػ<EFBFBD><D8BB><EFBFBD> <20><><EFBFBD><EFBFBD>
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)
{
// <20>ߺ<EFBFBD> <20><><EFBFBD><EFBFBD>
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);
}
}