Version: 2022.3
Language : English
The Simulator view
Adding a device

Simulated classes

The Device Simulator provides simulated classes, which you can use to test code that responds to device-specific behaviors in the Device Simulator.

The following simulated classes are in the UnityEngine.Device namespace:

These simulated classes have the same members as their regular UnityEngine namespace counterparts. You can use them anywhere in your codebase where you would normally use the regular classes. There is no performance impact, and you can use them in release builds.

In the Editor, when the Device Simulator is active, the simulated classes mimic the platform-specific behaviors of the simulated device; for example, Device.SystemInfo.operatingSystem returns the Android or iOS version of the simulated device.

In a built application, or when the Device Simulator isn’t active, the simulated classes have the same behavior as their counterparts in the UnityEngine namespace.

Although the simulated classes have the same members as the regular classes, the Device Simulator doesn’t simulate every behavior. In the UnityEditor, members that the Device Simulator doesn’t simulate have the same behavior as their UnityEngine equivalent, which isn’t platform-dependent. For example, the Device Simulator doesn’t simulate Device.Screen.brightness. This means this member has the same in-Editor behavior as UnityEngine.Screen.brightness, which always returns 1. For information on which members the Device Simulator simulates, see the API documentation for:

Updating your scripts to use simulated classes

If you want to convert existing code to use classes from the UnityEngine.Device namespace, it’s best practice to use alias directives. For example:

using Screen = UnityEngine.Device.Screen;
using Application = UnityEngine.Device.Application;
using SystemInfo = UnityEngine.Device.SystemInfo;

This way you can change which class the entire file uses and not change every API call.

The Simulator view
Adding a device
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961