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

メールアドレスが公開されることはありません。 が付いている欄は必須項目です


reCaptcha の認証期間が終了しました。ページを再読み込みしてください。

関連記事

no image

Unity2019でMapboxを使用する

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

no image

Unityのオブジェクトが使用しているメモリ量を取得する

こんにちは、今日はUnityのオブジェクトが使用しているメモリ量を取得する方法についてまとめていきます。 確認環境 Unity 2018.4.15f1 Unityオブジェクトの使用メモリ量取得 以下の …

no image

Unityでアプリケーションの多重起動を制限する方法

こんにちは、今日はUnityでアプリケーションの多重起動を制限する方法についてまとめていきます。 確認環境 Unity 2018.4.15f1 アプリケーションの多重起動を制限する Edit > Pr …

no image

Unityで0から指定範囲の間を行き来する数値を取得できる関数Mathf.PingPong

確認環境 Unity 2018.4.15f1 使い方 public static float PingPong(float t, float length); UnityEngine.Mathfに定義 …

no image

UnityのProfilerの使い方

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