3テラバイト

プログラム関連備忘録サイト。主にゲーム。

Unity

Unity – モニターがサポートするフルスクリーン解像度一覧を取得する

投稿日:2020年6月9日 更新日:

こんにちは、今日はUnityでモニターがサポートするフルスクリーン解像度一覧を取得する方法についてまとめていきます。

確認環境

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);
        }
    }
}

-Unity


comment

メールアドレスが公開されることはありません。

関連記事

no image

UnityのGUI.Labelのサイズを取得する

こんにちは、今日はUnityのGUI.Labelのサイズを取得する方法についてまとめていきます。 確認環境 Unity 2018.4.15f1 GUI.Labelのサイズを取得する string st …

no image

簡易逆ジオコーディングサービスをUnityで使う

農研機構が提供しているWebサービス、簡易逆ジオコーディングサービスをUnityから使用してみます。https://aginfo.cgk.affrc.go.jp/rgeocode/index.html …

no image

UnityのProfilerの使い方

確認環境 Unity 2018.4.15f1 Profiler ウィンドウの開き方 Window > Analysis > Profiler から Profiler ウィンドウ を開きます。 Prof …

no image

Unity2019でMapboxを使用する

確認環境 Unity Version 2019.4.28f1mapbox-unity-sdk_v2.1.1 Unity2020で使用する場合の記事は以下です。 Unity2020でMapboxを使用す …

no image

Unityで発生するWarning CS0649の対処方法

こんにちは、今日はUnityのC#スクリプトで発生するWarning CS0649の対処方法についてまとめていきます。 確認環境 Unity 2018.4.15f1 発生原因 以下のようなコードでスク …