Unity触屏操作 (主要是解决多点触 屏问题)
来源:互联网 发布:插件式软件开发 编辑:程序博客网 时间:2024/05/21 17:09
1)、声明允许多点触屏
2)判断手指触摸到屏幕的位置
3)判断手指触摸到屏幕的数目
input.touchCount =0
return
input.touchCount =1
我们让其来做点事: (移动摄像机左右移动)
1)用phase来判断触碰的状态
Began:表示手指已触摸屏幕
Move:手指在屏幕上移动
End:手指从屏幕上移开。这是一个触摸的最后状态
Canceled:系统取消跟踪触摸,如用户把屏幕放到 他脸上或超过五个接触同时发生。这是一个触摸 的最后状态。
Stationary:手指触摸屏幕,但并没有移动。
2)当判断Input.touches[0].phase ==TouchesPhase.Began
用一个Verctor2记录下Input.touches[0].position
3)当判断Input.touches[0].phase == TouchesPhase.Move
此时就可用来移动主摄像机了 Camin.main.tranform.translate(new Verctor3(Input.touches[0].position.x*Time.deltaTime, Input.touches[0].position.y*Time.deltaTime,0))
1、定义变量来储存两个touchCount的开始位置 与所移动的距离
Vector2 finger1 = new Vector2()
Vector2 finger2 = new Vector2()
Vector2 mov1 = new Vector2()
Vector2 mov2 = new Vector2()
2、想像一个我们划动屏幕的动作 我们的两个手指放下后一般会一个 手指定住,一个手指移动来放大, 当然也会有两个手指都移动,但我 们只取这种状态来作判断即可
在一个for循环里定义一个touch类型变量来 接收Input.touches[i]
1、对touch.phase作判断 如果touch.phase ==touches.Ended 则break
2对touch.phase作判断 如果touch.phase ==touches.Move
0、定议一个floa mov 来接收最终经过判断所移动的值
mov = move.x+move.y
1、for循环作一个判断i==1时对finger1、mov1、赋值
2、else里对finger2、mov2赋值,并对比较finger1与finger2的X、Y
2)判断手指触摸到屏幕的位置
3)判断手指触摸到屏幕的数目
input.touchCount =0
return
input.touchCount =1
我们让其来做点事: (移动摄像机左右移动)
1)用phase来判断触碰的状态
Began:表示手指已触摸屏幕
Move:手指在屏幕上移动
End:手指从屏幕上移开。这是一个触摸的最后状态
Canceled:系统取消跟踪触摸,如用户把屏幕放到 他脸上或超过五个接触同时发生。这是一个触摸 的最后状态。
Stationary:手指触摸屏幕,但并没有移动。
2)当判断Input.touches[0].phase ==TouchesPhase.Began
用一个Verctor2记录下Input.touches[0].position
3)当判断Input.touches[0].phase == TouchesPhase.Move
此时就可用来移动主摄像机了 Camin.main.tranform.translate(new Verctor3(Input.touches[0].position.x*Time.deltaTime, Input.touches[0].position.y*Time.deltaTime,0))
input.touchCount>1
1、定义变量来储存两个touchCount的开始位置 与所移动的距离
Vector2 finger1 = new Vector2()
Vector2 finger2 = new Vector2()
Vector2 mov1 = new Vector2()
Vector2 mov2 = new Vector2()
2、想像一个我们划动屏幕的动作 我们的两个手指放下后一般会一个 手指定住,一个手指移动来放大, 当然也会有两个手指都移动,但我 们只取这种状态来作判断即可
在一个for循环里定义一个touch类型变量来 接收Input.touches[i]
1、对touch.phase作判断 如果touch.phase ==touches.Ended 则break
2对touch.phase作判断 如果touch.phase ==touches.Move
0、定议一个floa mov 来接收最终经过判断所移动的值
mov = move.x+move.y
1、for循环作一个判断i==1时对finger1、mov1、赋值
2、else里对finger2、mov2赋值,并对比较finger1与finger2的X、Y
其实无论touchCount的数目是多少 我们都只取两个点来做判断即可
以下插入总体源码(这个与上面所讲有点不同,这个直接挂在与要旋转放大缩小的物体上)
using UnityEngine;using System.Collections;public class mobileChane : MonoBehaviour {// Use this for initialization private float mx; private float my; private float xSpeed =3; private float ySpeed =3; private Vector2 start; private Quaternion mRoation;void Start () { Input.multiTouchEnabled = true;}// Update is called once per framevoid Update () { MoblieInput();} void MoblieInput() { if(Input.touchCount ==0 ) { return; } if(Input.touchCount ==1) { if(Input.touches[0].phase ==TouchPhase.Began) { start = Input.touches[0].position; } if(Input.touches[0].phase ==TouchPhase.Moved) { mx += Input.touches[0].deltaPosition.x * xSpeed; my += Input.touches[0].deltaPosition.y * ySpeed; ; } mRoation = Quaternion.Euler(mx, my, 0); transform.rotation = mRoation; } else if(Input.touchCount>1) { Vector2 finger1 = new Vector2(); Vector2 finger2 = new Vector2(); Vector2 mov1 = new Vector2(); Vector2 mov2 = new Vector2(); // Vector2 mov = new Vector2(); for(int i = 0;i<2;i++) { Touch touch = Input.touches[i]; if(touch.phase == TouchPhase.Ended) { break; } if(touch.phase == TouchPhase.Moved) { float mov = 0; if(i==0) { finger1 = touch.position; mov1 = touch.deltaPosition; } else { finger2 = touch.position; finger2 = touch.deltaPosition; //开始做移动判断 if(finger1.x>finger2.x) { mov = mov1.x; } else { mov = mov2.x; } if(finger1.y >finger2.y) { mov += mov1.y; } else { mov += mov2.y; } } Camera.main.transform.Translate(0, 0, mov * Time.deltaTime);//主要通过控制主摄像的远近来放大缩小 } } } }}
0 0
- Unity触屏操作 (主要是解决多点触 屏问题)
- unity 多点触控
- unity多点触控
- unity多点触控
- QT多点触屏
- Tap Sense:不只是多点触屏而且是多种触屏
- 关于Unity3d的多点触屏输入问题
- Unity中的连调和多点触控
- unity 多点触控(放大,缩小)
- 解决多点透视问题
- unity3d 触屏多点触控(旋转与缩放)
- Unity性能优化(主要是内存的优化)
- android 电容屏多点触控协议
- 多点触屏浏览器的js开发
- Unity 3D实现多点触控源代码
- unity操作android触屏移动代码
- 关于cocos2dx多点触控的问题
- Cocos2dx 3.x多点触控问题
- 操作系统学习笔记二 操作系统结构
- PHP内核探索之变量(3)- hash table
- Maven学习四:使用mvn install创建自己的repository
- 一个人的旅行 解题报告
- Nginx配置文件详细说明
- Unity触屏操作 (主要是解决多点触 屏问题)
- String to Integer (atoi)
- Fermat vs. Pythagoras - UVa 106 勾股数
- 确保nginx安全的10个技巧
- Linux 运用debugfs调试方法
- AccessibilityService ClassNotFoundExcepiton
- Jacobian。。。
- nginx安全配置
- 【剑指Offer面试编程题】题目1386:旋转数组的最小数字--九度OJ