Reputation: 11
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
Upvotes: 1
Views: 3213
Reputation: 355
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
Upvotes: 1
Reputation: 23500
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
Upvotes: 4