---
title: 扩展 Device Simulator
product: Unity Editor
version: '6000.0'
latest_version: '7000.0'
status: outdated
canonical: https://docs.unity.com/zh-cn/engine/6000.0/manual/unity-editor/using-the-editor/device-simulator/plugins
latest_url: https://docs.unity.com/zh-cn/engine/7000.0/manual/unity-editor/using-the-editor/device-simulator/plugins.md
generated_at: 2026-11-02T22:28:14.058Z
locale: zh-cn
---

# 扩展 Device Simulator

> **Note:** This page documents version 6000.0. The latest version is 7000.0: https://docs.unity.com/zh-cn/engine/7000.0/manual/unity-editor/using-the-editor/device-simulator/plugins.md

> Explains how to create Device Simulator plugins to extend the functionality and user interface of the Simulator view.

Device Simulator 支持用插件来扩展其功能，并在 Simulator 视图中更改控制面板的 UI。

## 创建插件

要创建 Device Simulator 插件，请扩展 [DeviceSimulatorPlugin](/engine/6000.0/script-reference/unity-editor-device-simulation/device-simulator-plugin.md) 类。

要将 UI 插入到 Device Simulator 视图中，插件必须：

* 覆盖 `title` 属性以返回非空字符串。
* 覆盖 `OnCreateUI` 方法以返回包含 UI 的 [VisualElement](/engine/6000.0/script-reference/unity-engine-ui-elements/visual-element.md)。

如果插件不符合这些条件，Device Simulator 会实例化插件，但不会在 Simulator 视图中显示其 UI。

以下示例演示了如何创建覆盖游戏作品属性，并将 UI 添加到 Simulator 视图的插件。

```lang-csharp
public class TouchInfoPlugin : DeviceSimulatorPlugin
{
    public override string title => "Touch Info";
    private Label m_TouchCountLabel;
    private Label m_LastTouchEvent;
    private Button m_ResetCountButton;

    [SerializeField]
    private int m_TouchCount = 0;

    public override void OnCreate()
    {
        deviceSimulator.touchScreenInput += touchEvent =>
        {
            m_TouchCount += 1;
            UpdateTouchCounterText();
            m_LastTouchEvent.text = $"Last touch event: {touchEvent.phase.ToString()}";
        };
    }

    public override VisualElement OnCreateUI()
    {
        VisualElement root = new VisualElement();
        
        m_LastTouchEvent = new Label("Last touch event: None");
        
        m_TouchCountLabel = new Label();
        UpdateTouchCounterText();

        m_ResetCountButton = new Button {text = "Reset Count" };
        m_ResetCountButton.clicked += () =>
        {
            m_TouchCount = 0;
            UpdateTouchCounterText();
        };

        root.Add(m_LastTouchEvent);
        root.Add(m_TouchCountLabel);
        root.Add(m_ResetCountButton);
            
        return root;
    }

    private void UpdateTouchCounterText()
    {
        if (m_TouchCount > 0)
            m_TouchCountLabel.text = $"Touches recorded: {m_TouchCount}";
        else
            m_TouchCountLabel.text = "No taps recorded";
    }
}
```
