-
Notifications
You must be signed in to change notification settings - Fork 0
/
ResolutionChanger
52 lines (41 loc) · 1.49 KB
/
ResolutionChanger
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
using UnityEngine;
using UnityEngine.UI;
using System.Collections.Generic;
using TMPro;
public class ResolutionChanger : MonoBehaviour
{
public TMP_Dropdown resolutionDropdown;
private Resolution[] resolutions;
void Start()
{
// Get all available screen resolutions
resolutions = Screen.resolutions;
// Clearing the current list in dropdown
resolutionDropdown.ClearOptions();
// Creating a list of strings for permissions
List<string> options = new List<string>();
int currentResolutionIndex = 0;
for (int i = 0; i < resolutions.Length; i++)
{
// Correct access to Resolution properties
string option = resolutions[i].width + " x " + resolutions[i].height;
options.Add(option);
// Check resolution
if (resolutions[i].width == Screen.currentResolution.width &&
resolutions[i].height == Screen.currentResolution.height)
{
currentResolutionIndex = i;
}
}
// v
resolutionDropdown.AddOptions(options);
// Set the current resolution as selected in dropdown
resolutionDropdown.value = currentResolutionIndex;
resolutionDropdown.RefreshShownValue();
}
public void SetResolution(int resolutionIndex)
{
Resolution resolution = resolutions[resolutionIndex];
Screen.SetResolution(resolution.width, resolution.height, Screen.fullScreen);
}
}