[Unity2d系列教程] 005.Unity如何使用外部触控插件FingerGuesture
用过Unity的都知道自带的Input.touches并不支持鼠标输入,给我们的调试带来很大的不方便。那么我们会发现其实有很多触控方面的插件,如inputtouches,easy touch,fingerGesture等。
下面我主要讲解FingerGesture的使用,这个插件不是免费的,可以自行购买
1.导入插件

导入后的插件会在Assets/Plugins下面
2.拖动Assets/Plugins/FingerGestures/Prefabs/FingerGestures到你的Hierarchy中,如下图

3.创建空节点GestureObj,然后绑定脚本TestGesture.cs
using UnityEngine;
using System.Collections; public class testGestures : MonoBehaviour
{ // Use this for initialization
void Start () { } // Update is called once per frame
void Update () { } // 单击
void OnTap(TapGesture gesture)
{
if (gesture.Selection == tapObject)
{
Debug.Log("Tab!!!!!!!!!!!");
}
} // 双击
void OnDoubleTap(TapGesture gesture)
{
if (gesture.Selection == doubleTapObject)
{
Debug.Log("Double Tab!!!!!!!!!!!");
}
} void OnSwipe(SwipeGesture gesture)
{
// make sure we started the swipe gesture on our swipe object
// we use the object the swipe started on, instead of the current one
GameObject selection = gesture.StartSelection; if (selection == swipeObject)
{
Debug.Log("Swipe!!!!!!!");
}
} int dragFingerIndex = -;
void OnDrag(DragGesture gesture)
{
// 获取起始点
FingerGestures.Finger finger = gesture.Fingers[]; if (gesture.Phase == ContinuousGesturePhase.Started)
{
// dismiss this event if we're not interacting with our drag object
if (gesture.Selection != dragObject)
return; // remember which finger is dragging dragObject
dragFingerIndex = finger.Index;
}
else if (finger.Index == dragFingerIndex) // gesture in progress, make sure that this event comes from the finger that is dragging our dragObject
{
if (gesture.Phase == ContinuousGesturePhase.Updated)
{
// update the position by converting the current screen position of the finger to a world position on the Z = 0 plane
dragObject.transform.position = GetWorldPos(gesture.Position);
}
else
{
// reset our drag finger index
dragFingerIndex = -;
}
}
} // 长按
void OnLongPress(LongPressGesture gesture)
{
if (gesture.Selection == longPressObject)
{
Debug.Log("Long press!!!!!!");
}
}
// 定义变量,用来操作
public GameObject longPressObject;
public GameObject tapObject;
public GameObject doubleTapObject;
public GameObject swipeObject;
public GameObject dragObject; // 公共方法
public static Vector3 GetWorldPos(Vector2 screenPos)
{
Ray ray = Camera.main.ScreenPointToRay(screenPos); // we solve for intersection with z = 0 plane
float t = -ray.origin.z / ray.direction.z; return ray.GetPoint(t);
}
}
4.添加指定的触控对象

5.添加Component
6.添加Screen Raycaster

7.要为对象添加2D物理碰撞区域。不然的话点击没有效果。
[Unity2d系列教程] 005.Unity如何使用外部触控插件FingerGuesture的更多相关文章
- [Unity2d系列教程] 003.Unity如何调用android的方法
Unity开发的时候很多时候我们需要用到底层的一些功能,比如摄像,录音,震动等等,我们在Unity的层面是无法完成的.那么我们考虑到Unity是否可以直接调用到android方面的方法,替我们去完成我 ...
- [Unity2d系列教程] 006.Unity如何根据图片自动生成Animator
Unity制作2D产品的时候,我们在制作动画的时候,要不断的生成Animation,Animator等等资源,如果动画一多的话,就变得麻烦.由于Unity是支持插件开发的,我们可以添加一个Editor ...
- [Unity2d系列教程] 004.Unity如何调用ios的方法(SDK集成相关)
和上一篇类似,我们同样希望Unity能够直接调用IOS底层的代码,那么我们就需要研究怎么去实现它.下面让我来带大家看一个简单的例子 1.创建.h和.m文件如下 .h // // myTest.m // ...
- 黄聪:Microsoft Enterprise Library 5.0 系列教程(八) Unity Dependency Injection and Interception
原文:黄聪:Microsoft Enterprise Library 5.0 系列教程(八) Unity Dependency Injection and Interception 依赖注入容器Uni ...
- [Unity2d系列教程] 002.引用外部DLL - C
上一篇我们学习了Unity调用C#生成的外部DLL,但是有时候我们需要访问底层,不能不适用C生成的DLL.下面就让我们一起学习下,C如何生成. 1.创建一个C的控制台程序 2.点击确定->点击下 ...
- [Unity2d系列教程] 001.引用外部DLL - C#
众所周知,Unity可以支持多种语言开发, C#, JS, Boo三种方式的开发, 能够很方便的集成一些外部插件,以便调用现有的动态链接库.学过C#的都知道C#可以生成一个dll供给其他的程序调用.那 ...
- Enterprise Library 5.0 系列教程
1. Microsoft Enterprise Library 5.0 系列教程(一) Caching Application Block (初级) 2. Microsoft Enterprise L ...
- Fastify 系列教程一(路由和日志)
介绍 Fastify是一个高度专注于以最少开销和强大的插件架构,为开发人员提供最佳体验的Web框架. 它受到了 Hapi 和 Express 的启发,是目前最快的 Node 框架之一. Fastify ...
- Fastify 系列教程二 (中间件、钩子函数和装饰器)
Fastify 系列教程: Fastify 系列教程一 (路由和日志) Fastify 系列教程二 (中间件.钩子函数和装饰器) 中间件 Fastify 提供了与 Express 和 Restify ...
随机推荐
- python(文件操作)
一.文件操作 1.tell()方法返回文件的当前位置,即文件指针当前位置. UTF-8 编码格式,一个中文占3个字符 GBK 编码格式,一个中文占2个字符 #写入前文件内容如下 "" ...
- 不可错过的java面试博客之java集合篇
1. List List 是有序的 Collection.Java List 一共三个实现类: 分别是 ArrayList.Vector 和 LinkedList ArrayList ArrayLis ...
- turtle库应用实例3-叠加等边三角形绘制(一笔画)
叠加等边三角形绘制 ...
- java基础 之 从Class.forName()跟.class的区别看类的初始化
代码如下: public class Test { public static void main(String[] args) throws Exception { System.out.print ...
- java运行时跟编译时的区别,欢迎大家指正
个人博客地址:https://blog.csdn.net/qq_41907991 关于java运行时及编译时期的区别: 首先我们要了解编译以及运行的概念: 编译就是指,编译器帮你把源码翻译成机器能识别 ...
- Windows命令行:xcopy、move、rename
Windows命令行,xcopy复制粘贴,move剪切粘贴,rename/ren重命名.当简单事情重复做时,Windows命令行有用武之地了.批命令中,暂时用不到的行,用两个冒号注释掉. 不同路径下, ...
- burpsuite抓包无法识别POST参数问题
直接拿一道bugkuctf中的题目进行测试 这道题目就是用POST方法上传what=flag 我们利用burpsuite进制抓包 需要更改三个部分,这样就可以解决burpsuite无法识别POST参数 ...
- ASP.NET Core on K8S学习之旅(13)Ocelot API网关接入
本篇已加入<.NET Core on K8S学习实践系列文章索引>,可以点击查看更多容器化技术相关系列文章. 上一篇介绍了Ingress的基本概念和Nginx Ingress的基本配置和使 ...
- C#实现局域网聊天 通讯 Socket TCP 多人
程序分别为服务端与客户端,服务端创建套接字使用多线程侦听多客户端请求 代码需要引用System.Net:和System.Net.Socket:这两个类 分享源码demo:https://pan.bai ...
- throttle和debounce
遇到的问题 在开发过程中会遇到频率很高的事件或者连续的事件,如果不进行性能的优化,就可能会出现页面卡顿的现象,比如: 鼠标事件:mousemove(拖曳)/mouseover(划过)/mouseWhe ...