UGUI - 长按事件实现
来源:互联网 发布:sql查询表语句怎么写 编辑:程序博客网 时间:2024/05/28 16:16
直接上代码:
/*************************************************** * 文件名: UGUI_LongPressListener.cs * 时 间: 2015-12-12 14:42:08 * 作 者: AnYuanLzh ***************************************************/using UnityEngine;using UnityEngine.EventSystems;using UnityEngine.Events;public class UGUI_LongPressListener : MonoBehaviour, IPointerDownHandler, IPointerUpHandler, IPointerExitHandler{ public float interval = 0.5f; public UnityEvent onLongPress = new UnityEvent(); bool isPressing = false; int fingerId = -10; float last_time_press_down = 0f; // Update is called once per frame void Update () { ProcessLongPress(); } void ProcessLongPress() { if (isPressing && fingerId != -10) { Debug.Log("time: " + (Time.time - last_time_press_down)); if (Time.time - last_time_press_down >= interval) { onLongPress.Invoke(); last_time_press_down = Time.time; isPressing = false; fingerId = -10; } } } public void OnPointerDown(PointerEventData eventData) { Debug.Log("OnPointerDown"); if (fingerId != -10) return; isPressing = true; fingerId = eventData.pointerId; last_time_press_down = Time.time; } public void OnPointerUp(PointerEventData eventData) { Debug.Log("OnPointerUp"); if(eventData.pointerId != fingerId) return; isPressing = false; last_time_press_down = Time.time; fingerId = -1; } public void OnPointerExit(PointerEventData eventData) { Debug.Log("OnPointerExit"); if (eventData.pointerId != fingerId) return; isPressing = false; last_time_press_down = Time.time; fingerId = -1; }}
0 0
- UGUI - 长按事件实现
- UGUI - 长按事件实现
- Unity uGUI 长按事件
- Unity教程之-对UGUI长按事件的实现
- Unity事件系统实现uGUI Button长按
- Unity3D UGUI按钮长按事件
- UGUI鼠标事件绑定+鼠标长按
- UGUI 实现Button长按效果(RepeatButton)
- Unity3d使用UGUI实现长按功能
- Unity3d使用UGUI实现长按功能
- UGUI实现接口事件
- 【UGUI】Unity的UGUI实现Button按钮长按状态的判断
- 【UGUI】Unity的UGUI实现Button按钮长按状态的判断
- 【UGUI】Unity的UGUI实现Button按钮长按状态的判断
- IOS UIbutton的长按事件实现
- android 自定义View实现长按事件
- Cocos2d-x Lua实现长按事件
- [UnityUI]UGUI按钮长按效果
- 有趣的数
- 《TCP/IP详解 卷1:协议》 读书笔记 第十一章 UDP:用户数据报协议
- Linux 内核 虚拟地址 物理地址 转换
- VS2012下X64平台嵌入汇编程序
- Android优化(二)——代码优化
- UGUI - 长按事件实现
- Hdu 1195 Open the Lock
- 每个android开发者都应该知道的Top 5三方库(2015版)
- java线程学习
- java内部类之方法内部类
- C语言的printf函数的执行顺序
- 单例设计模式
- scanf/fscanf 的%[]和%n使用方法 http://blog.csdn.net/wesweeky/article/details/6439777
- 解一元三次方程