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:
https://help.github.com/articles/installing-git-large-file-storage/
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.
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:
-
Add the
iOS/Sample/Config
directory to your project. -
Add the
iOS/Sample/Unity
directory to your project. -
If using Cocoapods, change the xcconfig name in the Debug and Release configs in the
Config
directory. You can't use variables in the path, but the included Cocoapods config should be this format:Pods-$(TARGET_NAME).debug.xcconfig
Pods-$(TARGET_NAME).debug.xcconfig
-
Set the Configuration for your Debug and Release targets to the appropiate config from the
Config
directory. Your project settings should then look similar to this:
-
Add a new Run Script build phase with the contents of
Copy Unity Data
script from the sample project. If you're using Unity 2018.3 or later, also add a Run Script phase with the contents of theEmbed Unity Dylibs (Simulator Only)
script from the sample project. -
If using Vuforia, disable Metal API validation in Scheme -> Options. If not using Vuforia, you can delete
Vuforia.xcconfig
from theConfig
directory.
- Add this line in your app delegate's
didFinishLaunchingWithOptions:
:
UnityViewController.shared.configure(with: application, options: launchOptions)
-
Add contents of
Unity/Assets/Editor/Build
andUnity/Assets/Scripts
to your project -
Add either
Scene-Device
orScene-Simulator
labels 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
ConfigureVuforiaDatasetLoader
to your AR scene.