Version: Unity 6.0 (6000.0)
语言 : 中文
模拟类
扩展 Device Simulator

添加设备

要将新设备添加到设备模拟器,请创建一个设备定义和设备覆盖层。

设备定义是 Unity 项目中扩展名为 .device 的文本文件。它包含描述设备属性的 JSON。

设备覆盖层是指包含设备屏幕边框的图像,此外还包括缺口、开孔以及屏幕矩形区域外的其他任何附加部分。可以选择将其与设备定义一起使用,以可视化呈现硬件元素如何遮挡设备屏幕,并确定触控输入何时因此失效。

创建设备定义

设备定义是表示设备的 JSON 文件。它具有必要属性和一些可选属性。如果设备定义文件包含任何错误,则在选择文件时,错误将显示在检视器中。

框架

属性 必需 描述
friendlyName 要在此设备的__ UI__(即用户界面,User Interface)让用户能够与您的应用程序进行交互。Unity 目前支持三种 UI 系统。更多信息
See in Glossary
中显示的名称。
version 指示设备定义文件的版本。目前,版本为 1
screens 对象列表,其中每个对象都描述了要模拟设备的屏幕。必须包含至少一个屏幕。有关每个屏幕对象的框架的信息,请参阅屏幕
systemInfo 描述设备功能的对象。此对象中的值映射到 SystemInfo。有关 systemInfo 对象框架的信息,请参阅 systemInfo

屏幕

属性 必需 描述
width 屏幕的宽度(以像素为单位)。
height 屏幕的高度(以像素为单位)。
navigationBarHeight 屏幕 Android 导航栏的高度(以像素为单位),在某些设备上非全屏显示时会出现此导航栏。
dpi 屏幕的 dpi。
orientations 对象列表,其中每个对象都描述了屏幕可以模拟的方向。如果没有为此属性设置值,则屏幕支持模拟所有方向。有关每个方向对象的框架的信息,请参阅方向
presentation 描述设备覆盖层的对象。有关此对象的框架的信息,请参阅演示

方向

属性 必需 描述
orientation 屏幕方向。此属性的值是一个映射到 ScreenOrientation 枚举的数字。
safeArea 确定屏幕安全区域的矩形。如果没有为此属性设置值,模拟器会默认整个屏幕都是安全的。
Cutout Rect 列表,指定了屏幕中无法显示内容的区域。

演示

属性 必需 描述
overlayPath 从设备定义文件到要用作设备覆盖层的图像的相对路径。
borderSize 从覆盖层到屏幕开始位置的距离(以像素为单位)。

systeminfo

此对象中的属性描述了设备的功能和系统信息。由于它们描述了系统信息,因此许多都映射到 SystemInfo 中的属性。

属性 必需 描述
deviceModel 请参阅 Device.SystemInfo.deviceModel
deviceType 请参阅 Device.SystemInfo.deviceType
operatingSystem 请参阅 Device.SystemInfo.operatingSystem
operatingSystemFamily 请参阅 Device.SystemInfo.operatingSystemFamily
processorCount 请参阅 Device.SystemInfo.processorCount
processorFrequency 请参阅 Device.SystemInfo.processorFrequency
processorType 请参阅 Device.SystemInfo.processorType
supportsAccelerometer 请参阅 Device.SystemInfo.supportsAccelerometer
supportsAudio SystemInfo.supportsAudio
supportsGyroscope 请参阅 Device.SystemInfo.supportsGyroscope
supportsLocationService 请参阅 Device.SystemInfo.supportsLocationService
supportsVibration 请参阅 Device.SystemInfo.supportsVibration
systemMemorySize 请参阅 Device.SystemInfo.systemMemorySize
unsupportedIdentifier 请参阅 Device.SystemInfo.unsupportedIdentifier
graphicsDependentData 对象列表,其中每个对象都描述了设备支持的图形 API。有关每个对象的框架的信息,请参阅 graphicsDependentData

graphicsDependentData

对象中的属性描述了设备支持的图形 API。

属性 必需 描述
graphicsDeviceType 请参阅 Device.SystemInfo.graphicsDeviceType
graphicsMemorySize 请参阅 Device.SystemInfo.graphicsMemorySize
graphicsDeviceName 请参阅 Device.SystemInfo.graphicsDeviceName
graphicsDeviceVendor 请参阅 Device.SystemInfo.graphicsDeviceVendor
graphicsDeviceID 请参阅 Device.SystemInfo.graphicsDeviceID
graphicsDeviceVendorID 请参阅 Device.SystemInfo.graphicsDeviceVendorID
graphicsUVStartsAtTop 请参阅 Device.SystemInfo.graphicsUVStartsAtTop
graphicsDeviceVersion 请参阅 Device.SystemInfo.graphicsDeviceVersion
graphicsShaderLevel 请参阅 Device.SystemInfo.graphicsShaderLevel
graphicsMultiThreaded 请参阅 Device.SystemInfo.graphicsMultiThreaded
renderingThreadingMode 请参阅 Device.SystemInfo.renderingThreadingMode
hasHiddenSurfaceRemovalOnGPU 请参阅 Device.SystemInfo.hasHiddenSurfaceRemovalOnGPU
hasDynamicUniformArrayIndexingInFragmentShaders 请参阅 Device.SystemInfo.hasDynamicUniformArrayIndexingInFragmentShaders
supportsShadows 请参阅 Device.SystemInfo.supportsShadows
supportsRawShadowDepthSampling 请参阅 Device.SystemInfo.supportsRawShadowDepthSampling
supportsMotionVectors 请参阅 Device.SystemInfo.supportsMotionVectors
supports3DTextures 请参阅 Device.SystemInfo.supports3DTextures
supports2DArrayTextures 请参阅 Device.SystemInfo.supports2DArrayTextures
supports3DRenderTextures 请参阅 Device.SystemInfo.supports3DRenderTextures
supportsCubemapArrayTextures 请参阅 Device.SystemInfo.supportsCubemapArrayTextures
copyTextureSupport 请参阅 Device.SystemInfo.copyTextureSupport
supportsComputeShaders 请参阅 Device.SystemInfo.supportsComputeShaders
supportsGeometryShaders 请参阅 Device.SystemInfo.supportsGeometryShaders
supportsTessellationShaders 请参阅 Device.SystemInfo.supportsTessellationShaders
supportsInstancing 请参阅 Device.SystemInfo.supportsInstancing
supportsHardwareQuadTopology 请参阅 Device.SystemInfo.supportsHardwareQuadTopology
supports32bitsIndexBuffer 请参阅 Device.SystemInfo.supports32bitsIndexBuffer
supportsSparseTextures 请参阅 Device.SystemInfo.supportsSparseTextures
supportedRenderTargetCount 请参阅 Device.SystemInfo.supportedRenderTargetCount
supportsSeparatedRenderTargetsBlend 请参阅 Device.SystemInfo.supportsSeparatedRenderTargetsBlend
supportedRandomWriteTargetCount 请参阅 Device.SystemInfo.supportedRandomWriteTargetCount
supportsMultisampledTextures 请参阅 Device.SystemInfo.supportsMultisampledTextures
supportsMultisampleAutoResolve 请参阅 Device.SystemInfo.supportsMultisampleAutoResolve
supportsTextureWrapMirrorOnce 请参阅 Device.SystemInfo.supportsTextureWrapMirrorOnce
usesReversedZBuffer 请参阅 Device.SystemInfo.usesReversedZBuffer
npotSupport 请参阅 Device.SystemInfo.npotSupport
maxTextureSize 请参阅 Device.SystemInfo.maxTextureSize
maxCubemapSize 请参阅 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
maxComputeWorkGroupSize 请参阅 Device.SystemInfo.maxComputeWorkGroupSize
maxComputeWorkGroupSizeX 请参阅 Device.SystemInfo.maxComputeWorkGroupSizeX
maxComputeWorkGroupSizeY 请参阅 Device.SystemInfo.maxComputeWorkGroupSizeY
maxComputeWorkGroupSizeZ 请参阅 Device.SystemInfo.maxComputeWorkGroupSizeZ
supportsAsyncCompute 请参阅 Device.SystemInfo.supportsAsyncCompute
supportsGraphicsFence 请参阅 Device.SystemInfo.supportsGraphicsFence
supportsAsyncGPUReadback 请参阅 Device.SystemInfo.supportsAsyncGPUReadback
supportsParallelPSOCreation 请参阅 Device.SystemInfo.supportsParallelPSOCreation
supportsRayTracing 请参阅 Device.SystemInfo.supportsRayTracing
supportsRayTracingShaders 请参阅 Device.SystemInfo.supportsRayTracingShaders
supportsInlineRayTracing 请参阅 Device.SystemInfo.supportsInlineRayTracing
supportsSetConstantBuffer 请参阅 Device.SystemInfo.supportsSetConstantBuffer
hasMipMaxLevel 请参阅 Device.SystemInfo.hasMipMaxLevel
supportsMipStreaming 请参阅 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,
                "supportsParallelPSOCreation": true,
                "supportsRayTracing": false,
                "supportsRayTracingShaders": false,
                "supportsInlineRayTracing": 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 的默认天空盒。在实际设备覆盖层中,这些像素应该是透明的。

Apple iPhone 8 Overlay Apple iPhone XS Overlay

使用设备覆盖层

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

注意:当设备模拟器加载设备覆盖纹理时,设备模拟器会尝试为设备覆盖纹理启用 Read/Write。如果无法实现,则设备模拟器会显示纹理,但无法使用纹理来遮罩输入。这意味着,如果单击设备覆盖层应遮挡的屏幕缺口和其他区域,则设备模拟器会检测输入。为确保不会发生这种情况,导入设备覆盖纹理时,请在 Texture Import Settings 窗口中启用 Read/Write

当设备覆盖纹理位于项目中时,打开设备定义文件,然后在定义了设备所支持的屏幕的对象中添加 presentation 属性。在此处,设置图像文件的路径 (overlayPath) 和边框的大小 (borderSize)。有关如何执行此操作的示例,请参阅以下设备定义文件:

{
    "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"
    }
}

注意:设备覆盖纹理文件的路径可以是相对于设备定义文件的路径,也可以是相对于包含 AssetsPackages 目录的 Unity 项目目录的路径。例如,如果设备定义文件位于 Assets/Devices 目录中,而设备覆盖文件位于 Assets/Devices/Overlays 目录中,则以下文件路径均有效:

  • 相对于设备定义文件:Overlays/MinimalDeviceOverlay.png
  • 相对于包含 Assets 目录的目录:Assets/Devices/Overlays/MinimalDeviceOverlay.png
模拟类
扩展 Device Simulator