UnityGUI 输入和处理事件的类型。
使用它来辨别在 GUI 中发生了哪种类型的事件。Events 类型包括鼠标点击、鼠标拖动、按下按钮、鼠标进入或退出窗口、滚轮以及以下提到的其他类型。
Events can be used to prevent other GUI elements from responding to that event. Refer to Event.Use.
另请参阅:Event.type、Event、GUI Scripting Guide。
//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."); } } }
MouseDown | 按下了鼠标键。 |
MouseUp | 释放了鼠标键。 |
MouseMove | 移动了鼠标(仅限 Editor 视图)。 |
MouseDrag | 拖动了鼠标。 |
KeyDown | 按下了一个键盘键。 |
KeyUp | 释放了一个键盘键。 |
ScrollWheel | 移动了滚轮。 |
Repaint | 重绘事件。每一帧都发送一个。 |
Layout | 布局事件。 |
DragUpdated | 仅限 Editor:拖放操作已更新。 |
DragPerform | 仅限 Editor:拖放操作已执行。 |
DragExited | 仅限 Editor:拖放操作已退出。 |
Ignore | 应忽略 Event。 |
Used | 已经处理了事件。 |
ValidateCommand | 验证特殊命令(例如复制和粘贴)。 |
ExecuteCommand | 执行特殊命令(例如复制和粘贴)。 |
ContextClick | 用户已点击了右键(或者在 Mac 上点击了 Control)。 |
MouseEnterWindow | 鼠标进入了某个窗口(仅限 Editor 视图)。 |
MouseLeaveWindow | 鼠标离开了某个窗口(仅限 Editor 视图)。 |
TouchDown | Direct manipulation device (finger, pen) touched the screen. |
TouchUp | Direct manipulation device (finger, pen) left the screen. |
TouchMove | Direct manipulation device (finger, pen) moved on the screen (drag). |
TouchEnter | Direct manipulation device (finger, pen) moving into the window (drag). |
TouchLeave | Direct manipulation device (finger, pen) moved out of the window (drag). |
TouchStationary | Direct manipulation device (finger, pen) stationary event (long touch down). |
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.