zoukankan      html  css  js  c++  java
  • Unity判断手势在物品的滑动方向(上下左右)

     /*************
    ** 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;
            }
        }
    }
  • 相关阅读:
    Docker之4---Docker存储卷与容器卷详解
    Docker之3---java业务镜像制作
    Docker之2---Dockerfile详解
    devops持续集成
    云计算之4---Cockpit
    云计算之3---OpenStack
    云计算之2---KVM
    云计算之1---介绍
    自动化运维工具-Ansible之7-roles
    mycat读写分离
  • 原文地址:https://www.cnblogs.com/weiqiangwaideshijie/p/9287257.html
Copyright © 2011-2022 走看看