使用事件系统可以根据输入(即键盘、鼠标、触摸或自定义输入)将事件发送到应用程序中的对象。事件系统包含一些共同协作以发送事件的组件。
将事件系统组件添加到游戏对象时,应该会注意到该组件未公开太多功能,这是因为事件系统本身设计为事件系统模块之间通信的管理器和协调器。
事件系统的主要作用如下:
输入模块包含定义事件系统行为方式的主要逻辑,可用于:
事件系统中一次只能有一个输入模块处于激活状态,这些输入模块必须是与事件系统组件位于同一游戏对象上的组件。
如果希望编写自定义输入模块,请发送 Unity 中现有 UI 组件支持的事件。要扩展或编写您自己的事件,请参阅消息系统文档。
射线投射器用于确定指针在哪个对象上方。输入模块通常使用场景中配置的射线投射器来计算指针设备位于哪个对象上方。
默认情况下提供了 3 种射线投射器:
If you have a 2d / 3d Raycaster configured in your Scene, it is easy to make non-UI elements receive messages from the Input Module. Simply attach a script that implements one of the event interfaces. For examples of this, see the IPointerEnterHandler and IPointerClickHandler Scripting Reference pages.
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.