1

how i can insert my unity project(2017.2.0f3) into my viewcontroller in xcode 9.0?

In this guide, actually outdated, i got the following error :

clang: error: unknown argument: '-weak-LSystem'

And in Build Phases - Compile Sources, i got only 3 files (ViewController, main, AppDelegate), but in tutorial 90+ compiled sources

2
  • Create a custom .xconfig file which has all the flags and parameters from the unity project. Add the unity data folder to your project as a reference. Add the unity library files to your project. Change app delegate to forward all calls to unity and start unity then stop unity. Finally copy the UnityView to your controller and voila. I do this at my company and it works. Commented Nov 3, 2017 at 18:33
  • @Brandon maybe can you have a link for guide?:) Commented Nov 4, 2017 at 8:38

2 Answers 2

4

I added a guide video here: https://www.youtube.com/watch?v=2PW7_CfIwY0

I uploaded a 4K 10GB video file.. Hopefully, youtube finishes processing it by the time you see this answer.

Should be simple to follow (I hope.. I'm not good at videos).. but will take some time. If you are not building for Simulator, then remove: -DTARGET_IPHONE_SIMULATOR=1.. Modify other flags accordingly.

The Debug.xcconfig I used in the video is as follows:

UNITY_RUNTIME_VERSION = 2017.2.0f3;
UNITY_SCRIPTING_BACKEND = il2cpp;
UNITY_IOS_EXPORT_PATH = ../Unity;
GCC_PREFIX_HEADER = $(UNITY_IOS_EXPORT_PATH)/Classes/Prefix.pch;

OTHER_LDFLAGS = -weak-lSystem -weak_framework CoreMotion -weak_framework GameKit -weak_framework iAd -framework CoreGraphics -framework AVFoundation -framework CoreVideo -framework CoreMedia -framework CoreText -framework SystemConfiguration -framework CoreLocation -framework MediaPlayer -framework MediaToolbox -framework CFNetwork -framework AudioToolbox -framework OpenAL -framework Metal -framework QuartzCore -framework Metal -framework OpenGLES -framework UIKit -framework Foundation -liconv.2 -liPhone-lib;

HEADER_SEARCH_PATHS = "$(UNITY_IOS_EXPORT_PATH)/Classes" "$(UNITY_IOS_EXPORT_PATH)/Classes/Native" "$(UNITY_IOS_EXPORT_PATH)/Libraries/bdwgc/include" "$(UNITY_IOS_EXPORT_PATH)/Libraries/libil2cpp/include";
LIBRARY_SEARCH_PATHS = "$(UNITY_IOS_EXPORT_PATH)" "$(UNITY_IOS_EXPORT_PATH)/Libraries" "$(UNITY_IOS_EXPORT_PATH)/Libraries/libil2cpp/include";

ENABLE_BITCODE = YES;

OTHER_CFLAGS = -DINIT_SCRIPTING_BACKEND=1 -DTARGET_IPHONE_SIMULATOR=1 -DRUNTIME_IL2CPP=1 -fno-strict-overflow;
LD_GENERATE_MAP_FILE = YES;
CLANG_CXX_LANGUAGE_STANDARD = c++11;
CLANG_CXX_LIBRARY = libc++;
CLANG_ENABLE_MODULES = NO;
CLANG_WARN_BOOL_CONVERSION = NO;
CLANG_WARN_CONSTANT_CONVERSION = NO;
CLANG_WARN_INT_CONVERSION = NO;
CLANG_WARN_OBJC_ROOT_CLASS = YES;
CLANG_WARN_UNREACHABLE_CODE = NO;
CLANG_WARN__DUPLICATE_METHOD_MATCH = NO;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES;
CLANG_WARN_EMPTY_BODY = NO;
CLANG_WARN_ENUM_CONVERSION = NO;
GCC_C_LANGUAGE_STANDARD = c99;
GCC_ENABLE_OBJC_EXCEPTIONS = NO;
GCC_ENABLE_CPP_RTTI = NO;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_THUMB_SUPPORT = NO;
GCC_USE_INDIRECT_FUNCTION_CALLS = NO;
GCC_WARN_64_TO_32_BIT_CONVERSION = NO;
GCC_WARN_64_TO_32_BIT_CONVERSION[arch=*64] = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNDECLARED_SELECTOR = NO;
GCC_WARN_UNINITIALIZED_AUTOS = NO;
GCC_WARN_UNUSED_FUNCTION = NO;

The code for the Launcher.mm in the video is (so you don't have to type it all out):

@interface Launcher()
@property (nonatomic, assign) bool isRunning;
@end

@implementation Launcher

+ (int)initializeUnity:(int)argc argv:(char**)argv appDelegateName:(NSString *)appDelegateName {
    return UNITY_INIT(argc, argv, appDelegateName.UTF8String);
}

+ (UnityAppController *)controller {
    static UnityAppController *instance = nil;

    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        instance = [[UnityAppController alloc] init];
    });

    return instance;
}

- (void)start {
    if (!self.isRunning) {
        self.isRunning = true;
        [self applicationDidBecomeActive:UIApplication.sharedApplication];
    }
}

- (void)stop {
    if (self.isRunning) {
        [self applicationWillResignActive:UIApplication.sharedApplication];
        self.isRunning = false;
    }
}

- (UIView *)view {
    return UnityGetGLView();
}


- (NSUInteger)application:(UIApplication*)application supportedInterfaceOrientationsForWindow:(UIWindow*)window
{
    return [[Launcher controller] application:application supportedInterfaceOrientationsForWindow:window];
}

- (void)application:(UIApplication*)application didReceiveLocalNotification:(UILocalNotification*)notification
{
    [[Launcher controller] application:application didReceiveLocalNotification:notification];
}


- (void)application:(UIApplication*)application didReceiveRemoteNotification:(NSDictionary*)userInfo
{
    #if UNITY_USES_REMOTE_NOTIFICATIONS
    [[Launcher controller] application:application didReceiveRemoteNotification:userInfo];
    #endif
}

- (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken
{
    #if UNITY_USES_REMOTE_NOTIFICATIONS
    [[Launcher controller] application:application didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];
    #endif
}

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult result))handler
{
    #if UNITY_USES_REMOTE_NOTIFICATIONS
    [[[Launcher controller] application:application didReceiveRemoteNotification:userInfo] fetchCompletionHandler:handler];
    #endif
}

- (void)application:(UIApplication*)application didFailToRegisterForRemoteNotificationsWithError:(NSError*)error
{
    #if UNITY_USES_REMOTE_NOTIFICATIONS
    [[Launcher controller] application:application didFailToRegisterForRemoteNotificationsWithError:error];
    #endif
}

- (BOOL)application:(UIApplication*)application openURL:(NSURL*)url sourceApplication:(NSString*)sourceApplication annotation:(id)annotation
{
    return [[Launcher controller] application:application openURL:url sourceApplication:sourceApplication annotation:annotation];
}

- (BOOL)application:(UIApplication*)application willFinishLaunchingWithOptions:(NSDictionary*)launchOptions
{
    [[Launcher controller] application:application willFinishLaunchingWithOptions:launchOptions];
    return YES;
}

- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions
{
    [[Launcher controller] application:application didFinishLaunchingWithOptions:launchOptions];

    return YES;
}

- (void)applicationDidEnterBackground:(UIApplication*)application
{
    if (self.isRunning) {
        [[Launcher controller] applicationDidEnterBackground:application];
    }
}

- (void)applicationWillEnterForeground:(UIApplication*)application
{
    if (self.isRunning) {
        [[Launcher controller] applicationWillEnterForeground:application];
    }
}

- (void)applicationDidBecomeActive:(UIApplication*)application
{
    if (self.isRunning) {
        [[Launcher controller] applicationDidBecomeActive:application];
    }
}

- (void)applicationWillResignActive:(UIApplication*)application
{
    if (self.isRunning) {
        [[Launcher controller] applicationWillResignActive:application];
    }
}

- (void)applicationDidReceiveMemoryWarning:(UIApplication*)application
{
    [[Launcher controller] applicationDidReceiveMemoryWarning:application];
}

- (void)applicationWillTerminate:(UIApplication*)application
{
    [[Launcher controller] applicationWillTerminate:application];
}
@end
Sign up to request clarification or add additional context in comments.

3 Comments

HI! Thank you very much for this guide:) But i got 15 errors after first build (10:32 in video) i.imgur.com/jF5ex6E.png
******************* One of the great Answer. *****************
@Brandon: Can you please let me know, how can I add to a swift project.
1

Here is a most up to date guide that integrate Unity View Controller (Unity 2017.2.0f3) into Xcode 9 (and 9.1) Swift project. If you are using Obj-C, it shares similar concept. It also has a demo project that you can play with to see how everything works before applying to your own project.

https://github.com/jiulongw/swift-unity

1 Comment

how to use the same with ARKIT app exported from unity?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.