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で実行環境の情報を取得する方法

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

no image

UnityのHierarchyの順序をスクリプトから変更する

こんにちは、今日はUnityのHierarchyの順序をスクリプトから変更する方法についてまとめていきます。 確認環境 Unity 2018.4.15f1 Hierarchyの順序をスクリプトから変更 …

no image

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

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

no image

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

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

no image

Unityでアプリケーションのフルスクリーン切り替えキーを無効にする方法

こんにちは、今日はUnityでアプリケーションのフルスクリーン切り替えキーを無効にする方法についてまとめていきます。 確認環境 Unity 2018.4.15f1 フルスクリーン切り替えキーの有効/無 …