EventType
Types of UnityGUI input and processing events.
Read time 2 minutesLast updated 6 days ago
Definition
- Type: Enum
- Namespace: UnityEngine
- Assembly: UnityEngine.IMGUIModule
public enum EventType
Remarks
Use this to tell which type of event has taken place in the GUI. Types of Events include mouse clicking, mouse dragging, button pressing, the mouse entering or exiting the window, and the scroll wheel as well as others mentioned below.
Events can be used to prevent other GUI elements from responding to that event. Refer to Event.Use.
Examples
//Attach this script to a GameObject//This script is a basic overview of some of the Event Types available. It outputs messages depending on the current Event Type.using UnityEngine;public class Example : MonoBehaviour{ void OnGUI() { Event m_Event = Event.current; if (m_Event.type == EventType.MouseDown) { Debug.Log("Mouse Down."); } if (m_Event.type == EventType.MouseDrag) { Debug.Log("Mouse Dragged."); } if (m_Event.type == EventType.MouseUp) { Debug.Log("Mouse Up."); } }}
using UnityEngine;public class Example : MonoBehaviour{ void OnGUI() { Event m_Event = Event.current; if (m_Event.type == EventType.MouseDown) { if (m_Event.pointerType == PointerType.Pen) //Check if it's a pen event. Debug.Log("Pen Down."); else Debug.Log("Mouse Down."); //If it's not a pen event, it's a mouse event. } }}
Fields
Value | Description |
|---|---|
| ContextClick | User has right-clicked (or control-clicked on the mac). |
| DragExited | Editor only: drag & drop operation exited. |
| DragPerform | Editor only: drag & drop operation performed. |
| DragUpdated | Editor only: drag & drop operation updated. |
| ExecuteCommand | Execute a special command (eg. copy & paste). |
| Ignore | Event should be ignored. |
| KeyDown | A keyboard key was pressed. |
| KeyUp | A keyboard key was released. |
| Layout | A layout event. |
| MouseDown | Mouse button was pressed. |
| MouseDrag | Mouse was dragged. |
| MouseEnterWindow | Mouse entered a window (Editor views only). |
| MouseLeaveWindow | Mouse left a window (Editor views only). |
| MouseMove | Mouse was moved (Editor views only). |
| MouseUp | Mouse button was released. |
| Repaint | A repaint event. One is sent every frame. |
| ScrollWheel | The scroll wheel was moved. |
| TouchDown | Direct manipulation device (finger, pen) touched the screen. |
| TouchEnter | Direct manipulation device (finger, pen) moving into the window (drag). |
| TouchLeave | Direct manipulation device (finger, pen) moved out of the window (drag). |
| TouchMove | Direct manipulation device (finger, pen) moved on the screen (drag). |
| TouchStationary | Direct manipulation device (finger, pen) stationary event (long touch down). |
| TouchUp | Direct manipulation device (finger, pen) left the screen. |
| Used | Already processed event. |
| ValidateCommand | Validates a special command (e.g. copy & paste). |