码迷,mamicode.com
首页 > 其他好文 > 详细

判断手势在物品的滑动方向(上下左右)

时间:2018-07-10 11:31:15      阅读:216      评论:0      收藏:0      [点我收藏+]

标签:name   any   base   position   ems   nts   listener   return   1.0   

 /*************
** Company: DX
**SrtiptName:DragItem
** Auth:    CW
** Des:    文本描述
** Ver.:     V1.0.0
*************/

using UnityEngine;
using System.Collections;
using UnityEngine.EventSystems;
using Kernal;

namespace Global

{
    public class DragItem : MonoBehaviour
    {
        /// <summary>
        /// 开始触摸的手指的位置
        /// </summary>
        private Vector3 _startTouchPos;
        private PointerEventData _pointerEventData;
        /// <summary>
        /// 拖拽的方向
        /// </summary>
        private E_DragDir _dragDir;
        void Start()
        {
            EventTriggerListener.Get(gameObject).OnMyBeginDrag += OnBeginDrag;
            EventTriggerListener.Get(gameObject).OnMyDrag += OnDrag;
            EventTriggerListener.Get(gameObject).OnMyEndDrag += OnEndDrag;

        }


        private void OnEndDrag(GameObject go, BaseEventData baseEventData)
        {
            _dragDir = E_DragDir.None;
        }
        private E_ClickPosType CurretClickType;
        private void OnDrag(GameObject go, BaseEventData baseEventData)
        {
            if (_pointerEventData.position.x > _startTouchPos.x)
            {
                Log.Debug("往右边滑动");
                _dragDir = E_DragDir.Right;

            }
            else if (_pointerEventData.position.x < _startTouchPos.x)
            {
                Log.Debug("往左边滑动");
                _dragDir = E_DragDir.Left;
              
            }
            else if (_pointerEventData.position.y < _startTouchPos.y)
            {
                 Log.Debug("往下面滑动");
                _dragDir = E_DragDir.Down;
            }
            else if (_pointerEventData.position.y > _startTouchPos.y)
            {
                Log.Debug("往上面滑动");
                _dragDir = E_DragDir.Up;
                
            }
            _startTouchPos = _pointerEventData.position;

        }

        private void OnBeginDrag(GameObject go, BaseEventData baseEventData)
        {

             _pointerEventData = baseEventData as PointerEventData;
            _startTouchPos = _pointerEventData.position;
        }

        /// <summary>
        /// 得到滑动的方向
        /// </summary>
        /// <returns></returns>
        public E_DragDir GetDragDir()
        {
            return _dragDir;
        }
    }
}

 

判断手势在物品的滑动方向(上下左右)

标签:name   any   base   position   ems   nts   listener   return   1.0   

原文地址:https://www.cnblogs.com/weiqiangwaideshijie/p/9287257.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!