Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Integrating Unity in Swift project

Tags:

ios

swift

unity3d

Well, I have seen and tried most of tutorials referenced from similar questions "How to integrate Unity iOS code into Swift project". But all my attempts were failed with linker error "No such symbol for architecture arm_64" or "No such symbol for architecture x86_64". I have tried different build options in Unity side, no success. Common minus of all of that tutorials / articles is: all of them outdated, latest version of Unity I have found article is 2018.2.2f1, my version of Unity is 2018.2.20f1. So, anyone have idea how integrate Unity 2018.2.20+ iOS builded code into Swift 4.2 (XCode 10) project? Any help will be great appreciated.

like image 222
zzheads Avatar asked Dec 21 '18 15:12

zzheads


1 Answers

Here is how I have integrated unity in my swift project.

  1. Create new Xcode project (using swift)

  2. (create bridging header step) Create new class File -> New -> Cocoa touch class and select language Objective C it will ask for create bridging header choose create

  3. Goto https://github.com/jiulongw/swift-unity and download zip file

  4. Open downloaded file and unzip it. Go to Xcode folder -> DemoApp-> You will find Unity Folder copy paste to your project (if you drag and drop it make sure you check the check box for copy at destination)

  5. open your new Xcode project and auto generated unity project side by side so you can copy paste it easily

  6. copy Classes Folder from unity Xcode project to your Xcode project to the unity Folder of step 4

  7. copy Library Folder from unity Xcode project to your Xcode project to the unity Folder of step 4

  8. copy Data Folder from unity Xcode project to your Xcode project to the unity Folder of step 4

  9. Important Goto Xcode project tap on name of project on left side there will be two options Project and target. Select project on centre main window you can see Configuration Expand it and against the name of your project choose Unity from drop drown

  10. Goto Classes Folder that you have copied in step And either delete main.mm file or comment everything

  11. goto folder you have downloaded in step3 Copy all code of AppDelegate.swift to your AppDelegate.swift file

  12. In your Xcode project search for YourProjectFileName-Bridging-Header and copy paste

    #ifndef BRIDGING_HEADER #define BRIDGING_HEADER

    #import <UIKit/UIKit.h> #import "UnityUtils.h" #import "UnityAppController.h" #import "UnityInterface.h"

    #endif /* BRIDGING_HEADER */

  13. Copy paste LaunchScreen-iPad.xib and LaunchScreen-iPhone.xib to your project and delete LaunchScreen.storyboard

  14. Compile it :] it should compile successfully (not in my case I got error that DeviceSettings.mm there is return statement missing so I just added return deviceUnknown; before the })

  15. You can see step3 downloaded view controller.swift file for see how to show unity view in your screen

Notes: After integrate unity you are not able to run in simulator so you have to run in real device. it is better to have unity and xcode in same machine. sometime all the framework only get ref of folder so in different machine you may face the issue

at last your project should look like

Screenshot

like image 63
Prashant Tukadiya Avatar answered Oct 20 '22 23:10

Prashant Tukadiya