How to integrate Unity into a Swift 3 iOS project

匿名 (未验证) 提交于 2019-12-03 02:52:02

问题:

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?

回答1:

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



回答2:

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.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!