Unity3D:添加设备

Unity3D:添加设备

推荐:将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)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值