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

Unityで使用するコンパイラーを切り替える方法

こんにちは、今日はUnityで使用するC#コンパイラーを切り替える方法についてまとめていきます。 確認環境 Unity 2018.4.15f1 設定方法 Edit > Project Settings …

no image

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

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

no image

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

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

no image

Unityエディタ上で使用できるダイアログを表示する方法

EditorUtility.DisplayDialog関数でダイアログの表示が可能です。 bool isOK = EditorUtility.DisplayDialog("Title&quo …

no image

Unityで古いプロジェクトを開いた際に表示されるAPI Update Requiredダイアログ

確認環境 Unity 2019.4.28f1 表示内容 This project contains scripts and/or assemblies that use obsolete APIs.I …