🐈

Unityで動作しているPCの情報を取得できるSystemInfoというクラス

2023/08/08に公開

なぜ

複数のプラットフォームやスペックによっては機能を制限しなきゃ動かないことがありますよね。
その時の解決手段の一つとして動作するPCの情報を所得してそこから判別させるというものがあります。
UnityではSystemInfoというクラスがその情報を保持しているようだ。
早速みていこう

デバッグログに表示させる

コード

  private void Start()
    {
        LogAllSystemInfo();
    }

    private void LogAllSystemInfo()
    {
        Debug.Log("batteryLevel: " + SystemInfo.batteryLevel);
        Debug.Log("batteryStatus: " + SystemInfo.batteryStatus);
        Debug.Log("copyTextureSupport: " + SystemInfo.copyTextureSupport);
        Debug.Log("deviceModel: " + SystemInfo.deviceModel);
        Debug.Log("deviceName: " + SystemInfo.deviceName);
        Debug.Log("deviceType: " + SystemInfo.deviceType);
        Debug.Log("deviceUniqueIdentifier: " + SystemInfo.deviceUniqueIdentifier);
        Debug.Log("graphicsDeviceID: " + SystemInfo.graphicsDeviceID);
        Debug.Log("graphicsDeviceName: " + SystemInfo.graphicsDeviceName);
        Debug.Log("graphicsDeviceType: " + SystemInfo.graphicsDeviceType);
        Debug.Log("graphicsDeviceVendor: " + SystemInfo.graphicsDeviceVendor);
        Debug.Log("graphicsDeviceVendorID: " + SystemInfo.graphicsDeviceVendorID);
        Debug.Log("graphicsDeviceVersion: " + SystemInfo.graphicsDeviceVersion);
        Debug.Log("graphicsMemorySize: " + SystemInfo.graphicsMemorySize);
        Debug.Log("graphicsMultiThreaded: " + SystemInfo.graphicsMultiThreaded);
        Debug.Log("graphicsShaderLevel: " + SystemInfo.graphicsShaderLevel);
        Debug.Log("graphicsUVStartsAtTop: " + SystemInfo.graphicsUVStartsAtTop);
        Debug.Log("maxTextureSize: " + SystemInfo.maxTextureSize);
        Debug.Log("npotSupport: " + SystemInfo.npotSupport);
        Debug.Log("operatingSystem: " + SystemInfo.operatingSystem);
        Debug.Log("operatingSystemFamily: " + SystemInfo.operatingSystemFamily);
        Debug.Log("processorCount: " + SystemInfo.processorCount);
        Debug.Log("processorFrequency: " + SystemInfo.processorFrequency);
        Debug.Log("processorType: " + SystemInfo.processorType);
        Debug.Log("supportedRenderTargetCount: " + SystemInfo.supportedRenderTargetCount);
        Debug.Log("supports2DArrayTextures: " + SystemInfo.supports2DArrayTextures);
        Debug.Log("supports3DRenderTextures: " + SystemInfo.supports3DRenderTextures);
        Debug.Log("supportsAccelerometer: " + SystemInfo.supportsAccelerometer);
        Debug.Log("supportsAudio: " + SystemInfo.supportsAudio);
        Debug.Log("supportsComputeShaders: " + SystemInfo.supportsComputeShaders);
        Debug.Log("supportsGyroscope: " + SystemInfo.supportsGyroscope);
        Debug.Log("supportsImageEffects: " + SystemInfo.supportsImageEffects);
        Debug.Log("supportsInstancing: " + SystemInfo.supportsInstancing);
        Debug.Log("supportsLocationService: " + SystemInfo.supportsLocationService);
        Debug.Log("supportsMipStreaming: " + SystemInfo.supportsMipStreaming);
        Debug.Log("supportsMotionVectors: " + SystemInfo.supportsMotionVectors);
        Debug.Log("supportsRawShadowDepthSampling: " + SystemInfo.supportsRawShadowDepthSampling);
        Debug.Log("supportsShadows: " + SystemInfo.supportsShadows);
        Debug.Log("supportsSparseTextures: " + SystemInfo.supportsSparseTextures);
        Debug.Log("supportsVibration: " + SystemInfo.supportsVibration);
        Debug.Log("systemMemorySize: " + SystemInfo.systemMemorySize);
        Debug.Log("unsupportedIdentifier: " + SystemInfo.unsupportedIdentifier);
        Debug.Log("usesReversedZBuffer: " + SystemInfo.usesReversedZBuffer);
    }

思いの外めちゃくちゃたくさんの情報が取れてびっくりしました。約40個ほど。。。

出力結果

batteryLevel: 1
UnityEngine.Debug:Log (object)
Player:LogAllSystemInfo () (at Assets/Scripts/Player.cs:12)
Player:Start () (at Assets/Scripts/Player.cs:7)

batteryStatus: Full
UnityEngine.Debug:Log (object)
Player:LogAllSystemInfo () (at Assets/Scripts/Player.cs:13)
Player:Start () (at Assets/Scripts/Player.cs:7)

copyTextureSupport: Basic, Copy3D, DifferentTypes, TextureToRT, RTToTexture
UnityEngine.Debug:Log (object)
Player:LogAllSystemInfo () (at Assets/Scripts/Player.cs:14)
Player:Start () (at Assets/Scripts/Player.cs:7)

deviceModel: MacBookPro16,2
UnityEngine.Debug:Log (object)
Player:LogAllSystemInfo () (at Assets/Scripts/Player.cs:15)
Player:Start () (at Assets/Scripts/Player.cs:7)

deviceName: ****のMacBook Pro
UnityEngine.Debug:Log (object)
Player:LogAllSystemInfo () (at Assets/Scripts/Player.cs:16)
Player:Start () (at Assets/Scripts/Player.cs:7)

deviceType: Desktop
UnityEngine.Debug:Log (object)
Player:LogAllSystemInfo () (at Assets/Scripts/Player.cs:17)
Player:Start () (at Assets/Scripts/Player.cs:7)

deviceUniqueIdentifier: *************
UnityEngine.Debug:Log (object)
Player:LogAllSystemInfo () (at Assets/Scripts/Player.cs:18)
Player:Start () (at Assets/Scripts/Player.cs:7)

graphicsDeviceID: 0
UnityEngine.Debug:Log (object)
Player:LogAllSystemInfo () (at Assets/Scripts/Player.cs:19)
Player:Start () (at Assets/Scripts/Player.cs:7)

graphicsDeviceName: Intel(R) Iris(TM) Plus Graphics
UnityEngine.Debug:Log (object)
Player:LogAllSystemInfo () (at Assets/Scripts/Player.cs:20)
Player:Start () (at Assets/Scripts/Player.cs:7)

graphicsDeviceType: Metal
UnityEngine.Debug:Log (object)
Player:LogAllSystemInfo () (at Assets/Scripts/Player.cs:21)
Player:Start () (at Assets/Scripts/Player.cs:7)

graphicsDeviceVendor: Apple
UnityEngine.Debug:Log (object)
Player:LogAllSystemInfo () (at Assets/Scripts/Player.cs:22)
Player:Start () (at Assets/Scripts/Player.cs:7)

graphicsDeviceVendorID: 0
UnityEngine.Debug:Log (object)
Player:LogAllSystemInfo () (at Assets/Scripts/Player.cs:23)
Player:Start () (at Assets/Scripts/Player.cs:7)

graphicsDeviceVersion: Metal
UnityEngine.Debug:Log (object)
Player:LogAllSystemInfo () (at Assets/Scripts/Player.cs:24)
Player:Start () (at Assets/Scripts/Player.cs:7)

graphicsMemorySize: 1536
UnityEngine.Debug:Log (object)
Player:LogAllSystemInfo () (at Assets/Scripts/Player.cs:25)
Player:Start () (at Assets/Scripts/Player.cs:7)

graphicsMultiThreaded: True
UnityEngine.Debug:Log (object)
Player:LogAllSystemInfo () (at Assets/Scripts/Player.cs:26)
Player:Start () (at Assets/Scripts/Player.cs:7)

graphicsShaderLevel: 50
UnityEngine.Debug:Log (object)
Player:LogAllSystemInfo () (at Assets/Scripts/Player.cs:27)
Player:Start () (at Assets/Scripts/Player.cs:7)

graphicsUVStartsAtTop: True
UnityEngine.Debug:Log (object)
Player:LogAllSystemInfo () (at Assets/Scripts/Player.cs:28)
Player:Start () (at Assets/Scripts/Player.cs:7)

maxTextureSize: 16384
UnityEngine.Debug:Log (object)
Player:LogAllSystemInfo () (at Assets/Scripts/Player.cs:29)
Player:Start () (at Assets/Scripts/Player.cs:7)

npotSupport: Full
UnityEngine.Debug:Log (object)
Player:LogAllSystemInfo () (at Assets/Scripts/Player.cs:30)
Player:Start () (at Assets/Scripts/Player.cs:7)

operatingSystem: Mac OS X 13.4.1
UnityEngine.Debug:Log (object)
Player:LogAllSystemInfo () (at Assets/Scripts/Player.cs:31)
Player:Start () (at Assets/Scripts/Player.cs:7)

operatingSystemFamily: MacOSX
UnityEngine.Debug:Log (object)
Player:LogAllSystemInfo () (at Assets/Scripts/Player.cs:32)
Player:Start () (at Assets/Scripts/Player.cs:7)

processorCount: 8
UnityEngine.Debug:Log (object)
Player:LogAllSystemInfo () (at Assets/Scripts/Player.cs:33)
Player:Start () (at Assets/Scripts/Player.cs:7)

processorFrequency: 2300
UnityEngine.Debug:Log (object)
Player:LogAllSystemInfo () (at Assets/Scripts/Player.cs:34)
Player:Start () (at Assets/Scripts/Player.cs:7)

processorType: Intel(R) Core(TM) i7-1068NG7 CPU @ 2.30GHz
UnityEngine.Debug:Log (object)
Player:LogAllSystemInfo () (at Assets/Scripts/Player.cs:35)
Player:Start () (at Assets/Scripts/Player.cs:7)

supportedRenderTargetCount: 8
UnityEngine.Debug:Log (object)
Player:LogAllSystemInfo () (at Assets/Scripts/Player.cs:36)
Player:Start () (at Assets/Scripts/Player.cs:7)

supports2DArrayTextures: True
UnityEngine.Debug:Log (object)
Player:LogAllSystemInfo () (at Assets/Scripts/Player.cs:37)
Player:Start () (at Assets/Scripts/Player.cs:7)

supports3DRenderTextures: True
UnityEngine.Debug:Log (object)
Player:LogAllSystemInfo () (at Assets/Scripts/Player.cs:38)
Player:Start () (at Assets/Scripts/Player.cs:7)

supportsAccelerometer: False
UnityEngine.Debug:Log (object)
Player:LogAllSystemInfo () (at Assets/Scripts/Player.cs:39)
Player:Start () (at Assets/Scripts/Player.cs:7)

supportsAudio: True
UnityEngine.Debug:Log (object)
Player:LogAllSystemInfo () (at Assets/Scripts/Player.cs:40)
Player:Start () (at Assets/Scripts/Player.cs:7)

supportsComputeShaders: True
UnityEngine.Debug:Log (object)
Player:LogAllSystemInfo () (at Assets/Scripts/Player.cs:41)
Player:Start () (at Assets/Scripts/Player.cs:7)

supportsGyroscope: False
UnityEngine.Debug:Log (object)
Player:LogAllSystemInfo () (at Assets/Scripts/Player.cs:42)
Player:Start () (at Assets/Scripts/Player.cs:7)

supportsImageEffects: True
UnityEngine.Debug:Log (object)
Player:LogAllSystemInfo () (at Assets/Scripts/Player.cs:43)
Player:Start () (at Assets/Scripts/Player.cs:7)

supportsInstancing: True
UnityEngine.Debug:Log (object)
Player:LogAllSystemInfo () (at Assets/Scripts/Player.cs:44)
Player:Start () (at Assets/Scripts/Player.cs:7)

supportsLocationService: False
UnityEngine.Debug:Log (object)
Player:LogAllSystemInfo () (at Assets/Scripts/Player.cs:45)
Player:Start () (at Assets/Scripts/Player.cs:7)

supportsMipStreaming: True
UnityEngine.Debug:Log (object)
Player:LogAllSystemInfo () (at Assets/Scripts/Player.cs:46)
Player:Start () (at Assets/Scripts/Player.cs:7)

supportsMotionVectors: True
UnityEngine.Debug:Log (object)
Player:LogAllSystemInfo () (at Assets/Scripts/Player.cs:47)
Player:Start () (at Assets/Scripts/Player.cs:7)

supportsRawShadowDepthSampling: True
UnityEngine.Debug:Log (object)
Player:LogAllSystemInfo () (at Assets/Scripts/Player.cs:48)
Player:Start () (at Assets/Scripts/Player.cs:7)

supportsShadows: True
UnityEngine.Debug:Log (object)
Player:LogAllSystemInfo () (at Assets/Scripts/Player.cs:49)
Player:Start () (at Assets/Scripts/Player.cs:7)

supportsSparseTextures: False
UnityEngine.Debug:Log (object)
Player:LogAllSystemInfo () (at Assets/Scripts/Player.cs:50)
Player:Start () (at Assets/Scripts/Player.cs:7)

supportsVibration: False
UnityEngine.Debug:Log (object)
Player:LogAllSystemInfo () (at Assets/Scripts/Player.cs:51)
Player:Start () (at Assets/Scripts/Player.cs:7)

systemMemorySize: 16384
UnityEngine.Debug:Log (object)
Player:LogAllSystemInfo () (at Assets/Scripts/Player.cs:52)
Player:Start () (at Assets/Scripts/Player.cs:7)

unsupportedIdentifier: n/a
UnityEngine.Debug:Log (object)
Player:LogAllSystemInfo () (at Assets/Scripts/Player.cs:53)
Player:Start () (at Assets/Scripts/Player.cs:7)

usesReversedZBuffer: True
UnityEngine.Debug:Log (object)
Player:LogAllSystemInfo () (at Assets/Scripts/Player.cs:54)
Player:Start () (at Assets/Scripts/Player.cs:7)

CPUのコア数や周波数などが簡単に取れるのでとても微調整しやすそうですね!!

ざっとどのような情報が取れるかまとめてみた

  • batteryLevel: バッテリー残量(0.0 〜 1.0)
  • batteryStatus: バッテリーの状態(充電中、フル、放電中など)
  • copyTextureSupport: テクスチャのコピー機能のサポート度合い
  • deviceModel: デバイスのモデル名
  • deviceName: デバイスの名前
  • deviceType: デバイスのタイプ(デスクトップ、モバイルなど)
  • deviceUniqueIdentifier: デバイスの一意の識別子
  • graphicsDeviceID: グラフィックデバイスのID
  • graphicsDeviceName: グラフィックデバイスの名前
  • graphicsDeviceType: グラフィックデバイスのタイプ(Direct3D, OpenGLなど)
  • graphicsDeviceVendor: グラフィックデバイスのベンダー名
  • graphicsDeviceVendorID: グラフィックデバイスのベンダーID
  • graphicsDeviceVersion: グラフィックデバイスのバージョン
  • graphicsMemorySize: グラフィックデバイスのメモリサイズ(MB)
  • graphicsMultiThreaded: グラフィックがマルチスレッドをサポートしているか
  • graphicsShaderLevel: シェーダのサポートレベル
  • graphicsUVStartsAtTop: UV座標が上から始まるか
  • maxTextureSize: 最大テクスチャサイズ
  • npotSupport: NPOT(非パワーオブツー)テクスチャのサポート度合い
  • operatingSystem: オペレーティングシステムの情報
  • operatingSystemFamily: OSのファミリー(Windows, Linuxなど)
  • processorCount: プロセッサのコア数
  • processorFrequency: プロセッサの周波数(MHz)
  • processorType: プロセッサのタイプ
  • supportedRenderTargetCount: サポートされているレンダーターゲットの数
  • supports2DArrayTextures: 2D配列テクスチャをサポートしているか
  • supports3DRenderTextures: 3Dレンダーテクスチャをサポートしているか
  • supportsAccelerometer: 加速度センサーをサポートしているか
  • supportsAudio: オーディオをサポートしているか
  • supportsComputeShaders: コンピュートシェーダをサポートしているか
  • supportsGyroscope: ジャイロスコープをサポートしているか
  • supportsImageEffects: 画像エフェクトをサポートしているか
  • supportsInstancing: インスタンシングをサポートしているか
  • supportsLocationService: 位置情報サービスをサポートしているか
  • supportsMipStreaming: Mipマッピングのストリーミングをサポートしているか
  • supportsMotionVectors: モーションベクトルをサポートしているか
  • supportsRawShadowDepthSampling: 生のシャドウ深度サンプリングをサポートしているか
  • supportsShadows: シャドウをサポートしているか
  • supportsSparseTextures: スパーステクスチャをサポートしているか
  • supportsVibration: 振動をサポートしているか
  • systemMemorySize: システムのメモリサイズ(MB)
  • unsupportedIdentifier: サポートされていない識別子
  • usesReversedZBuffer: 逆Zバッファを使用しているか

アイデア

  • バッテリー容量を見て機能をオフに自動でさせる
  • コア数や周波数によって機能を最適化
    などなど、色々使い道がありそう。
Flamers Tech Blog

Discussion