Version: 2020.2
USS 编写样式表
分发事件

事件系统

UI Toolkit includes an event system that communicates user interactions to visual elements. Inspired by HTML events, the UI Toolkit event system shares many of the same terminology and event naming. The event system is composed of the following:

  • Event dispatcher: The event system listens to events, coming from the operating system or scripts, and dispatches these events with the Event dispatcher. The Event dispatcher also determines the dispatching strategy used to send events to visual elements and other supporting classes.
  • 事件处理程序:当事件发生在面板内时,事件将发送到面板中的 VisualElement 树。可以向视觉元素添加事件处理程序,从而在发生事件时响应某些事件类型。请参阅事件响应
  • 事件合成程序:操作系统并非事件的唯一来源。脚本也可以通过分发程序创建和分发事件。请参阅合成事件以了解有关创建和分发事件的更多信息。
  • 事件类型:根据 EventBase 将不同的事件类型组织成一个层级视图,并将其分组为不同的系列。每个事件系列都实现了一个接口;该接口定义了同一系列的所有事件的共同特征。例如,MouseUpEventMouseDownEvent 和其他鼠标事件实现了 IMouseEvent 接口。此接口指定每个鼠标事件都有一个位置、一个按下的按钮、一组修改器和其他与鼠标相关的事件类型。请参阅事件类型参考以了解有关每个事件系列及其 UIElement 事件类型的描述。

还可以使用事件将其他类型的消息传递给视觉元素。例如,ContextualMenuManager 使用 ContextualMenuPopulateEvent 将菜单项添加到上下文菜单。请参阅内置控件


  • 2018–11–02 页面已修订
USS 编写样式表
分发事件
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961