日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Unity手势插件FingerGestures

發布時間:2023/12/20 编程问答 38 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Unity手势插件FingerGestures 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

點擊下載FingerGestures手勢插件

1、拖入Finger Gestures Initializer預制資源,在任意對象上添加以下腳本即可使用,注意:相機Camera的tag是MainCamera。

using UnityEngine; using System.Collections;public class FingerEvent : MonoBehaviour {void OnEnable(){//啟動時調用,這里開始注冊手勢操作的事件。//按下事件: OnFingerDown就是按下事件監聽的方法,這個名子可以由你來自定義。方法只能在本類中監聽。下面所有的事件都一樣!!!FingerGestures.OnFingerDown += OnFingerDown;//抬起事件FingerGestures.OnFingerUp += OnFingerUp;//開始拖動事件FingerGestures.OnFingerDragBegin += OnFingerDragBegin;//拖動中事件...FingerGestures.OnFingerDragMove += OnFingerDragMove;//拖動結束事件FingerGestures.OnFingerDragEnd += OnFingerDragEnd; //上、下、左、右、四個方向的手勢滑動FingerGestures.OnFingerSwipe += OnFingerSwipe;//連擊事件 連續點擊事件FingerGestures.OnFingerTap += OnFingerTap;//按下事件后調用一下三個方法FingerGestures.OnFingerStationaryBegin += OnFingerStationaryBegin;FingerGestures.OnFingerStationary += OnFingerStationary;FingerGestures.OnFingerStationaryEnd += OnFingerStationaryEnd;//長按事件FingerGestures.OnFingerLongPress += OnFingerLongPress;}void OnDisable(){//關閉時調用,這里銷毀手勢操作的事件//和上面一樣FingerGestures.OnFingerDown -= OnFingerDown;FingerGestures.OnFingerUp -= OnFingerUp;FingerGestures.OnFingerDragBegin -= OnFingerDragBegin;FingerGestures.OnFingerDragMove -= OnFingerDragMove;FingerGestures.OnFingerDragEnd -= OnFingerDragEnd; FingerGestures.OnFingerSwipe -= OnFingerSwipe;FingerGestures.OnFingerTap -= OnFingerTap;FingerGestures.OnFingerStationaryBegin -= OnFingerStationaryBegin;FingerGestures.OnFingerStationary -= OnFingerStationary;FingerGestures.OnFingerStationaryEnd -= OnFingerStationaryEnd;FingerGestures.OnFingerLongPress -= OnFingerLongPress;}//按下時調用void OnFingerDown( int fingerIndex, Vector2 fingerPos ){//int fingerIndex 是手指的ID 第一按下的手指就是 0 第二個按下的手指就是1。。。一次類推。//Vector2 fingerPos 手指按下屏幕中的2D坐標//將2D坐標轉換成3D坐標transform.position = GetWorldPos( fingerPos );Debug.Log(" OnFingerDown =" +fingerPos); }//抬起時調用void OnFingerUp( int fingerIndex, Vector2 fingerPos, float timeHeldDown ){Debug.Log(" OnFingerUp =" +fingerPos); }//開始滑動void OnFingerDragBegin( int fingerIndex, Vector2 fingerPos, Vector2 startPos ){Debug.Log("OnFingerDragBegin fingerIndex =" + fingerIndex + " fingerPos ="+fingerPos +"startPos =" +startPos); }//滑動結束void OnFingerDragEnd( int fingerIndex, Vector2 fingerPos ){Debug.Log("OnFingerDragEnd fingerIndex =" + fingerIndex + " fingerPos ="+fingerPos); }//滑動中void OnFingerDragMove( int fingerIndex, Vector2 fingerPos, Vector2 delta ){transform.position = GetWorldPos( fingerPos );Debug.Log(" OnFingerDragMove =" +fingerPos); }//上下左右四方方向滑動手勢操作void OnFingerSwipe( int fingerIndex, Vector2 startPos, FingerGestures.SwipeDirection direction, float velocity ){//結果是 Up Down Left Right 四個方向Debug.Log("OnFingerSwipe " + direction + " with finger " + fingerIndex);}//連續按下事件, tapCount就是當前連續按下幾次void OnFingerTap( int fingerIndex, Vector2 fingerPos, int tapCount ){Debug.Log("OnFingerTap " + tapCount + " times with finger " + fingerIndex);}//按下事件開始后調用,包括 開始 結束 持續中狀態只到下次事件開始!void OnFingerStationaryBegin( int fingerIndex, Vector2 fingerPos ){Debug.Log("OnFingerStationaryBegin " + fingerPos + " times with finger " + fingerIndex);}void OnFingerStationary( int fingerIndex, Vector2 fingerPos, float elapsedTime ){Debug.Log("OnFingerStationary " + fingerPos + " times with finger " + fingerIndex);}void OnFingerStationaryEnd( int fingerIndex, Vector2 fingerPos, float elapsedTime ){Debug.Log("OnFingerStationaryEnd " + fingerPos + " times with finger " + fingerIndex);}//長按事件void OnFingerLongPress( int fingerIndex, Vector2 fingerPos ){Debug.Log("OnFingerLongPress " + fingerPos );}//把Unity屏幕坐標換算成3D坐標Vector3 GetWorldPos( Vector2 screenPos ){Camera mainCamera = Camera.main;return mainCamera.ScreenToWorldPoint( new Vector3( screenPos.x, screenPos.y, Mathf.Abs( transform.position.z - mainCamera.transform.position.z ) ) ); } }/*FingerGestures最大的好處就是結合unity3d進行多點觸控,手勢識別,編寫一次代碼 ,通過配置來進行多平臺發布 FingerGestures提供了3種不同的方法來檢測由用戶執行的拖動手勢。方法1:使用默認的手勢事件 每個手指的手勢事件:為每個單獨的手指,獨立的狀態 OnFingerTap 輕敲 OnFingerDoubleTap OnFingerSwipe 猛擊 OnFingerLongPress 長按 OnFingerDragBegin,OnFingerDragMove,OnFingerDragEnd 拖曳全局手勢事件:當一個手指觸摸屏幕上:OnTAPOnDoubleTapOnSwipeOnLongPressOnDragBegin,OnDragMove,OnDragEnd兩個手指觸摸屏幕時:OnPinchBegin,OnPinchMove,OnPinchEnd 捏,夾OnRotationBegin,OnRotationMove,OnRotationEnd 旋轉OnTwoFingerTapOnTwoFingerSwipeOnTwoFingerLongPressOnTwoFingerDragBegin,OnTwoFingerDragMove,OnTwoFingerDragEnd方法2:使用一個DragGestureRecognizer 一種識別器方法3:使用“工具箱”:工具箱是一種更高級方便的方式,設計的理念是開箱就用,包括了很多腳本,但是沒有涉及到核心源碼, 所以不用的話 可以把這個包直接刪掉,FingerGestures 的事件注冊是基于c#的,性能還是可以。*/

總結

以上是生活随笔為你收集整理的Unity手势插件FingerGestures的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。