zoukankan      html  css  js  c++  java
  • (二)简单触控

    此部分简单触控是指在屏幕上简单的进行点击,拖动,鼠标(手指)按下与松开等功能,此部分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可以获得滑动的方向等

  • 相关阅读:
    UTF8转换为GB编码gb2312转换为utf-8
    localtime 和 localtime_r
    无损音频介绍
    bgr to rgb
    Farseer.Net
    为大家分享一个 Ajax Loading —— spin.js(转)
    HTML5-Ajax文件上传(转)
    Firefox火狐Flash插件卡死问题完美解决方法(转载)
    50 个最棒的 jQuery 日历插件,很齐全了!(转)
    linq to xml学习
  • 原文地址:https://www.cnblogs.com/llstart-new0201/p/8932241.html
Copyright © 2011-2022 走看看