こんにちは、今日はUnityでモニターがサポートするフルスクリーン解像度一覧を取得する方法についてまとめていきます。
Table of Contents
確認環境
Unity 2018.4.15f1
モニターがサポートするフルスクリーン解像度一覧の取得方法
以下のようにUnityEngine.Screenクラスに定義されているresolutionsから取得可能です。
Resolution[] resolutions = Screen.resolutions;https://docs.unity3d.com/ja/2018.4/ScriptReference/Screen-resolutions.html
解像度の変更方法
同じくUnityEngine.Screenクラスに定義されているSetResolution関数で解像度の変更が行えます。
Screen.SetResolution(640, 480, true);https://docs.unity3d.com/ja/current/ScriptReference/Screen.SetResolution.html
サンプル
Screen.resolutionsで取得した解像度をConsoleウィンドウに出力するサンプルです。
 Screen.resolutionsのヘルプページにあるものと同じものです。
using UnityEngine;
public class ExampleScript : MonoBehaviour
{
    void Start()
    {
        Resolution[] resolutions = Screen.resolutions;
        // Print the resolutions
        foreach (var res in resolutions)
        {
            Debug.Log(res.width + "x" + res.height + " : " + res.refreshRate);
        }
    }
}