# 模拟类

> Contains information on classes the Device Simulator provides so you can test code that responds to device-specific behavior.

Device Simulator 提供了模拟类，可用于测试能够响应 Device Simulator 中特定于设备的行为的代码。

以下模拟类位于 UnityEngine.Device 命名空间中：

* [应用程序](/engine/6000.0/script-reference/unity-engine-device/application.md) (Application)：
* [Screen](/engine/6000.0/script-reference/unity-engine-device/screen.md)
* [SystemInfo](/engine/6000.0/script-reference/unity-engine-device/system-info.md)

这些模拟类的成员，与其常规 UnityEngine 命名空间对应类的成员相同。您可以在代码库中的任何位置使用它们，就像在通常情况下使用常规类一样。对性能没有影响，因此您可以在发布版本中使用。

在编辑器中，当 Device Simulator处于[活动](/engine/6000.0/manual/unity-editor/using-the-editor/device-simulator/introduction.md#limitations)状态时，模拟类会对模拟设备的特定于平台的行为进行模拟；例如，[Device.SystemInfo.operatingSystem](/engine/6000.0/script-reference/unity-engine-device/system-info/operating-system.md) 返回模拟设备的 Android 或 iOS 版本。

在构建的应用程序中，或者在 Device Simulator未激活时，模拟类的行为与 UnityEngine 命名空间中的类相同。

虽然模拟类的成员与常规类相同，但 Device Simulator 不会模拟所有行为。在 UnityEditor 中，Device Simulator 未模拟的成员具有与其 UnityEngine 等效对象相同的行为，这与平台无关。例如，Device Simulator 不会模拟 [Device.Screen.brightness](/engine/6000.0/script-reference/unity-engine-device/screen/brightness.md)。这意味着此成员具有与 [UnityEngine.Screen.brightness](/engine/6000.0/script-reference/unity-engine/screen/brightness.md) 相同的编辑器内行为，后者始终返回 `1`。有关 Device Simulator 模拟的成员的信息，请参阅 API 文档：

* [Device.Application](/engine/6000.0/script-reference/unity-engine-device/application.md)
* [Device.Screen](/engine/6000.0/script-reference/unity-engine-device/screen.md)
* [Device.SystemInfo](/engine/6000.0/script-reference/unity-engine-device/system-info.md)

## 更新脚本以使用模拟类

如果要转换现有代码，以使用 UnityEngine.Device 命名空间中的类，最佳做法是使用[别名指令](https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/using-directive)。例如：

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

这样就可以更改整个文件使用的类，而不是更改每个 API 调用。
