[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 ...
随机推荐
- CodeForces - 260B
A recently found Ancient Prophesy is believed to contain the exact Apocalypse date. The prophesy is ...
- 跟哥一起学Python(1) - python简介
01—写在前面 我做了十几年的程序猿,码过代码.带过项目.做过产品经理.做过软件架构师.因为我是做通信设备软件的,面向底层操作系统,所以我的工作主要以C语言为主.Python在我的工作中通常用来写一些 ...
- libevent(三)event_base
libevent能够处理三种事件: I/O.定时器.信号. event_base 统一管理所有事件. struct event_base { const struct eventop *evsel; ...
- Python基础03 id
id id(x)对应变量x所引用对象的内存地址.可以把id(x)看成变量x的身份标识. is 有时在编程中需要与变量的身份标识打交道,但不是通过 id 函数,而是 is 操作符. The operat ...
- Java——理解面向对象
1.程序设计的三种基本结构 顺序结构 顺序结构表示程序中的各操作是按照它们在源代码中的排列顺序依次执行的 选择结构 选择结构表示程序的处理需要根据某个特定的条件选择其中的一个分支执行.选择结构有单选择 ...
- (1).Mybatis的创建。配置。映射。dao映射
https://www.cnblogs.com/zxdup/ 一.Mybatis的创建 1.创建一个新的项目,建议选 Empty Project(空项目), 之后回跳转到Project Structu ...
- SpringCloud 踩坑之 注册中心绑定端口一直是8080
今天在启动注册中心服务时,突然端口一直是8080,找了好久一直没找到原因,先看看我有问题的配置 spring: application: name: eureka-server profiles: d ...
- ocaml 和coq 安装
安装opam 参考官网安装步骤即可,比如对于centos系统,以root用户执行如下指令 cd /etc/yum.repos.d/ wget http://download.opensuse.org/ ...
- 设计模式之GOF23享元模式
享元模式FlyWeight 场景:如果有很多个完全相同或者相似的对象,可以节省内存资源 核心: 享元模式以共享的方式高效地支持大量细粒对象的重用 享元对象做到共享的关键是区分了内部状态和外部状态: 内 ...
- 设计模式GOF23之工厂模式01
简单工厂模式和工厂方法模式 工厂模式核心:分工 简单工厂模式不符合OCP(Open-Closed Princinple)原则,扩展时需要更改原代码 工厂方法模式增加了类复杂度代码复杂度等,所以一般使用 ...