Unity3D: デバイスの追加

Unity3D: デバイスの追加

推奨: NSDT シーン エディターを3D ツールチェーンに追加します。

3D ツールセット: NSDT Jane Stone Digital Twins

デバイスを追加

新しいデバイスをデバイス エミュレーターに追加するには、デバイス定義とデバイス オーバーライドを作成します。

デバイス定義は、拡張子が のテキスト ファイルです。これには、デバイスのプロパティを記述する JSON が含まれています。.device

デバイス オーバーレイは、デバイスの画面のベゼルと、ノッチ、パンチ ホール、および画面の四角形へのその他の追加部分を含む画像です。オプションでこれをデバイス定義とともに使用して、ハードウェア要素がデバイス画面をどのように妨げているかを視覚化し、その結果としてタッチ入力がいつ失敗するかを判断できます。

デバイス定義を作成する

デバイス定義は、デバイスを表す JSON ファイルです。これには必須の属性といくつかのオプションの属性の両方があります。デバイス定義ファイルにエラーが含まれている場合は、ファイルを選択するとインスペクタにエラーが表示されます。

スキーマ

属性 必要 説明
分かりやすい名前 はい このデバイスの UI に表示される名前。
バージョン はい デバイス定義ファイルのバージョンを示します。現在のバージョンは です。1
画面 はい オブジェクトのリスト。それぞれがエミュレートされるデバイスの画面を記述します。これには少なくとも 1 つの画面が含まれている必要があります。各画面オブジェクトのスキーマについては、 「画面」を参照してください
システムメッセージ はい デバイスの機能を記述するオブジェクト。このオブジェクトの値はシステム情報にマップされます。systemInfo オブジェクトのスキーマについては、 「systemInfo」を参照してください 

画面

属性 必要 説明
はい 画面の幅 (ピクセル単位)。
高い はい 画面の高さ (ピクセル単位)。
ナビゲーションバーの高さ いいえ 一部のデバイスで全画面表示でないときに表示される、画面上の Android ナビゲーション バーのピクセル単位の高さ。
報道部 はい 画面の dpi。
ガイド いいえ 画面がエミュレートできる方向をそれぞれ記述するオブジェクトのリスト。このプロパティに値が設定されていない場合、画面はすべての方向をサポートします。各方向オブジェクトのスキーマについては、「 Orientation 」を参照してください。
導入 いいえ デバイスがカバーするオブジェクトについて説明します。このオブジェクトのスキーマについては、プレゼンテーションを参照してください

オリエンテーション

属性 必要 説明
オリエンテーション はい 画面の向き。このプロパティの値は、画面の向きの列挙にマップされる数値です
安全地帯 いいえ 画面の安全領域を決定する長方形このプロパティに値が設定されていない場合、エミュレータは画面全体が安全であると想定します。
切開 いいえ コンテンツを表示できない画面の領域を指定するRectのリスト。

導入

属性 必要 説明
カバレッジパス いいえ デバイス定義ファイルからデバイス オーバーレイとして使用される画像への相対パス。
境界線のサイズ いいえ 画面上でオーバーレイが開始される位置からの距離 (ピクセル単位)。

システムメッセージ

このオブジェクトのプロパティは、デバイスの機能とシステム情報を記述します。これらはシステム情報を記述するため、その多くはシステム情報の属性にマッピングされます。

属性 必要 説明
デバイスモデル いいえ Device.SystemInfo.deviceModelを参照してください 
設備の種類 いいえ Device.SystemInfo.deviceTypeを参照してください 
オペレーティング·システム はい 「デバイス.システム情報.オペレーティング システム」を参照してください
オペレーティング システム ファミリ いいえ Device.SystemInfo.operatingSystemFamilyを参照してください 
プロセッサ数 いいえ Device.SystemInfo.processorCountを参照してください 
プロセッサ周波数 いいえ Device.SystemInfo.processorFrequencyを参照してください 
プロセッサの種類 いいえ Device.SystemInfo.processorTypeを参照してください 
加速度センサーのサポート いいえ Device.SystemInfo.supportsAccelerometerを参照してください 
サポートオーディオ いいえ Device.SystemInfo.supportsAudioを参照してください 
ジャイロスコープをサポート いいえ Device.SystemInfo.supportsGyrscopeを参照してください 
位置情報サービスのサポート いいえ Device.SystemInfo.supportsLocationServiceを参照してください 
サポート振動 いいえ 「デバイス.システム情報.振動のサポート」を参照してください
システムメモリサイズ いいえ Device.SystemInfo.systemMemorySizeを参照してください 
サポートされていない識別子 いいえ Device.SystemInfo.unsupportedIdentifierを参照してください 
グラフ依存データ いいえ 各オブジェクトは、デバイスによってサポートされるグラフィックス API を記述するオブジェクトのリストです。各オブジェクトのスキーマについては、 graphicsDependentDataを参照してください 

グラフ依存データ

オブジェクト内のプロパティは、デバイスによってサポートされるグラフィックス API を記述します。

属性 必要 説明
グラフィックスデバイスの種類 はい Device.SystemInfo.graphicsDeviceTypeを参照してください 
グラフィックスメモリのサイズ いいえ Device.SystemInfo.graphicsMemorySizeを参照してください 
グラフィックスデバイス名 いいえ 请参阅 Device.SystemInfo.graphicsDeviceName
图形设备供应商 请参阅 Device.SystemInfo.graphicsDeviceVendor
图形设备标识 请参阅 Device.SystemInfo.graphicsDeviceID
graphicsDeviceVendorID 请参阅 Device.SystemInfo.graphicsDeviceVendorID
图形UV馅饼在顶部 请参阅 Device.SystemInfo.graphicsUVStartsAtTop
图形设备版本 请参阅 Device.SystemInfo.graphicsDeviceVersion
图形着色器级别 请参阅 Device.SystemInfo.graphicsShaderLevel
图形多线程 请参阅 Device.SystemInfo.graphicsMultiThreaded
渲染线程模式 请参阅 Device.SystemInfo.renderingThreadingMode
hasHiddenSurfaceRemovalOnGPU 请参阅 Device.SystemInfo.hasHiddenSurfaceRemovalOnGPU
hasDynamicUniformArrayIndexingInFragmentShaders 请参阅 Device.SystemInfo.hasDynamicUniformArrayIndexingInFragmentShaders
支持阴影 请参阅 Device.SystemInfo.supportsShadows
支持原始阴影深度采样 请参阅 Device.SystemInfo.supportsRawShadowDepthSampling
支持运动矢量 请参阅 Device.SystemInfo.supportsMotionVectors
支持3DTextures 请参阅 Device.SystemInfo.supports3DTextures
支持2DArrayTextures 请参阅 Device.SystemInfo.supports2DArrayTextures
支持3DRender纹理 请参阅 Device.SystemInfo.supports3DRenderTextures
支持立方体地图数组纹理 请参阅 Device.SystemInfo.supportsCubemapArrayTextures
复制纹理支持 请参阅 Device.SystemInfo.copyTextureSupport
支持计算着色器 请参阅 Device.SystemInfo.supportsComputeShaders
支持几何着色器 请参阅 Device.SystemInfo.supportsGeometryShaders
支持TessellationShaders 请参阅 Device.SystemInfo.supportsTessellationShaders
支持实例化 请参阅 Device.SystemInfo.supportsInstancing
支持硬件四拓扑 请参阅 Device.SystemInfo.supportsHardwareQuadTopology
支持32位索引缓冲区 请参阅 Device.SystemInfo.supports32bitsIndexBuffer
支持稀疏纹理 请参阅 Device.SystemInfo.supportsSparseTextures
支持的渲染目标计数 请参阅 Device.SystemInfo.supportedRenderTargetCount
supportsSepardRenderTargetsBlend 请参阅 Device.SystemInfo.supportsSepardRenderTargetsBlend
支持的随机写入目标计数 请参阅 Device.SystemInfo.supportedRandomWriteTargetCount
支持多重采样纹理 请参阅 Device.SystemInfo.supportsMultisampledTextures
支持多采样自动解析 请参阅 Device.SystemInfo.supportsMultisampleAutoResolve
支持纹理包装镜像一次 请参阅 Device.SystemInfo.supportsTextureWrapMirrorOnce
用途反转ZBuffer 请参阅 Device.SystemInfo.usesReversedZBuffer
npot支持 请参阅 Device.SystemInfo.npotSupport
最大纹理大小 请参阅 Device.SystemInfo.maxTextureSize
最大立方体地图大小 请参阅 Device.SystemInfo.maxCubemapSize
maxComputeBufferInputsVertex 请参阅 Device.SystemInfo.maxComputeBufferInputsVertex
maxComputeBufferInputsFragment 请参阅 Device.SystemInfo.maxComputeBufferInputsFragment
maxComputeBufferInputsGeometry 请参阅 Device.SystemInfo.maxComputeBufferInputsGeometry
maxComputeBufferInputsDomain 请参阅 Device.SystemInfo.maxComputeBufferInputsDomain
maxComputeBufferInputsHull 请参阅 Device.SystemInfo.maxComputeBufferInputsHull
maxComputeBufferInputsCompute 请参阅 Device.SystemInfo.maxComputeBufferInputsCompute
最大计算工作组大小 请参阅 Device.SystemInfo.maxComputeWorkGroupSize
maxComputeWorkGroupSizeX 请参阅 Device.SystemInfo.maxComputeWorkGroupSizeX
maxComputeWorkGroupSizeY 请参阅 Device.SystemInfo.maxComputeWorkGroupSizeY
maxComputeWorkGroupSizeZ 请参阅 Device.SystemInfo.maxComputeWorkGroupSizeZ
支持异步计算 请参阅 Device.SystemInfo.supportsAsyncCompute
支持图形围栏 请参阅 Device.SystemInfo.supportsGraphicsFence
支持AsyncGPUReadback 请参阅 Device.SystemInfo.supportsAsyncGPUReadback
支持光线追踪 请参阅 Device.SystemInfo.supportsRayTracing
支持设置常量缓冲区 请参阅 Device.SystemInfo.supportsSetConstantBuffer
hasMipMaxLevel 请参阅 Device.SystemInfo.hasMipMaxLevel
支持MipStreaming 请参阅 Device.SystemInfo.supportsMipStreaming
usesLoadStoreActions 请参阅 Device.SystemInfo.usesLoadStoreActions

最少的设备定义

以下设备定义包含每个必需属性,不包含可选属性。这是您可以拥有的最低设备定义。

注意:此设备定义不提供方向数据,因此模拟器假定设备支持所有方向,并且安全区域覆盖整个屏幕。

{
    "friendlyName": "Minimal Device",
    "version": 1,
    "screens": [
        {
            "width": 1080,
            "height": 1920,
            "dpi": 450.0
        }
    ],
    "systemInfo": {
        "operatingSystem": "Android"
    }
}

完整的设备定义

以下设备定义包含每个必需属性和可选属性。

{
    "friendlyName": "Apple iPhone XR",
    "version": 1,
    "screens": [
        {
            "width": 828,
            "height": 1792,
            "navigationBarHeight": 0,
            "dpi": 326.0,
            "orientations": [
                {
                    "orientation": 1,
                    "safeArea": {
                        "serializedVersion": "2",
                        "x": 0.0,
                        "y": 68.0,
                        "width": 828.0,
                        "height": 1636.0
                    },
                    "cutouts": [
                        {
                            "serializedVersion": "2",
                            "x": 184.0,
                            "y": 1726.0,
                            "width": 460.0,
                            "height": 66.0
                        }
                    ]
                },
                {
                    "orientation": 3,
                    "safeArea": {
                        "serializedVersion": "2",
                        "x": 88.0,
                        "y": 42.0,
                        "width": 1616.0,
                        "height": 786.0
                    },
                    "cutouts": [
                        {
                            "serializedVersion": "2",
                            "x": 0.0,
                            "y": 184.0,
                            "width": 66.0,
                            "height": 460.0
                        }
                    ]
                },
                {
                    "orientation": 4,
                    "safeArea": {
                        "serializedVersion": "2",
                        "x": 88.0,
                        "y": 42.0,
                        "width": 1616.0,
                        "height": 786.0
                    },
                    "cutouts": [
                        {
                            "serializedVersion": "2",
                            "x": 1726.0,
                            "y": 184.0,
                            "width": 66.0,
                            "height": 460.0
                        }
                    ]
                }
            ],
            "presentation": {
                "overlayPath": "Apple iPhone 11_Overlay.png",
                "borderSize": {
                    "x": 51.0,
                    "y": 51.0,
                    "z": 51.0,
                    "w": 51.0
                }
            }
        }
    ],
    "systemInfo": {
        "deviceModel": "iPhone11,8",
        "deviceType": 1,
        "operatingSystem": "iOS 12.0",
        "operatingSystemFamily": 0,
        "processorCount": 6,
        "processorFrequency": 0,
        "processorType": "arm64e",
        "supportsAccelerometer": true,
        "supportsAudio": true,
        "supportsGyroscope": true,
        "supportsLocationService": true,
        "supportsVibration": true,
        "systemMemorySize": 2813,
        "unsupportedIdentifier": "n/a",
        "graphicsDependentData": [
            {
                "graphicsDeviceType": 16,
                "graphicsMemorySize": 1024,
                "graphicsDeviceName": "Apple A12 GPU",
                "graphicsDeviceVendor": "Apple",
                "graphicsDeviceID": 0,
                "graphicsDeviceVendorID": 0,
                "graphicsUVStartsAtTop": true,
                "graphicsDeviceVersion": "Metal",
                "graphicsShaderLevel": 50,
                "graphicsMultiThreaded": true,
                "renderingThreadingMode": 0,
                "hasHiddenSurfaceRemovalOnGPU": true,
                "hasDynamicUniformArrayIndexingInFragmentShaders": true,
                "supportsShadows": true,
                "supportsRawShadowDepthSampling": true,
                "supportsMotionVectors": true,
                "supports3DTextures": true,
                "supports2DArrayTextures": true,
                "supports3DRenderTextures": true,
                "supportsCubemapArrayTextures": true,
                "copyTextureSupport": 31,
                "supportsComputeShaders": true,
                "supportsGeometryShaders": false,
                "supportsTessellationShaders": true,
                "supportsInstancing": true,
                "supportsHardwareQuadTopology": false,
                "supports32bitsIndexBuffer": true,
                "supportsSparseTextures": false,
                "supportedRenderTargetCount": 8,
                "supportsSeparatedRenderTargetsBlend": true,
                "supportedRandomWriteTargetCount": 8,
                "supportsMultisampledTextures": 1,
                "supportsMultisampleAutoResolve": false,
                "supportsTextureWrapMirrorOnce": 0,
                "usesReversedZBuffer": true,
                "npotSupport": 2,
                "maxTextureSize": 16384,
                "maxCubemapSize": 16384,
                "maxComputeBufferInputsVertex": 8,
                "maxComputeBufferInputsFragment": 8,
                "maxComputeBufferInputsGeometry": 0,
                "maxComputeBufferInputsDomain": 8,
                "maxComputeBufferInputsHull": 8,
                "maxComputeBufferInputsCompute": 8,
                "maxComputeWorkGroupSize": 1024,
                "maxComputeWorkGroupSizeX": 1024,
                "maxComputeWorkGroupSizeY": 1024,
                "maxComputeWorkGroupSizeZ": 1024,
                "supportsAsyncCompute": false,
                "supportsGraphicsFence": true,
                "supportsAsyncGPUReadback": true,
                "supportsRayTracing": false,
                "supportsSetConstantBuffer": true,
                "hasMipMaxLevel": true,
                "supportsMipStreaming": true,
                "usesLoadStoreActions": true,
                "supportedTextureFormats": [1, 2, 3, 4, 5],
                "supportedRenderTextureFormats": [1, 2, 3, 4, 5],
                "ldrGraphicsFormat": 59,
                "hdrGraphicsFormat": 74
            }
        ]
    }
}

创建设备覆盖

设备覆盖是包含设备屏幕边框和其他功能(如凹口、打孔和屏幕矩形的任何其他添加)的图像。您可以选择将其与设备定义一起使用,以可视化硬件元素如何阻碍设备屏幕,并确定触摸输入何时因此失败。

设备模拟器将透明像素解释为可以点击的屏幕区域,将任何其他颜色的不透明像素解释为硬件遮挡的区域。纹理本身可以是任何形状。

以下示例显示了两种 iPhone 机型的设备叠加。

注意:为了模拟使用设备叠加时看到的内容,这些示例在屏幕区域显示 Unity 的默认天空盒,您可以在其中按 tab 键显示。在实际设备叠加中,这些像素应该是透明的。

苹果 IPHONE 8 叠加层 苹果苹果IPHONE XS叠加层

使用设备覆盖

创建设备覆盖纹理后,若要将其与设备定义一起使用,必须先将设备覆盖纹理文件导入到项目中。

注意:当设备模拟器加载设备覆盖纹理时,它会尝试为其启用读/写。如果无法做到这一点,设备模拟器将显示纹理,但无法使用纹理来屏蔽输入。这意味着,如果单击设备覆盖应屏蔽的凹口和屏幕其他区域,设备模拟器将检测输入。为确保不会发生这种情况,导入设备叠加纹理时,请在纹理导入设置窗口中启用读/写

デバイス オーバーレイ テクスチャがプロジェクト内にある場合は、デバイス定義ファイルを開き、デバイスでサポートされる画面を定義するオブジェクトにプレゼンテーション プロパティを追加します。ここでは、画像ファイルへのパス()とボーダーのサイズ()を設定します。これを行う方法の例については、次のデバイス定義ファイルを参照してください。overlayPathborderSize

{
    "friendlyName": "Minimal Device with Overlay",
    "version": 1,
    "screens": [
        {
            "width": 1080,
            "height": 1920,
            "dpi": 450.0,
            "presentation": {
                "overlayPath": "Overlays/MinimalDeviceOverlay.png",
                "borderSize": {
                    "x": 51.0,
                    "y": 51.0,
                    "z": 51.0,
                    "w": 130.0
                }
            }
        }
    ],
    "systemInfo": {
        "operatingSystem": "Android"
    }
}

注: デバイス オーバーレイ テクスチャ ファイルへのパスは、デバイス定義ファイルに対する相対パス、またはリソースまたはバンドルディレクトリを含む Unity プロジェクト内のディレクトリに対する相対パスにすることができますたとえば、デバイス定義ファイルがassets/deviceディレクトリにあり、デバイスオーバーライドファイルがassets/device/overrideディレクトリにある場合、次のファイルパスはすべて有効です。

  • デバイス定義ファイルに関連して: /mindeviceoverride.pngをオーバーライドします。
  • アセット ディレクトリを含むディレクトリからの相対パス: assets /devices/overrides/ minimum-devices-override.png

この記事は3D Modeling Learning Studioによって構成および翻訳されています。転載する場合は出典を明記してください。

前: Unity3D: シミュレーション (mvrlink.com)

次へ: Unity3D: 拡張デバイス シミュレーター (mvrlink.com)

おすすめ

転載: blog.csdn.net/ygtu2018/article/details/131361466