简体   繁体   English

如何将Unity集成到Swift 3 iOS项目中

[英]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. 我只是想知道在已经存在的Swift 3 iOS项目中实现Unity项目的最佳策略是什么。 So far I only discovered sample code in Objective-C. 到目前为止,我只在Objective-C中发现了示例代码。 Is there any popular framework or wrapper out there? 那里有流行的框架或包装吗?

in my opinion this guide is extremely helpful: 在我看来,本指南非常有用:

https://github.com/blitzagency/ios-unity5 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. 首先我有几个链接器错误,但我没有考虑到Unity项目配置只是为“真实设备”设置的。 When I tried to build the project on the simulator, I had more than 100 compiler errors. 当我尝试在模拟器上构建项目时,我遇到了100多个编译器错误。

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 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* AssetsLibrary,AudioToolbox,AVFoundation,CFNetwork,CoreGraphics,CoreLocation,CoreMedia,CoreMotion,CoreVideo,Foundation,iAd,libiconv.2.tdb,MediaPlayer,MediaToolBox,(这是缺少的)OpenAL,OpenGLES,QuartzCore,Security,SystemConfiguration,UIKit ,libiPhone-lib.a,libVuforia.a *,libVuforiaUnityPlayer.a *

*only if you use Vuforia in your scene *仅当您在场景中使用Vuforia时

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: 最后也是最重要的一步是遵循以下pull请求中列出的建议,然后它将完美地运行Swift 3:

https://github.com/blitzagency/ios-unity5/pull/42 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) 从其他分支合并当前的演进(如swift 3支持),更新为与Unity 5.5.2,Xcode 8.3.2和Swift 3.1一起使用,删除了一些类似于main.swift的样板,增加了暂停统一以充分利用减少的cpu cylces的可能性因此当统一未运行时(活动)电池消耗

If you use Cocoa Pods, it's better not to use the config file provided by this repo. 如果你使用Cocoa Pods,最好不要使用这个repo提供的配置文件。 I actually ended up manipulating all build settings manually, so there will be no conflicts with the pod config file. 实际上我最终手动操作所有构建设置,因此不会与pod配置文件冲突。

I hope I could help you a little bit. 我希望我能帮到你一点点。

Happy coding 快乐的编码

The tutorial mentioned in the accepted answer is a good step by step guide to integrate Unity to Swift project. 在接受的答案中提到的教程是将Unity集成到Swift项目的一个很好的分步指南。

However, there are couple of changes needed for Swift 4 and Unity 2017.1. 但是,Swift 4和Unity 2017.1需要进行一些更改。 Here is a demo project in case someone needs it. 这是一个演示项目 ,以防有人需要它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM