A repository of scripts and configs for embedding a Unity app inside a native Swift project. This repo is a template for projects wanting to do this. Sample Xcode and Unity projects are included.
This repository uses Git Large File Storage (LFS). To install LFS, follow these instructions:
Clone the repo and run
git lfs pull in your clone directory, then build and run the sample Swift project. The sample app is a simple screen with a button to launch the Unity AR experience. When running in the simulator, the Unity scene displays text that indicates AR isn't supported. When running on device, the scene displays the Vuforia camera.
Aim the camera at the test image included in this repo to view the astronaut in AR! Tap on the astronaut to trigger an animation.
Setting up your own project
This repo serves as a template for how to configure both the Xcode and Unity projects for seamless integration of Unity into a native Swift app. If you're starting a new project from scratch, or want to integrate Unity into an existing Xcode project, follow these steps:
iOS/Sample/Configdirectory to your project.
iOS/Sample/Unitydirectory to your project.
If using Cocoapods, change the xcconfig name in the Debug and Release configs in the
Configdirectory. You can't use variables in the path, but the included Cocoapods config should be this format:
Set the Configuration for your Debug and Release targets to the appropiate config from the
Configdirectory. Your project settings should then look similar to this:
Add a new Run Script build phase with the contents of
Copy Unity Datascript (from the sample project) after
Copy Bundle Resourcesbuild phase.
If using Vuforia, disable Metal API validation in Scheme -> Options. If not using Vuforia, you can delete
- Add this line in your app delegate's
UnityViewController.shared.configure(with: application, options: launchOptions)
Add contents of
Unity/Assets/Scriptsto your project
Scene-Simulatorlabels to your scenes. The build script looks for these labels to determine which scenes to include for which target. To include a scene on both simulator and device, add both labels.
Make sure project is set to use .NET 4x equivalent in Project Settings.
If using Vuforia and on-device data sets (as opposed to a Cloud Target Database), add
ConfigureVuforiaDatasetLoaderto your AR scene.