Code : Tout sélectionner
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class SelectResolution : MonoBehaviour
{
public Dropdown dropdown;
public int currentQuality;
public Toggle toggle;
public float currentFullScreen;
Resolution[] resolutions;
public Dropdown resolutionDropdown;
void Awake()
{
currentQuality = PlayerPrefs.GetInt("Quality");
dropdown.value = currentQuality;
currentFullScreen = PlayerPrefs.GetFloat("FullScreen");
if (currentFullScreen == 1)
{
toggle.GetComponent<Toggle>().isOn = true;
}
if (currentFullScreen == 0)
{
toggle.GetComponent<Toggle>().isOn = false;
}
}
void Start()
{
resolutions = Screen.resolutions;
resolutionDropdown.ClearOptions();
List<string> options = new List<string>();
int currentResolutionIndex = 0;
for (int i = 0; i < resolutions.Length; i++)
{
string option = resolutions[i].width + " x " + resolutions[i].height;
options.Add(option);
if (resolutions[i].width == Screen.currentResolution.width && resolutions[i].height == Screen.currentResolution.height)
{
currentResolutionIndex = i;
}
}
resolutionDropdown.AddOptions(options);
resolutionDropdown.value = currentResolutionIndex;
resolutionDropdown.RefreshShownValue();
}
public void SetResolution(int resolutionIndex)
{
Resolution resolution = resolutions[resolutionIndex];
Screen.SetResolution(resolution.width, resolution.height, Screen.fullScreen);
}
public void SetQuality(int qualityIndex)
{
QualitySettings.SetQualityLevel(qualityIndex);
}
public void SetDropdouwn()
{
currentQuality = dropdown.value;
PlayerPrefs.SetInt("Quality", currentQuality);
}
public void SetFullscreen(bool isFullscreen)
{
Screen.fullScreen = isFullscreen;
if (isFullscreen == true)
{
currentFullScreen = 1;
PlayerPrefs.SetFloat("FullScreen", currentFullScreen);
}
else
{
currentFullScreen = 0;
PlayerPrefs.SetFloat("FullScreen", currentFullScreen);
}
}
}
Code : Tout sélectionner
void Start()
{
resolutions = Screen.resolutions;
resolutionDropdown.ClearOptions();
List<string> options = new List<string>();
int currentResolutionIndex = 0;
for (int i = 0; i < resolutions.Length; i++)
{
string option = resolutions[i].width + " x " + resolutions[i].height;
options.Add(option);
if (resolutions[i].width == Screen.currentResolution.width && resolutions[i].height == Screen.currentResolution.height)
{
currentResolutionIndex = i;
}
}
resolutionDropdown.AddOptions(options);
resolutionDropdown.value = currentResolutionIndex;
resolutionDropdown.RefreshShownValue();
}
public void SetResolution(int resolutionIndex)
{
Resolution resolution = resolutions[resolutionIndex];
Screen.SetResolution(resolution.width, resolution.height, Screen.fullScreen);
}
Merci d'avance pour votre réponse.
PS: les image c'est le dropdown. Si vous avez besoins d'autre photo dite le moi.