Version: 2020.1
USS Writing style sheets
Dispatching Events

The Event System

UI Toolkit includes an event systemA way of sending events to objects in the application based on input, be it keyboard, mouse, touch, or custom input. The Event System consists of a few components that work together to send events. More info
See in Glossary
that communicates user interactions to visual elements. Inspired by HTML events, the UI(User Interface) Allows a user to interact with your application. More info
See in Glossary
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 scriptsA piece of code that allows you to create your own Components, trigger game events, modify Component properties over time and respond to user input in any way you like. More info
    See in Glossary
    , 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.
  • Event handler: When an event occurs inside a panel, the event is sent to the VisualElement tree within the panel. You can add event handlers to visual elements to respond to certain event types when they occur. See Responding to events.
  • Event synthesizer: The operating system is not the only source of events. Scripts can also create and dispatch events through the dispatcher. See Synthesizing Events for more on creating and dispatching events.
  • Event types: The different event types are organized into a hierarchy based on EventBase and grouped into families. Each family of events implements an interface that defines the common characteristics for all events of the same family. For example, MouseUpEvent, MouseDownEvent and other mouse events implement the IMouseEvent inteface. This interface specifies that each mouse event has a position, a pressed button, a set of modifers, and other mouse-related event types. See Event type reference for a description of each event family and their UIElement event types.

You can also use events to communicate other types of messages to visual elements. For example, the ContextualMenuManager uses the ContextualMenuPopulateEvent to add items to a contextual menu. See built-in controls.

  • 2018–11–02 Page amended
USS Writing style sheets
Dispatching Events
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。