unity3D:添加设备

发布时间 2023-06-24 14:37:25作者: tuyg

推荐:将NSDT场景编辑器加入你的3D工具链

3D工具集:NSDT简石数字孪生

添加设备

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

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

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

创建设备定义

设备定义是表示设备的 JSON 文件。它既有必需的属性,也有一些可选属性。如果设备定义文件包含任何错误,则当您选择该文件时,这些错误将显示在检查器中。

图式

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

屏幕

属性必填描述
宽度 是 屏幕的宽度(以像素为单位)。
高度 是 屏幕的高度(以像素为单位)。
导航栏高度 否 屏幕 Android 导航栏的高度(以像素为单位),该栏在某些设备上未全屏显示时显示。
新闻部 是 屏幕的 dpi。
指引 否 每个对象描述屏幕可以模拟的方向的对象列表。如果未为此属性设置值,则屏幕支持所有方向。有关每个方向对象的架构的信息,请参阅方向。
介绍 否 描述设备覆盖的对象。有关此对象的架构的信息,请参阅演示文稿。

取向

属性必填描述
取向 是 屏幕方向。此属性的值是映射到屏幕方向枚举的数字。
安全区域 否 确定屏幕安全区域的矩形。如果未为此属性设置值,模拟器将假定整个屏幕是安全的。
切口 否 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.supportsGyroscope。
支持定位服务 否 请参阅 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 项目中包含资源或包目录的目录。例如,如果设备定义文件位于资产/设备目录中,设备覆盖文件位于资产/设备/覆盖目录中,则以下文件路径均有效:

  • 相对于设备定义文件:覆盖/最小设备覆盖.png
  • 相对于包含资产目录的目录:资产/设备/覆盖/最小设备覆盖.png

此文由3D建模学习工作室整理翻译,转载请注明出处!

上一篇:Unity3D:模拟类 (mvrlink.com)

下一篇:Unity3D:扩展设备模拟器 (mvrlink.com)