unity手势插件《FingerGestures 》使用入门
来源:互联网 发布:51单片机控制机箱风扇 编辑:程序博客网 时间:2024/05/20 19:18
什么是FingerGestures?
FingerGestures是Unity上,非常热门的一款用于处理用户输入的插件
为什么要使用FingerGestures?
1:它统一了鼠标点击和用户触摸的输入模型。使得我们可以在UnityEditor里面就可以方便地进行触摸测试(而不必发布到机器上)
2:它提供了丰富的触摸、手势事件支持
3:使用符合KISS原则,不需要复杂的配置,即可实现功能
4:这个吊了:允许用户自定义手势触发图案(无尽之剑的手势触发技能,用它轻松实现)
相信你已经迫不及待开始这段传奇之旅了。下面通过一个简单Tap(点击)事件的例子:触摸屏幕上的物体,输出碰撞的物体名称和碰撞点;
OK,让我们开始了解这个神器
入门
1:导入FingerGestures的Unity安装包,默认位置在Plugins/FingerGestures/目录下
2:创建一个场景,将FingerGestures这个prefab拖进场景
3:创建一个空的GameObject(也可以用现有的),我们需要将触摸的脚本挂载到这个上面
4:点击该GameObject的属性窗口,在弹出的窗口选择FingerGestures,然后依次在如下两个选项下,找到Tap Recognizer 和Screen RayCaster
5:将你场景里面的Camera的Tag设置成MainCamera(推荐)
或者你需要告诉FingerGestures,那个Camera才是它需要的(不推荐,个人测试,遇到碰撞优先级错误的问题)
设置Tag法:
或者手动指定法:
找到第4步骤添加的Screen RayCaster组件,指定相机
6:编写测试代码
FingerGestures里面方法传递有两种方式
1:使用c# 代理方式(推荐,性能好)
2:类似Unity的SendMessage()广播方式(方便,性能略低)
第1种代理法:创建一个脚本,黏贴下面的代码,挂载到第三步骤创建的GameObject就好了
using UnityEngine;[RequireComponent(typeof(TapRecognizer))]public class InputHelper : MonoBehaviour{ // Use this for initialization void Start () { TapRecognizer tapRecognizer = GetComponent<TapRecognizer> (); tapRecognizer.OnGesture += Tap_Gesture; } void Tap_Gesture (TapGesture e) { GameObject hittedObject = e.Selection; if (null != hittedObject) { Vector3 hitPos3d = e.Raycast.Hit3D.point; Debug.Log (hittedObject.name + " pos:" + hitPos3d); } else { } }}
第二种广播法:
1:设置Tap Recognizer,如下把我们第三部创建的GameObject拖放到MessageTarget上
2:代码:
去掉第一种代理法里Start()方法,就可以了
总结:
1:本文中推荐的步骤或者少配置、或者性能好,请使用的时候倾向于这些方式。
2:要碰撞的物体请设置一个Collider,在Component的Physics目录下。
3:添加的两个组件的作用:
Tap Recognizer:触摸事件识别类
Screen RayCaster:物体被碰撞的时候,需要知道这道光线从哪里过来(和摄像头的方向一致)
- unity手势插件《FingerGestures 》使用入门
- unity手势插件《FingerGestures 》使用入门
- Unity手势插件FingerGestures
- Unity FingerGestures 手势插件教程
- Unity手势操作FingerGestures插件
- Unity手势插件FingerGestures使用遇到的问题
- Unity3D FingerGestures 手势插件使用
- FingerGestures手势插件的使用
- 【Unity插件】FingerGestures 插件使用
- unity中使用FingerGestures插件3.0
- 【Unity插件】FingerGestures导入使用教程
- Unity3D插件之FingerGestures:手势插件
- FingerGestures Unity手势操作(一)
- 【Unity】unity3d FingerGestures 单点 多点触摸 手势
- unityios开发--FingerGestures插件使用
- Unity中使用NGUI和FingerGestures插件点击UI穿透的问题
- Unity中使用NGUI和FingerGestures插件点击UI穿透的问题
- 【NGUI】Unity中使用NGUI和FingerGestures插件点击UI穿透的问题
- Oracle中rank() over, dense_rank(), row_number() 的区别
- openstack安装rabbitmq时查看rabbitmq插件出现failed to connect rabbitmq@controller
- Struts2中action三种方式
- 51nod--1085--背包问题
- 格式良好的XML文档( well formed)
- unity手势插件《FingerGestures 》使用入门
- Python与数据结构总结(一)
- 项目3 求集合并集
- [codefoces2017-2018 ACM-ICPC]刷题小练
- P3793礼物和糖果
- GitBook Editor不能pull新Book时的处理
- 知识点记录之Integer
- Converting FC layers to CONV layers
- LeetCode--word ladder(python)