arkit unity_凯蒂猫! 如何使用ARKit和Unity制作增强现实应用程序。

arkit unity

by Francesco Pallotta

由Francesco Pallotta

凯蒂猫! 如何使用ARKit和Unity制作增强现实应用程序。 (Hello, Kitty! How to make an augmented reality app using ARKit and Unity.)

We’ve all heard of Augmented Reality (AR), but at this point there are few opportunities to see this technology in action. We know that AR allows us to see virtual elements fused with the real world around us. For example, with AR we can see a virtual sofa in our room. Apple now lets us see new items added to the real world using the cameras in our phones.

我们都听说过增强现实(AR),但是目前几乎没有机会看到该技术的实际应用。 我们知道,AR使我们能够看到虚拟元素与周围的现实世界融为一体。 例如,使用AR,我们可以看到我们房间里的虚拟沙发。 Apple现在允许我们使用手机中的相机查看添加到现实世界中的新物品。

Apple introduced ARKit, the framework for creating experiences in Augmented Reality, in iOS11. ARKit uses Visual Inertial Odometry (VIO) to map the surrounding environment. VIO blends the data provided by the camera sensor with Core Motion data. Core Motion data are collected through the accelerometer, gyroscope, pedometer, magnetometer, and barometer.

苹果在iOS11中引入了ARKit,这是用于在增强现实中创建体验的框架。 ARKit使用视觉惯性里程表(VIO)映射周围环境。 VIO将摄像机传感器提供的数据与Core Motion数据混合在一起。 Core Motion数据通过加速度计,陀螺仪,计步器,磁力计和气压计收集。

All these inputs allow the device to understand its movement within a room. With ARKit, the iPhone and iPad can analyze a scene and find the horizontal planes of a room. ARKit can locate tables and floors, and can trace and position objects at precise points.

所有这些输入使设备能够了解其在房间内的运动。 借助ARKit,iPhone和iPad可以分析场景并找到房间的水平面。 ARKit可以定位桌子和地板,并可以在精确的点上跟踪和定位对象。

ARKit also uses the room sensor to measure ambient light and apply the correct amount of light to virtual objects. ARKit is compatible with Apple’s A9, A10, and A11 processors. To develop with ARKit you can use Metal, Scenekit, and third-party tools such as Unity and Unreal Engine.

ARKit还使用室内传感器来测量环境光并将正确数量的光施加到虚拟物体上。 ARKit与Apple的A9,A10和A11处理器兼容。 要使用ARKit进行开发,您可以使用Metal,Scenekit和第三方工具,例如Unity和Unreal Engine。

Let’s now see how to create an AR application using ARKit.


开发环境 (Development environment)

To get started we need:


  • The release version of Unity 2017.1.0 or later. ARKit is also compatible with the Experimental VR build used for macOS VR content creation and Unity 5.x versions of Unity 5.6.2 or later.

    Unity 2017.1.0或更高版本的发行版本。 ARKit还与用于macOS VR内容创建的实验VR版本以及Unity 5.6.2或更高版本的Unity 5.x版本兼容。

  • iOS 11 or later

    iOS 11或更高版本
  • XCode 9 beta or later, with iOS SDK that includes ARKit Framework

    XCode 9 beta或更高版本,带有包含ARKit Framework的iOS SDK
  • iOS that supports ARKit (iPhone 6S or later, iPad 2017 or later)

    支持ARKit的iOS(iPhone 6S或更高版本,iPad 2017或更高版本)

程序 (Procedure)

Start Unity. The project window will open.

启动Unity。 项目窗口将打开。

At this point, we have to create a new, empty project:


  1. In the window, click on New for a new project.

    在窗口中,单击“ 新建”以创建一个新项目。

  2. Write “ARKitty” in the Project name text box.

    项目名称文本框中输入“ ARKitty”。

  3. On the same window, press the Create project button.


We have created our AR project!


Open the Asset Store by clicking on that tab.


Next, search within the store: write “ARKit” in the text box and click on the magnifying glass icon.

接下来,在商店中搜索:在文本框中输入“ ARKit”,然后单击放大镜图标。

Scroll through the Asset Store window until you find “Unity ARKit Plugin.” This is the plugin that integrates ARKit within Unity.

滚动浏览Asset Store窗口,直到找到“ Unity ARKit插件”。 这是将ARKit集成到Unity中的插件。

Click on Unity ARKit Plugin and scroll down to the import button and press it. Press import again to import the same project, and import once more on the plugin element window.

单击Unity ARKit插件,然后向下滚动到导入按钮,然后按一下。 再次按导入,以导入相同的项目,然后在插件元素窗口中再次导入。

Now go back to the Asset store, press the Home symbol, and write “Cute Kitten” in the search text field. Press the search symbol and import the Cute Kitten model as you just did with the ARKit plug-in.

现在返回到资产商店,按Home符号,然后在搜索文本字段中输入“ Cute Kitten”。 按下搜索符号,然后像使用ARKit插件一样导入Cute Kitten模型。

Scroll with the cursor to the import button and press it. Press import again on the plug-in element window.

用光标滚动到导入按钮,然后按它。 在插件元素窗口上再次按导入。

Search the “UnityARKitScene” scene in the UnityARKitScene folder under “Asset/Examples.”

在“资产/示例”下的UnityARKitScene文件夹中搜索“ UnityARKitScene”场景。

Drag the scene “UnityARKitScene” under Hierarchy.

将场景“ UnityARKitScene”拖到“层次结构”下。

Go to the assets and find Kitten.


Go under Model and drag “kitten” under “Hierarchy-> HitCubeParent”.

转到“ 模型 ”下,并将“小猫”拖到“层次结构-> HitCubeParent”下。

Remove HitCube and RandomCube from the scene by right-clicking and then hitting Delete. Select GeneratePlanes, ARKitControl, and click on the inspector and uncheck Tag.

右键单击然后单击Delete从场景中删除HitCube和RandomCube。 选择GeneratePlanes,ARKitControl,然后单击检查器并取消选中Tag

Go to Main Camera under CameraParent and, in Inspector, set Near to 0.01.

转到CameraParent下的Main Camera ,然后在Inspector中将Near设置为0.01。

Click the Scene tab. Click on the kitten in Hierarchy to select it. Now we see our kitten in the Scene view in three-dimensional space. Go to the asset “UnityARKitPlugin-> Plugins-> Helpers” and take the UnityARHitTestExample.cs script. Drag the script into the kitten inspector.

单击“ 场景”选项卡。 单击“ 层次结构 ”中的小猫以将其选中。 现在,我们在三维空间的“场景”视图中看到了小猫。 转到资产“ UnityARKitPlugin->插件-> Helpers”,并使用UnityARHitTestExample.cs脚本。 将脚本拖到小猫检查器中。

Drag the kitten in the Hit transform field of the “UnityARHitTestExample.cs” script.

将小猫拖到“ UnityARHitTestExample.cs”脚本的“ 命中”变换字段中。

Save the scene by selecting “File-> Save Scenes” and call it “ARKittyTest”.

通过选择“文件->保存场景”保存场景,并将其命名为“ ARKittyTest”。

Finished! It’s time to try the new application in Augmented Reality.

完蛋了! 现在是时候在增强现实中尝试新的应用程序了。

Go to the File menu and choose Build Settings. In the window that opens, under Platform, choose IOS.

转到“ 文件”菜单,然后选择“ 构建设置” 。 在打开的窗口的“ 平台”下,选择“ IOS”。

Press the Player Settings button and scroll down until you find Bundle Identifier. Here, write an identifier of the type: “com. <Your name> .arkittytest”.

按“ 播放器设置”按钮并向下滚动,直到找到“ 捆绑包标识符” 。 在这里,输入类型为“ com。 <您的名字> .arkittytest”。

Click the Build button in the Build Settings window and save the project to iOS as “ARKittyTest”.

单击“构建设置”窗口中的“构建”按钮,并将项目另存为“ ARKittyTest”到iOS。

At the end of the process, find the XCode project in the Finder named “Unity-iPhone.xcodeproj”. Double-click to open the project with XCode. In XCode, click Unity-iPhone and go to General. In the identity field, write the same Bundle Identifier inserted in Unity’s Build Settings.

在该过程的最后,在Finder中找到名为“ Unity-iPhone.xcodeproj”的XCode项目。 双击以使用XCode打开项目。 在XCode中,单击Unity-iPhone,然后转到常规 。 在标识字段中,编写插入Unity的“构建设置”中的同一捆绑包标识符。

Under Signing in the Team pull-down menu, select the registered team name.

在“ 登录 团队”下拉菜单中,选择注册的团队名称。

Select the device (iPhone / iPad) before connecting to the Mac as the target device.

在连接到Mac作为目标设备之前,先选择设备(iPhone / iPad)。

Press the XCode arrow key to “Build and Run the Current Scheme.”


In the end, when we frame a surface near us and tap on the phone screen, we can see our Kitten live in front of us.


Mission accomplished! The following video shows the complete procedure.

任务完成! 以下视频显示了完整的过程。

Francesco Pallotta is a senior software engineer expert in software design and development. He works in the field of Space and Defense and deals with application development techniques for virtual reality and augmented reality.

Francesco Pallotta是软件设计和开发方面的高级软件工程师专家。 他从事太空和国防领域的工作,并负责虚拟现实和增强现实的应用程序开发技术

Do you want to read more about Virtual Reality, Augmented Reality and Mixed Reality? Follow me on Medium and Twitter.

您是否想了解有关虚拟现实,增强现实和混合现实的更多信息? 在MediumTwitter上 关注我

Did you enjoy this post? Recommend it, by give it some claps. Thanks!

你喜欢这个帖子吗? 推荐一下 ,鼓掌吧。 谢谢!


arkit unity

评论将由博主筛选后显示,对所有人可见 | 还能输入1000个字符
©️2020 CSDN 皮肤主题: 编程工作室 设计师:CSDN官方博客 返回首页