2024-02-16 16:21:09 +08:00
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
using TMPro;
|
|
|
|
|
public class ListGameResolutions : MonoBehaviour
|
|
|
|
|
{
|
|
|
|
|
public TMP_Dropdown ResolutionDropdown;
|
|
|
|
|
private List<Resolution> FilteredResolutions;
|
|
|
|
|
//int DropdownResolutionValue;
|
|
|
|
|
private Resolution[] resolutions;
|
|
|
|
|
private float currentRefreshrate;
|
|
|
|
|
private int currentResolutionIndex = 0;
|
|
|
|
|
private int fl;
|
|
|
|
|
private int fw;
|
|
|
|
|
|
|
|
|
|
public static string ToAspectRatio(int width, int height)
|
|
|
|
|
{
|
|
|
|
|
int r;
|
|
|
|
|
int oa = width;
|
|
|
|
|
int ob = height;
|
|
|
|
|
while (height != 0)
|
|
|
|
|
{
|
|
|
|
|
r = width % height;
|
|
|
|
|
width = height;
|
|
|
|
|
height = r;
|
|
|
|
|
}
|
|
|
|
|
return (oa / width).ToString() + ":" + (ob / width).ToString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Start()
|
|
|
|
|
{
|
|
|
|
|
if (ResolutionDropdown)
|
|
|
|
|
{
|
|
|
|
|
resolutions = Screen.resolutions;
|
|
|
|
|
FilteredResolutions = new List<Resolution>();
|
|
|
|
|
ResolutionDropdown.ClearOptions();
|
|
|
|
|
currentRefreshrate = Screen.currentResolution.refreshRate;
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < resolutions.Length; i++)
|
|
|
|
|
{
|
|
|
|
|
if (resolutions[i].refreshRate == currentRefreshrate)
|
|
|
|
|
{
|
|
|
|
|
FilteredResolutions.Add(resolutions[i]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
List<string> options = new List<string>();
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < FilteredResolutions.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
if (ToAspectRatio(FilteredResolutions[i].width, FilteredResolutions[i].height) == "16:9")
|
|
|
|
|
{
|
|
|
|
|
string ResolOption = FilteredResolutions[i].width + "x" + FilteredResolutions[i].height;
|
|
|
|
|
options.Add(ResolOption);
|
|
|
|
|
|
|
|
|
|
if (FilteredResolutions[i].width == Screen.width && FilteredResolutions[i].height == Screen.height)
|
|
|
|
|
{
|
|
|
|
|
currentResolutionIndex = i;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
ResolutionDropdown.AddOptions(options);
|
|
|
|
|
ResolutionDropdown.value = currentResolutionIndex;
|
|
|
|
|
ResolutionDropdown.RefreshShownValue();
|
|
|
|
|
//}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SetWindowResolution(int ResolutionIndex)
|
|
|
|
|
{
|
|
|
|
|
Resolution resolution = FilteredResolutions[ResolutionIndex];
|
2024-03-08 15:49:30 +08:00
|
|
|
//Screen.SetResolution(resolution.width, resolution.height, true);
|
2024-02-16 16:21:09 +08:00
|
|
|
fl = resolution.width;
|
|
|
|
|
fw = resolution.height;
|
2024-03-08 15:49:30 +08:00
|
|
|
//PlayerPrefs.SetInt("ResolutionIndex", ResolutionIndex);
|
2024-02-16 16:21:09 +08:00
|
|
|
Debug.Log("Changed window resolution index in PlayerPrefs: " + PlayerPrefs.GetInt("ResolutionIndex"));
|
|
|
|
|
}
|
|
|
|
|
}
|