Wing的小站

  • 首页
  • 小工具
  • IT新闻
  • 技术文章
  • 生活随笔
  • 休闲娱乐
  • 个人作品
  • 留言板
  • 关于博主
  1. 首页
  2. 技术文章
  3. 正文

Unity3D UGUI事件处理

2015年7月19日 5708点热度 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
取消回复

分类
  • IT新闻 / 11篇
  • 个人作品 / 4篇
  • 休闲娱乐 / 5篇
  • 其他学习 / 1篇
  • 技术文章 / 117篇
  • 生活随笔 / 40篇
  • 行业新闻 / 1篇
  • 默认 / 7篇
标签聚合
游戏 随笔 Android Studio 作品 Unity 随拍 opengl 游记 IOS 从零开始学习JavaFX MFC 特色 从零开始学习OpenGL javafx C++ NGUI XCode Swift 光谷 Android
归档
  • 2026 年 11 月 / 1篇
  • 2024 年 5 月 / 2篇
  • 2023 年 12 月 / 1篇
  • 2023 年 8 月 / 1篇
  • 2022 年 6 月 / 1篇
  • 2021 年 9 月 / 1篇
  • 2021 年 5 月 / 1篇
  • 2021 年 1 月 / 1篇
  • 2020 年 9 月 / 1篇
  • 2020 年 8 月 / 1篇
  • 2020 年 6 月 / 2篇
  • 2020 年 3 月 / 1篇
  • 2020 年 2 月 / 3篇
  • 2019 年 12 月 / 2篇
  • 2019 年 11 月 / 1篇
  • 2019 年 9 月 / 1篇
  • 2019 年 7 月 / 1篇
  • 2018 年 10 月 / 2篇
  • 2018 年 9 月 / 2篇
  • 2018 年 5 月 / 1篇
  • 2018 年 4 月 / 8篇
  • 2018 年 3 月 / 1篇
  • 2018 年 2 月 / 1篇
  • 2017 年 12 月 / 2篇
  • 2017 年 8 月 / 2篇
  • 2017 年 7 月 / 3篇
  • 2017 年 6 月 / 2篇
  • 2017 年 5 月 / 8篇
  • 2017 年 4 月 / 15篇
  • 2017 年 3 月 / 2篇
  • 2017 年 1 月 / 1篇
  • 2016 年 11 月 / 4篇
  • 2016 年 9 月 / 2篇
  • 2016 年 8 月 / 3篇
  • 2016 年 7 月 / 3篇
  • 2016 年 6 月 / 1篇
  • 2016 年 4 月 / 2篇
  • 2016 年 2 月 / 2篇
  • 2016 年 1 月 / 2篇
  • 2015 年 11 月 / 2篇
  • 2015 年 10 月 / 2篇
  • 2015 年 9 月 / 4篇
  • 2015 年 8 月 / 2篇
  • 2015 年 7 月 / 11篇
  • 2015 年 6 月 / 10篇
  • 2015 年 5 月 / 3篇
  • 2015 年 4 月 / 3篇
  • 2015 年 3 月 / 4篇
  • 2015 年 2 月 / 4篇
  • 2015 年 1 月 / 7篇
  • 2014 年 12 月 / 19篇
  • 2014 年 11 月 / 4篇
  • 2014 年 10 月 / 6篇
  • 2014 年 9 月 / 5篇
  • 2014 年 8 月 / 2篇
  • 2014 年 7 月 / 3篇
网站统计
  • 17
  • 17
  • 1,758,466
  • 182
  • 144

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

Theme Kratos Made By Seaton Jiang