using UnityEngine;
using System.Collections;
using UnityEngine.UI;

public class ResolutionDropdown : MonoBehaviour {

    private Dropdown dropdown;
    public Dropdown fullscreenDropdown;
    Resolution[] resolutions;

    private bool fullscreen;

	// Use this for initialization
	void Start ()
    {
        fullscreen = true;
        dropdown = GetComponent<Dropdown>();
        resolutions = Screen.resolutions;

        for (int i = 0; i < resolutions.Length; i++)
        {
            dropdown.options.Add(new Dropdown.OptionData(ResToString(resolutions[i])));
            dropdown.options[i].text = ResToString(resolutions[i]);
            dropdown.value = i;
        }

        ChangeResolution();
	}

    public void ChangeResolution()
    {
        Screen.SetResolution(resolutions[dropdown.value].width, resolutions[dropdown.value].height, fullscreen);
    }

    string ResToString(Resolution res)
    {
        return res.width + " x " + res.height;
    }

    public void ToggleFullscreen()
    {
        switch (fullscreenDropdown.value)
        {
            case 0:
                fullscreen = true;
                break;

            case 1:
                fullscreen = false;
                break;
        }

        ChangeResolution();
    }
}
