EventSystem

 

The EventSystem is a way of sending events to objects in the application based on input, be it keyboard, mouse, touch, or custom input. The EventSystem consists of a few components that work together to send events.

Overview

When you add an EventSystem component to a GameObject you will notice that it does not have much functionality exposed, this is because the EventSystem itself is designed as a manager and facilitator of communication between EventSystem modules.

The primary roles of the EventSystem are as follows:

  • Manage which GameObject is considered selected
  • Manage which InputModule is in use
  • Manage Raycasting (if required)
  • Updating all InputModules as required

Input Modules

An input module is where the main logic of how you want the EventSystem to behave lives, they are used for

  • Handling Input
  • Managing event state
  • Sending events to scene objects.

Only one InputModule can be active in the EventSystem at a time, and they must be components on the same GameObject as the EventSystem component.

If you wish to write a custom input module it is recommended that you send events supported by existing UI components in Unity, but you are also able to extend and write your own events as detailed in the Messaging System documentation.

Raycasters

Raycasters are used for sending figuring out what the pointer is over, it is common for InputModules to use the Raycasters configured in the scene to calculate what the pointing device is over.

There are 3 provided Raycasters that exist by default:

  • GraphicRaycaster - Used for UI elements
  • 2DPhysicsRaycaster - Used for 2D physics elements
  • 3DPhysicsRaycaster - Used for 3D physics elements

If you have a 2d / 3d Raycaster configured in your scene it is easily possible to have non UI elements receive messages from the InputModule. Simply attach a script that implements one of the event interfaces.

Supported Events

 

The Eventsystem supports a number of events, and they can be customised further in user custom user written InputModules.

The events that are supported by the StandaloneInputModule and TouchInputModule are provided by interface and can be implemented on a MonoBehaviour by implementing the interface. If you have a valid EventSystem configured the events will be called at the correct time.

  • IPointerEnterHandler - OnPointerEnter - Called when a pointer enters the object
  • IPointerExitHandler - OnPointerExit - Called when a pointer exits the object
  • IPointerDownHandler - OnPointerDown - Called when a pointer is pressed on the object
  • IPointerUpHandler - OnPointerUp - Called when a pointer is released (called on the original the pressed object)
  • IPointerClickHandler - OnPointerClick - Called when a pointer is pressed and released on the same object
  • IInitializePotentialDragHandler - OnInitializePotentialDrag - Called when a drag target is found, can be used to initialise values
  • IBeginDragHandler - OnBeginDrag - Called on the drag object when dragging is about to begin
  • IDragHandler - OnDrag - Called on the drag object when a drag is happening
  • IEndDragHandler - OnEndDrag - Called on the drag object when a drag finishes
  • IDropHandler - OnDrop - Called on the object where a drag finishes
  • IScrollHandler - OnScroll - Called when a mouse wheel scrolls
  • IUpdateSelectedHandler - OnUpdateSelected - Called on the selected object each tick
  • ISelectHandler - OnSelect - Called when the object becomes the selected object
  • IDeselectHandler - OnDeselect - Called on the selected object becomes deselected
  • IMoveHandler - OnMove - Called when a move event occurs (left, right, up, down, ect)
  • ISubmitHandler - OnSubmit - Called when the submit button is pressed
  • ICancelHandler - OnCancel - Called when the cancel button is pressed

【转】UGUI EventSystem的更多相关文章

  1. UGUI EventSystem.current.IsPointerOverGameObject(),判断是否进入了UI上

    EventSystem.current.IsPointerOverGameObject(); //返回一个布尔值,进入了UI上就返回true,用的时候要 using UnityEngine.Event ...

  2. Unity3D之UGUI学习笔记(三):EventSystem

    在UGUI中,EventSystem实现了所有关于交互方面的功能,和NGUI不一样的地方是,我们终于可以摆脱添加Box Collider了! 下面我们来学习一下. 对于按钮来说,直接有onClick的 ...

  3. Unity UGUI之Canvas&EventSystem

    最近想写一套关于UGUI所有控件的基础使用教程系列,主要是根据本人的使用心得来写的,所以其中可能难以避免会有不正确的地方. 好了进入主题,既然是第一篇,我觉得我有必要先介绍一下UGUI必不可缺的两个组 ...

  4. UGUI之Canvas和EventSystem

    先介绍一下UGUI必不可缺的两个组件:Canvas和EventSystem 事实上在场景中第一次创建UGUI控件的时候,这两个物体都会自动添加到场景中,当然,必不可缺的不是这两个物体,而是他们身上挂载 ...

  5. UGUI源码之EventSystem

    今天研究下UGUI的源码,先从EventSystem入手.EventSystem是用来处理点击.键盘输入以及触摸等事件的. 1.BaseInputModule EventSystem开头声明了两个变量 ...

  6. (二十二)unity4.6学习Ugui中文文档-------交互-Eventsystem & Binding

    大家好,我是孙广东.   转载请注明出处:http://write.blog.csdn.net/postedit/38922399 更全的内容请看我的游戏蛮牛地址:http://www.unityma ...

  7. UGUI研究院之控件以及按钮的监听事件系统

    继续学习,我相信大家在做NGUI开发的时候处理事件都会用到UIEventListener,那么UGUI中怎么办呢?先看UGUI的事件有那些吧 Supported Events The Eventsys ...

  8. Unity -- EventSystem完全掌握

    Event System 组成 系统生成的Event System里面主要有两个Components,分别是Event System和Standalone Input Module. 其中Standa ...

  9. UGUI代码分析

    1.canvas,screen模式和world模式区别:screen的绑定摄像机与canvas相对位置不会改变不可改变canvas,world模式下有个event camera相对位置可改变,canv ...

随机推荐

  1. 从.net到java,从基础架构到解决方案。

    这一年,职业生涯中的最大变化,是从.net到java的直接跨越,是从平台架构到解决方案的不断完善. 砥砺前行 初出茅庐,天下无敌.再学三年,寸步难行.很多时候不是别人太强,真的是自己太弱,却不自知. ...

  2. JAVA设计模式初探之桥接模式

    生活中的一个例子:    拿汽车在路上行驶的来说.既有小汽车又有公共汽车,它们都不但能在市区中的公路上行驶,也能在高速公路上行驶.这你会发现,对于交通工具(汽车)有不同的类型,它们所行驶的环境(路)也 ...

  3. 2018.6.21 css的应用---注册表格

    参与css样式表格的注册表单 <!DOCTYPE html> <head> <meta charset="UTF-8" /> <meta ...

  4. 一些常用的集合工具的代码块(缓慢更新XD,更新了多属性过滤:) )

    更新记录 虽然经常放鸽子,但是还是要记录一下更新 2017.8.30 更新了listToMap的方法,现在可以指定多个属性进行分组了,例如你要指定一个学生集合,按照名字和年龄相同的放在一组,现在只要调 ...

  5. tensorfow install error

    http://stackoverflow.com/questions/33655731/error-while-importing-tensorflow-in-python2-7-in-ubuntu- ...

  6. C#自增运算符(++)

    一.C#自增运算符(++) 自增运算符(++)是将操作数加1. 1. 前缀自增运算符 前缀自增运算符是“先加1,后使用”.它的运算结果是操作数加1之后的值. 例如: ++x;  // 前缀自增运算符 ...

  7. ASIHTTPRequest的使用

    本文转自csdn ASIHTTPRequest对CFNetwork API进行了封装,并且使用起来非常简单,用Objective-C编写,可以很好的应用在Mac OS X系统和iOS平台的应用程序中. ...

  8. Centos7 PHP的安装和配置

    前面Nginx和httpd的安装都是为了支持PHP而弄的,然后这个目标就给了我一沉重的打击,等我慢慢道来,先来说说PHP的安装和配置吧. 一.PHP的安装 1.由于linux的yum源不存在php7. ...

  9. ZendFramework-2.4 源代码 - ViewManager类图

  10. 利用python生成图形验证码

    validCode.py import random from io import BytesIO from PIL import Image, ImageDraw, ImageFont def ge ...