原创内容,转载请注明原文网址:http://homeqin.cn/a/wenzhangboke/jishutiandi/youxikaifa/2018/1103/158.html
				Unity判断手势的滑动方向,单点触摸和多点触摸,并获取刚触摸以及触摸结束事的坐标
			
				Unity判断手势触摸的类型 ,判断手势的滑动方向,并获取刚触摸以及触摸结束事的坐标
			
				本章咱们常州手机App游戏开发培训幻天网络一起来看下unity对有触摸手势做出的响应
			
				单点触摸
			
				Input.touchCount==1
			
				移动触摸
			
				Input.GetTouch(0).phase==TouchPhase.Moved
			
				多点触摸
			
				Input.touchCount > 1
			
				判断两只手指至少有一只为移动触摸
			
				Input.GetTouch(0).phase == TouchPhase.Moved || Input.GetTouch(1).phase == TouchPhase.Moved
			
				/**
			
				     * 判断是否为单点触摸
			
				     **/
			
				    public static bool singleTouch()
			
				    {
			
				        if(Input.touchCount==1)
			
				            return true;
			
				        return false;
			
				    }
			
				    /**
			
				     * 判断单点触摸条件下  是否为移动触摸
			
				     **/
			
				    public static bool moveSingleTouch()
			
				    {
			
				        if (Input.GetTouch(0).phase==TouchPhase.Moved)
			
				            return true;
			
				        return false;
			
				    }
			
				    /**
			
				     *判断是否为多点触摸 
			
				     **/
			
				    public static bool multipointTouch()
			
				    {
			
				        if (Input.touchCount > 1)
			
				            return true;
			
				        return false;
			
				    }
			
				    /**
			
				     *判断两只手指至少有一只为移动触摸
			
				     **/
			
				    public static bool moveMultiTouch()
			
				    {
			
				        if (Input.GetTouch(0).phase == TouchPhase.Moved || Input.GetTouch(1).phase == TouchPhase.Moved)
			
				            return true;
			
				        return false;
			
				}
			
				/**
			
				     * 
			
				     * 新建一个公共方法用于判断手指的移动方向 
			
				     * 假如是往左或者往上 则模型往各个轴的正方向位置移动 函数返回1
			
				     * 加入是往右或者往下 则模型往各个轴的负方向位置移动 函数返回-1
			
				     * 
			
				     * **/
			
				    int judueFinger(){
			
				        if (Input.GetTouch(0).phase == TouchPhase.Began && startPosFlag == true)
			
				        {
			
				            //Debug.Log("======开始触摸=====");
			
				            startFingerPos = Input.GetTouch(0).position;
			
				            startPosFlag = false;
			
				        }
			
				        if (Input.GetTouch(0).phase == TouchPhase.Ended)
			
				        {
			
				            //Debug.Log("======释放触摸=====");
			
				            startPosFlag = true;
			
				        }
			
				        nowFingerPos = Input.GetTouch(0).position;
			
				        xMoveDistance = Mathf.Abs(nowFingerPos.x - startFingerPos.x);
			
				        yMoveDistance = Mathf.Abs(nowFingerPos.y - startFingerPos.y);
			
				        if (xMoveDistance>yMoveDistance)
			
				        {
			
				            if(nowFingerPos.x-startFingerPos.x>0){
			
				                //Debug.Log("=======沿着X轴负方向移动=====");
			
				                backValue = -1;         //沿着X轴负方向移动
			
				            }
			
				            else
			
				            {
			
				                //Debug.Log("=======沿着X轴正方向移动=====");
			
				                backValue = 1;          //沿着X轴正方向移动
			
				            }
			
				        }
			
				        else
			
				        {
			
				            if (nowFingerPos.y - startFingerPos.y>0)
			
				            {
			
				                //Debug.Log("=======沿着Y轴正方向移动=====");
			
				                backValue = 1;         //沿着Y轴正方向移动
			
				            }else{
			
				                //Debug.Log("=======沿着Y轴负方向移动=====");
			
				                backValue = -1;         //沿着Y轴负方向移动
			
				            }
			
				        }
			
				        return backValue;
			
				    }
			上篇:上一篇:滑动屏幕旋转模型功能实现
下篇:下一篇:Unity3D研究院之DontDestroyOnLoad的坑




