赞
踩
官方文档链接:http://docs.unity3d.com/460/Documentation/Manual/SupportedEvents.html
部分内容参考:https://blog.csdn.net/lyh916/article/details/44570503
Unity自己的事件系统开放了一些接口,我们只需要实现这些接口就行。但是这个接口所代表的含义需要我们深入理解。
IPointerEnterHandler - OnPointerEnter - Called when a pointer enters the object
指针进入
public void OnPointerEnter(PointerEventData eventData);
IPointerExitHandler - OnPointerExit - Called when a pointer exits the object
指针退出
public void OnPointerExit(PointerEventData eventData);
这个对于鼠标的正键与反键都会响应,在接口的实现中注意用input.getmouse这个来判断当前按下的是鼠标正键还是反键。
需要注意的是,一个对象同时实现了按下抬起两个接口,当鼠标在这个物体上按下触发了按下事件,鼠标不松开的情况下移到另个实现了 抬起接口的物体上,在鼠标抬起的时候,触发的抬起事件对应的仍是第一个点击的物体的。
IPointerDownHandler - OnPointerDown - Called when a pointer is pressed on the object
指针按下
public void OnPointerDown(PointerEventData eventData);
IPointerUpHandler - OnPointerUp - Called when a pointer is released (called on the original the pressed object)
指针释放(可能按下时的指针位置跟释放时的指针位置不同,这里指的是按下时指针指着的物体)
public void OnPointerUp(PointerEventData eventData);
IPointerClickHandler - OnPointerClick - Called when a pointer is pressed and released on the same object
在同一物体上按下并释放
public void OnPointerClick(PointerEventData eventData);
IInitializePotentialDragHandler - OnInitializePotentialDrag - Called when a drag target is found, can be used to initialise values
拖拽时的初始化,跟IPointerDownHandler差不多,在按下时调用
public void OnInitializePotentialDrag(PointerEventData eventData);
IBeginDragHandler - OnBeginDrag - Called on the drag object when dragging is about to begin
开始拖拽
public void OnBeginDrag(PointerEventData eventData);
IDragHandler - OnDrag - Called on the drag object when a drag is happening
拖拽中
public void OnDrag(PointerEventData eventData);
IEndDragHandler - OnEndDrag - Called on the drag object when a drag finishes
拖拽结束(被拖拽的物体调用)
public void OnEndDrag(PointerEventData eventData);
IDropHandler - OnDrop - Called on the object where a drag finishes
拖拽结束(拖拽结束后的位置(即鼠标位置)如果有物体,则那个物体调用)
public void OnDrop(PointerEventData eventData);
IScrollHandler - OnScroll - Called when a mouse wheel scrolls
滚轮滚动
public void OnScroll(PointerEventData eventData);
IUpdateSelectedHandler - OnUpdateSelected - Called on the selected object each tick
被选中的物体每帧调用
public void OnUpdateSelected(BaseEventData eventData);
ISelectHandler - OnSelect - Called when the object becomes the selected object
物体被选中时(EventSystem.current.SetSelectedGameObject(gameObject))
public void OnSelect(BaseEventData eventData);
IDeselectHandler - OnDeselect - Called on the selected object becomes deselected
物体从选中到取消选中时
public void OnDeselect(BaseEventData eventData);
IMoveHandler - OnMove - Called when a move event occurs (left, right, up, down, ect)
物体移动时(与InputManager里的Horizontal和Vertica按键相对应),前提条件是物体被选中
public void OnMove(AxisEventData eventData);
ISubmitHandler - OnSubmit - Called when the submit button is pressed
提交按钮被按下时(与InputManager里的Submit按键相对应,PC上默认的是Enter键),前提条件是物体被选中
public void OnSubmit(BaseEventData eventData);
ICancelHandler - OnCancel - Called when the cancel button is pressed
取消按钮被按下时(与InputManager里的Cancel按键相对应,PC上默认的是Esc键),前提条件是物体被选中
public void OnCancel(BaseEventData eventData);
//
总结:
1.共有17个接口方法
2.其中OnMove使用的参数是AxisEventData eventData
3.其中OnUpdateSelected、OnSelect 、OnDeselect 、OnSubmit 、OnCancel 使用的参数是BaseEventData eventData
4.其余使用的参数是PointerEventData eventData
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。