UGUI UI操作事件
来源:互联网 发布:历史虚无主义批判知乎 编辑:程序博客网 时间:2024/05/22 02:22
刚写了一个UI点击事件捕获脚本。
using UnityEngine; using UnityEngine.EventSystems;public delegate void UIEventHandler(object args);public class UIEventSender : MonoBehaviour, IPointerClickHandler, IPointerDownHandler, IPointerUpHandler, IPointerEnterHandler, IPointerExitHandler{ private UIEventHandler onClickHandler; private object clickArgs; private UIEventHandler onPointHandler; private object downArgs; private UIEventHandler onUpHandler; private object upArgs; private UIEventHandler onEnterHandler; private object enterArgs; private UIEventHandler onExitHandler; private object exitArgs; public void OnPointerClick(PointerEventData eventData) { CallEventHandler(onClickHandler, clickArgs); } public void OnPointerDown(PointerEventData eventData) { CallEventHandler(onPointHandler, downArgs); } public void OnPointerEnter(PointerEventData eventData) { CallEventHandler(onEnterHandler, enterArgs); } public void OnPointerExit(PointerEventData eventData) { CallEventHandler(onExitHandler, exitArgs); } public void OnPointerUp(PointerEventData eventData) { CallEventHandler(onUpHandler, upArgs); } private void CallEventHandler(UIEventHandler evtHandler, object args) { if (null == evtHandler) { Debug.LogWarning("UIEventSender CallEventHandler evtHandler is null!"); return; } try { evtHandler(args); } catch (System.Exception exp) { Debug.LogException(exp); } }}只要给控件添加一个这样的脚本,给几个事件回调和参数赋值,就可以捕获UI事件了。我没有使用继承UnityEngine.EventSystems.EventTrigger,因为继承它会导致多个事件冲突,比如滚动列表中的Item的点击事件和Drag事件,只能捕获点击事件。
0 0
- UGUI UI操作事件
- 记UGUI中一些UI事件接口等
- unity之UGUI去掉UI事件拦截(穿透)
- 【UGUI】Unity4.6 UI按钮绑定事件(一)
- 【UGUI】Unity4.6 UI按钮绑定事件(二)
- 【UGUI】Unity4.6 UI按钮绑定事件(三)
- 【UGUI】Unity4.6 UI按钮绑定事件(四)
- Unity UGUI中按钮自动触发UI事件
- UGUI 事件
- UGUI事件
- Unity UGUI——UI控件的鼠标快捷操作
- 【UGUI】UGUI 防止UI穿透
- 【UGUI】unity3D中ugui事件
- 【UGUI】UGUI的事件监听
- UGUI EventSystems UI拖拽
- UGUI-UI添加特效
- 【Unity3D】【UGUI】UI Overview
- UGUI射线穿透UI
- 在Myeclipse里使用Junit
- Rebirth 认认真真的成为Android大拿!
- 数值的整数次方
- Laravel 学习笔记——路由(中间件与路由组)
- 选择排序
- UGUI UI操作事件
- PHP学习笔记-PHP语言基础1
- scoiday1T3&&bzoj4445小凸想跑步
- C++ 进阶——object slicing 与虚函数与dynamic_cast<>
- Android之Notification
- 插入排序
- http://blog.csdn.net/olanlanxiari/article/details/8104505
- Mac常见问题解决
- Ubuntu下控制蜂鸣器