Unity3D FingerGestures 手势插件使用
FingerGestures 下載地址(免積分的)點(diǎn)擊打開鏈接FingerGestures v3.1
?
原價(jià)$45
https://www.assetstore.unity3d.com/en/#!/content/1044
請支持正版
?
1,unity導(dǎo)入FingerGestures 包,
?
2,找到FingerGestures的Prefabs如下圖:
?
?
將此Prefabs拖入Hierarchy的根節(jié)點(diǎn)如下圖:
?
?
?
3,選中需要加入手勢識別的物體
在菜單中入加識別的腳本,如下圖:
本例采用Swipe Recognizer(滑動(dòng)識別)
?
4,添加好腳本后在物體上可以看到添加的腳本如下圖:
?
?
Message Name表示滑動(dòng)時(shí),組件調(diào)用的方法名
Message Target 表示調(diào)動(dòng)的發(fā)送消息的目標(biāo)(空的GameObject 綁定一個(gè)腳本,腳本中含有OnSwipe方法)
public void OnSwipe(SwipeGesture gesture)
??? {
??????? // 完整的滑動(dòng)數(shù)據(jù)
??????? Vector2 move = gesture.Move;
??????? // 滑動(dòng)的速度
??????? float velocity = gesture.Velocity;
??????? // 大概的滑動(dòng)方向
??????? FingerGestures.SwipeDirection direction = gesture.Direction;
?
??????? Debug.Log("OnSwipe,move=" + move.ToString() + ",velocity=" + velocity + ",direction=" + direction.ToString());
??? }
到此就可以成功滑動(dòng)了。
?
其它的手勢也基本類似
附上一些用法:
FingerGestures提供了3種不同的方法來檢測由用戶執(zhí)行的拖動(dòng)手勢。
- 方法1:使用默認(rèn)的手勢事件
- 每個(gè)手指的手勢事件:為每個(gè)單獨(dú)的手指,獨(dú)立的狀態(tài)
- OnFingerTap
- OnFingerDoubleTap
- OnFingerSwipe
- OnFingerLongPress
- OnFingerDragBegin,OnFingerDragMove,OnFingerDragEnd
- 全局手勢事件:
- 當(dāng)一個(gè)手指觸摸屏幕上:
- OnTAP
- OnDoubleTap
- OnSwipe
- OnLongPress
- OnDragBegin,OnDragMove,OnDragEnd
- 兩個(gè)手指觸摸屏幕時(shí):
- OnPinchBegin,OnPinchMove,OnPinchEnd
- OnRotationBegin,OnRotationMove,OnRotationEnd
- OnTwoFingerTap
- OnTwoFingerSwipe
- OnTwoFingerLongPress
- OnTwoFingerDragBegin,OnTwoFingerDragMove,OnTwoFingerDragEnd
- 方法2:使用一個(gè)DragGestureRecognizer
- 方法3:使用“工具箱”
工具箱是一種更高級方便的方式,設(shè)計(jì)的理念是開箱就用,包括了很多腳本,但是沒有涉及到核心源碼,所以不用的話 ?可以把這個(gè)包直接刪掉
?
?
?
?
總結(jié)
以上是生活随笔為你收集整理的Unity3D FingerGestures 手势插件使用的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: ERP - ERP项目实施考核办法
- 下一篇: WIN11下连不上车机ADB解决方案1