Unity + SenseAR Tutorial: emission love with gestures [Source]

Abstract: Unity + SenseAR2.3 development of AR applications, based on gesture recognition, launch your love ~

Torrent school, so you were quick steps. Hello, I'm your technical Pathfinder Zheng Hongzhi, you can call me wisdom.

Today is not the beginning of a long-winded, a "famous" given to everyone, and then we write the code a slight.

"Although today is Valentine's Day, but how could bring more dopamine than learning it?" - Dan deep Gou

final effect

Use the latest SenseAR this tutorial, gesture recognition can be achieved in a very short period of time.

Let this tutorial is to identify the pistol, than the heart and love your gestures, and then presents Heart of particle effects on screen.

The net effect .gif

Establish engineering

Note that you must use the version of Unity 2018.4, 2018.4 China is recommended to use an enhanced version of the latest version.
Path must not have Chinese , or packaging issues that may arise.

Create Project .gif

SenseAR plug-in installation

Search SenseAR XR plugin in Packamager in, I would use the latest version of the 1.1.0-preview.1version.

Installation sensear.gif

Import sample project

SenseAR was a new thing, no contact with before, so the best place to start is to look at an example to see what I can do.
How to import the sample project do?

1, found in the Packages Project window SenseAR XR Plugindirectory
2, select the directory in the right menu Show in Explorer
3, open the directory into the [email protected]\Samples~directory
4, the directory Examplefolder into the window of the Unity of Project Assets folder.

See the following specific processes:

Import example.gif

View Sample

After you import it, you will find that there are a lot of scenes, the scene is this gesture GestureDetect.

哇,还有那么多其他场景都是什么用呢?大智这几天会录制一个SenseAR全功能解析教程,记得关注哦(公众号:洪流学堂 b站:大智_Unity技术探路者

这个场景是没办法在电脑上运行的,只能发布到Android手机上运行。

发布手势示例

发布有以下几步:
1、确保安装好了Android发布的环境(JDK目前Unity已经内置了,Android SDK需要自行下载,可以使用Android Studio管理Android SDK),以及Unity的Android Support(推荐在Unity Hub中安装)。

android support.gif

2、在Unity的Build Settings中将平台切换为Android。

Switch to the android.gif

3、配置工程的Player Settings。

  • Package Name修改一下,别是默认的那个就行,我这设置为com.Company.ShootLove
  • Mininum API Level设置为Android 7.0 API level 24

4、 在手机上安装SenseAR2.3,下载地址是http://openar.sensetime.com/sdks
可能需要先卸载旧版本:小米预装版本SenseAR在应用设置里面名称为ARServer,OPPO预装版本SenseAR的名字为ARUnit

5、将手机开启开发者模式,USB连接到电脑上

6、记得打开GestureDetect场景,点击Unity菜单栏File > Build and Run,选择一个存放apk的路径。

体验手势App

如果打开黑屏检查下是否安装了SenseAR2.3,下载地址是http://openar.sensetime.com/sdks

最开始要同意使用摄像头的权限。

Examples .gif

SenseAR支持的手势有以下14种:

Source: http: //openar.sensetime.com/docs

开发

好,到这呢,我们已经体验了一把SenseAR强大的手势识别的功能了,那如何用手势发射爱心呢?

我们决定用三个手势发射爱心:分别是gun,finger_heart(比心),iloveu三个。

好,回到Unity工程里面。看一下AR Camera上的ARStandGuesturePainter中的代码,所有手势相关的代码都是在这里面的。

现在我们的思路就是判断出gun,finger_heart(比心),iloveu三个手势之后在界面显示爱心的特效。

1 做一个心的粒子效果

在AR Camera物体下创建一个粒子效果,这样粒子效果一会能显示在咱们的镜头中。粒子效果是可以在Scene和Game中预览的,最终效果在真机上也一致。

粒子效果的贴图用的是下面的这个白色的小心心(你可以直接下载使用),**为啥要用白色的呢?**因为这样可以在粒子系统里调它的颜色,五颜六色,随心所欲。如果你直接用个红色的心心,那就没办法叠加出所有的颜色了。

Map particle effects, the picture is white, oh, oh no not, right Download

下面就是你的舞台了,将这个粒子效果调到你满意为止。

大智审美缺陷党,调的效果如下:

Particle .gif

2 改造脚本

首先在ARStandGuesturePainter脚本中添加一个public的成员变量,用于关联爱心的粒子特效。

public GameObject HeartParticles;

然后在SetGuestureInfo方法的最后添加下面几行:

if (guestureInfo.HandGestureType == ArHandGestureType.GUN ||
            guestureInfo.HandGestureType == ArHandGestureType.I_LOVE_YOU ||
            guestureInfo.HandGestureType == ArHandGestureType.FINGER_HEART)
        {
            HeartParticles.SetActive(true);
        }
        else
        {
            HeartParticles.SetActive(false);
        }

然后在Inspector上将粒子效果的物体赋上去,就OK啦。

3 发布真机

The net effect .gif

更多探索

后面呢,大智还想做的更高级一些,可以根据指头的方向从指尖发射。大概思路如下,你可以和大智一起探索哦。

1、在ARStandGuesturePainter脚本的m_Points成员变量中获取到20个手指关节的位置。20个顶点与手指的位置关系如下图。

2、根据位置计算出来手指的方向,在对应方向上播放粒子效果。

本教程源码及后续更新

As the source subsequent updates, do not pass directly packaged here.
The project's source code can be continually updated torrent School public reply numbers 爱心get.

Wisdom these days will record a SenseAR full-function analysis tutorial , remember to focus on oh (public number: torrent school b station: Dazhi _Unity technology Pathfinder )


Well, today ramble here, and I wish the lovers get married ♥.
Did not make it clear where comments are welcome.

I am wisdom, your Pathfinder technology, see you next time!

Do not go! Thumbs up , collection oh!

Well, you can go.

Published 141 original articles · won praise 75 · views 290 000 +

Guess you like

Origin blog.csdn.net/zhenghongzhi6/article/details/104316307