Version: 6000.3
语言: 中文
模拟类
扩展设备模拟器

添加设备

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

设备定义是一个文本文件,其中包含.device扩展。它包含描述设备属性的 JSON。

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

创建设备定义

设备定义是表示设备的 JSON 文件。它既有必需属性,也有一些可选属性。如果设备定义文件包含任何错误,则错误将显示在检查器一个 Unity 窗口,显示有关当前选定游戏对象、资产或项目设置的信息,允许您检查和编辑值。更多信息
请参阅术语表
选择文件时。

图式

财产 必填 描述
友好名称 是的 要在此设备的 UI 中显示的名称。
版本 是的 指示设备定义文件的版本。目前,版本为1.
屏幕 是的 每个对象描述要模拟设备的屏幕的对象列表。这必须至少包含一个屏幕。有关每个屏幕对象的架构的信息,请参阅屏幕
系统信息 是的 描述设备功能的对象。此对象中的值映射到 SystemInfo。有关 systemInfo 对象的架构的信息,请参阅 systemInfo

屏幕

财产 必填 描述
宽度 是的 宽度,在像素计算机图像中的最小单位。像素大小取决于您的屏幕分辨率。像素光照是在每个屏幕像素下计算的。更多信息
请参阅术语表
,屏幕的。
高度 是的 屏幕的高度(以像素为单位)。
导航栏高度 某些设备上未全屏显示的屏幕 Android 导航栏的高度(以像素为单位)。
DPI 是的 屏幕的 dpi。
取向 每个对象描述屏幕可以模拟的方向的对象列表。如果未为此属性设置值,则屏幕支持所有方向。有关每个方向对象的架构的信息,请参阅方向
介绍 描述设备覆盖的对象。有关此对象的架构的信息,请参阅演示文稿

取向

性能 必填 描述
取向 是的 屏幕方向。此属性的值是映射到 ScreenOrientation 枚举的数字。
安全区域 确定屏幕安全区域的 Rect。如果未为此属性设置值,模拟器会假定整个屏幕是安全的。
镂空 Rect的列表,用于指定无法显示内容的屏幕区域。

介绍

财产 必填 描述
覆盖路径 从设备定义文件到要用作设备覆盖的图像的相对路径。
边框大小 从叠加层到屏幕开始位置的距离(以像素为单位)。

系统信息

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

财产 必填 描述
设备型号 请参阅 Device.SystemInfo.deviceModel
设备类型 请参阅 Device.SystemInfo.deviceType
作系统 是的 请参阅 Device.SystemInfo.operatingSystem
作系统系统系列 请参阅 Device.SystemInfo.operatingSystemFamily
处理器计数 请参阅 Device.SystemInfo.processorCount
处理器频率 请参阅 Device.SystemInfo.processorFrequency
处理器类型 请参阅 Device.SystemInfo.processorType
支持加速度计 请参阅 Device.SystemInfo.supportsAccelerometer
支持音频 请参阅 Device.SystemInfo.supportsAudio
支持陀螺仪 请参阅 Device.SystemInfo.supportsGyroscope
支持位置服务 请参阅 Device.SystemInfo.supportsLocationService
支持振动 请参阅 Device.SystemInfo.supportsVibration
系统内存大小 请参阅 Device.SystemInfo.systemMemorySize
unsupportedIdentifier 请参阅 Device.SystemInfo.unsupportedIdentifier
图形依赖数据 每个对象描述设备支持的图形 API 的对象列表。有关每个对象的架构的信息,请参阅 graphicsDependentData

图形依赖数据

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

财产 必填 描述
图形设备类型 是的 请参阅 Device.SystemInfo.graphicsDeviceType
图形内存大小 请参阅 Device.SystemInfo.graphicsMemorySize
图形设备名称 请参阅 Device.SystemInfo.graphicsDeviceName
图形设备供应商 请参阅 Device.SystemInfo.graphicsDeviceVendor
图形设备ID 请参阅 Device.SystemInfo.graphicsDeviceID
图形设备供应商 ID 请参阅 Device.SystemInfo.graphicsDeviceVendorID
图形UVStartsAtTop 请参阅 Device.SystemInfo.graphicsUVStartsAtTop
图形设备版本 请参阅 Device.SystemInfo.graphicsDeviceVersion
图形ShaderLevel 请参阅 Device.SystemInfo.graphicsShaderLevel
显卡多线程 请参阅 Device.SystemInfo.graphicsMultiThreaded
渲染线程模式 请参阅 Device.SystemInfo.renderingThreadingMode
hasHiddenSurfaceRemovalOnGPU 请参阅 Device.SystemInfo.hasHiddenSurfaceRemovalOnGPU
hasDynamicUniformArrayIndexingInFragmentShaders 请参阅 Device.SystemInfo.hasDynamicUniformArrayIndexingInFragmentShaders
支持阴影 请参阅 Device.SystemInfo.supportsShadows
支持RawShadowDepthSampling 请参阅 Device.SystemInfo.supportsRawShadowDepthSampling
支持运动矢量 请参阅 Device.SystemInfo.supportsMotionVectors
支持3Dextures 请参阅 Device.SystemInfo.supports3DTextures
支持2DArray纹理 请参阅 Device.SystemInfo.supports2DArrayTextures
支持3DRenderTextures 请参阅 Device.SystemInfo.supports3DRenderTextures
支持立方体贴图阵列纹理 请参阅 Device.SystemInfo.supportsCubemapArrayTextures
复制纹理支持 请参阅 Device.SystemInfo.copyTextureSupport
支持计算着色器 请参阅 Device.SystemInfo.supportsComputeShaders
支持几何着色器 请参阅 Device.SystemInfo.supportsGeometryShaders
支持细分着色器 请参阅 Device.SystemInfo.supportsTessellationShaders
支持实例化 请参阅 Device.SystemInfo.supportsInstancing
支持硬件四拓扑 请参阅 Device.SystemInfo.supportsHardwareQuadTopology
支持32位索引缓冲区 请参阅 Device.SystemInfo.supports32bitsIndexBuffer
支持稀疏纹理 请参阅 Device.SystemInfo.supportsSparseTextures
支持的渲染目标计数 请参阅 Device.SystemInfo.supportedRenderTargetCount
支持分离的渲染目标混合 请参阅 Device.SystemInfo.supportsSeparatedRenderTargetsBlend
支持的随机写入目标计数 请参阅 Device.SystemInfo.supportedRandomWriteTargetCount
支持多采样纹理 请参阅 Device.SystemInfo.supportsMultisampledTextures
支持多采样自动解析 请参阅 Device.SystemInfo.supportsMultisampleAutoResolve
支持TextureWrapMirrorOnce 请参阅 Device.SystemInfo.supportsTextureWrapMirrorOnce
用途ReversedZBuffer 请参阅 Device.SystemInfo.usesReversedZBuffer
npot支持 请参阅 Device.SystemInfo.npotSupport
最大纹理大小 请参阅 Device.SystemInfo.maxTextureSize
最大立方体贴图大小 请参阅 Device.SystemInfo.maxCubemapSize
maxComputeBufferInputs顶点 请参阅 Device.SystemInfo.maxComputeBufferInputsVertex
maxComputeBufferInputsFragment 请参阅 Device.SystemInfo.maxComputeBufferInputsFragment
maxComputeBufferInputs几何体 请参阅 Device.SystemInfo.maxComputeBufferInputsGeometry
maxComputeBufferInputs域 请参阅 Device.SystemInfo.maxComputeBufferInputsDomain
maxComputeBufferInputs外壳 请参阅 Device.SystemInfo.maxComputeBufferInputsHull
maxComputeBufferInputs计算 请参阅 Device.SystemInfo.maxComputeBufferInputsCompute。
maxComputeWorkGroupSize 请参阅 Device.SystemInfo.maxComputeWorkGroupSize
maxComputeWorkGroupSizeX 请参阅 Device.SystemInfo.maxComputeWorkGroupSizeX
maxComputeWorkGroupSizeY 请参阅 Device.SystemInfo.maxComputeWorkGroupSizeY
maxComputeWorkGroupSizeZ 请参阅 Device.SystemInfo.maxComputeWorkGroupSizeZ
支持异步计算 请参阅 Device.SystemInfo.supportsAsyncCompute
支持图形围栏 请参阅 Device.SystemInfo.supportsGraphicsFence
支持AsyncGPURead返回 请参阅 Device.SystemInfo.supportsAsyncGPUReadback
支持ParallelPSOCreation 请参阅 Device.SystemInfo.supportsParallelPSOCreation
支持光线追踪 请参阅 Device.SystemInfo.supportsRayTracing
支持光线追踪着色器 请参阅 Device.SystemInfo.supportsRayTracingShaders
支持内联光线追踪 请参阅 Device.SystemInfo.supportsInlineRayTracing
支持SetConstantBuffer 请参阅 Device.SystemInfo.supportsSetConstantBuffer
hasMipMaxLevel 请参阅 Device.SystemInfo.hasMipMaxLevel
支持Mip流送 请参阅 Device.SystemInfo.supportsMipStreaming
使用LoadStoreActions 请参阅 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 机型的设备叠加层。

iPhone 8 叠加层,显示 Unity 的默认天空盒填充 iPhone 8 屏幕的区域,您可以在其中点击
iPhone 8 叠加层,显示 Unity 的默认天空盒填充 iPhone 8 屏幕的区域,您可以在其中点击
iPhone XS 叠加层,显示 Unity 的默认天空盒,填充 iPhone XS 屏幕的区域,您可以在其中点击
iPhone XS 叠加层,显示 Unity 的默认天空盒,填充 iPhone XS 屏幕的区域,您可以在其中点击

注意:为了模仿您在使用设备叠加层时看到的内容,这些示例显示 Unity 的默认值天空盒(skybox) 一种特殊类型的材质,用于表示天空。通常是六面的。更多信息
请参阅术语表
在您可以点击的屏幕区域中。在真实设备叠加层中,这些像素应该是透明的。

使用设备叠加层

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

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

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

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