Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to integrate Unity into a Swift 3 iOS project

I was just wondering what might be the best strategy for implementing a Unity project into a already existing Swift 3 iOS project. So far I only discovered sample code in Objective-C. Is there any popular framework or wrapper out there?

like image 380
FBente Avatar asked Jul 13 '17 08:07

FBente


2 Answers

in my opinion this guide is extremely helpful:

https://github.com/blitzagency/ios-unity5

Please note that there are some pitfalls:

First I had several linker errors, but I did not take into account that the Unity project configuration was set up for "real devices" only. When I tried to build the project on the simulator, I had more than 100 compiler errors.

Then I tried to build it on my test device, but there were still some errors, until I noticed I had to add some of those necessary frameworks, which are listed right there:

https://github.com/blitzagency/ios-unity5/issues/36#issuecomment-303716827

AssetsLibrary, AudioToolbox, AVFoundation, CFNetwork, CoreGraphics, CoreLocation, CoreMedia, CoreMotion, CoreVideo, Foundation, iAd, libiconv.2.tdb, MediaPlayer, MediaToolBox, (this was the missing one) OpenAL, OpenGLES, QuartzCore, Security, SystemConfiguration, UIKit, libiPhone-lib.a, libVuforia.a*, libVuforiaUnityPlayer.a*

*only if you use Vuforia in your scene

The last and most important step is to follow the advices listed in the following pull request, then it will perfectly run with Swift 3:

https://github.com/blitzagency/ios-unity5/pull/42

merged current evolutions from other forks (like swift 3 support), updated to work with Unity 5.5.2, Xcode 8.3.2 and Swift 3.1, removed some boilerplate like main.swift added possibility to pause unity to take full advantage of reduced cpu cylces and therefore battery consumption, when unity is not running (active)

If you use Cocoa Pods, it's better not to use the config file provided by this repo. I actually ended up manipulating all build settings manually, so there will be no conflicts with the pod config file.

I hope I could help you a little bit.

Happy coding

like image 69
Objective D Avatar answered Nov 14 '22 22:11

Objective D


The tutorial mentioned in the accepted answer is a good step by step guide to integrate Unity to Swift project.

However, there are couple of changes needed for Swift 4 and Unity 2017.1. Here is a demo project in case someone needs it.

like image 45
jiulongw Avatar answered Nov 14 '22 23:11

jiulongw