(二)简单触控
此部分简单触控是指在屏幕上简单的进行点击,拖动,鼠标(手指)按下与松开等功能,此部分unity EventTrigger均可以实现,下边说一下Easy Touch实现
1)事件方法实现
void Start () { EasyTouch.On_TouchStart += OnBeginTouch; EasyTouch.On_SwipeEnd += OnEndTouch; EasyTouch.On_Swipe += OnSwipe; EasyTouch.On_TouchDown += OnTouchDown; } private void OnDisable() { EasyTouch.On_TouchStart -= OnBeginTouch; EasyTouch.On_SwipeEnd -= OnEndTouch; EasyTouch.On_Swipe -= OnSwipe; EasyTouch.On_TouchDown -= OnTouchDown; } void OnDoubleTap() { Debug.Log("Double Tap"); } void OnTouchDown(Gesture gesture) { Debug.Log("Touch Down"); } void OnBeginTouch(Gesture gesture) { Debug.Log("Touch Begin:"+gesture.startPosition); } void OnEndTouch(Gesture gesture) { Debug.Log("End Touch:" + gesture.position); } void OnSwipe(Gesture gesture) { Debug.Log("Swipe:" + gesture.position); }
通过注册相关时间可以拖动,滑动滑动结束等诸多功能
2)通过当前Gesture实例进行实现
void Update () { TouchEventControl(); } void TouchEventControl() { Gesture currentGesture = EasyTouch.current; if (currentGesture == null) return; if(currentGesture.type==EasyTouch.EvtType.On_DoubleTap) { OnDoubleTap(); } if (currentGesture.type == EasyTouch.EvtType.On_TouchDown) { OnTouchDown(currentGesture); } }
还可以通过currentGesture获得相关特征,如通过 currentGesture.swipe可以获得滑动的方向等