game logo (1)

This commit is contained in:
mangorifo
2024-02-16 16:21:09 +08:00
parent 159c74df2a
commit e2de50750c
9 changed files with 3182 additions and 537 deletions
@@ -0,0 +1,78 @@
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];
Screen.SetResolution(resolution.width, resolution.height, true);
fl = resolution.width;
fw = resolution.height;
PlayerPrefs.SetInt("ResolutionIndex", ResolutionIndex);
Debug.Log("Changed window resolution index in PlayerPrefs: " + PlayerPrefs.GetInt("ResolutionIndex"));
}
}