Wing的小站

  • 首页
  • IT新闻
  • 技术文章
  • 生活随笔
  • 休闲娱乐
  • 个人作品
  • 留言板
  • 关于博主
JavaFX,Unity3D,Android,IOS,技术教程,生活随笔
  1. 首页
  2. 技术文章
  3. 正文

Unity3D UGUI事件处理

2015年7月19日 4600点热度 0人点赞 0条评论

由于Unity3D官方出了新的UI系统,导致了不少的NGUI用户转向了UGUI。虽然现在UGUI相关的控件脚本等不及NGUI,但随着AssetStore里各种插件的开发,UGUI的发展前景还是比较看好的。

UGUI里面的事件处理代码跟NGUI不同,主要是通过实现接口方法来执行事件。

提供的接口如下:

  • 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

其实很好理解,就是一些点击进入拖动等操作,实现相应的接口即可。

例如点击事件:

using UnityEngine;
using System.Collections;
using UnityEngine.EventSystems;

public class TestPointerEnterEvent : MonoBehaviour,IPointerClickHandler
{
    public void OnPointerClick(PointerEventData data)
    {
        Debug.Log("Pointer click.");
    }
}

不过UGUI目前在鼠标事件和控件事件上有重叠,比如在点击控件的时候没有屏蔽掉鼠标事件,我也只是用其他方法来解决的,但我在stackoverflow上搜索的,暂时还没有完美的解决方案,不知道后续要怎么搞。

标签: UGUI Unity
最后更新:2017年4月14日

wing1314

这个人很懒,什么都没留下

点赞
< 上一篇
下一篇 >

文章评论

razz evil exclaim smile redface biggrin eek confused idea lol mad twisted rolleyes wink cool arrow neutral cry mrgreen drooling persevering
取消回复

COPYRIGHT © 2023 Wing的小站. ALL RIGHTS RESERVED.

Theme Kratos Made By Seaton Jiang

鄂ICP备17006951号-1

42011102000591