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でPowerShellの実行結果を取得する

以下の例ではGet-ChildItemコマンドレットを引数なしで実行、標準出力への出力をDebug.LogでUnityコンソールに出力しています。 System.Diagnostics.Process …

no image

Unity – UIのButtonにイベントを設定する方法まとめ

こんにちは、今日はUnityでUIのButtonクリック時に発生するイベントを設定する方法についてまとめていきます。 HierarchyウィンドウからCreate > UI > Buttonを選択や、 …

no image

Unityで実行環境の情報を取得する方法

System.Environmentクラスで現在の環境についての情報が取得できます。 OSバージョン System.OperatingSystem os = System.Environment.OS …

no image

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

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

no image

Unityでカスタムのdefineを追加する方法

こんにちは、今日はUnityでカスタムのdefineを追加する方法についてまとめていきます。 確認環境 Unity 2018.4.15f1 カスタムのdefineを追加する UnityのメニューのEd …