首页 > 编程语言 > 详细

Xcode中如何集成Unity

时间:2016-07-16 22:02:38      阅读:389      评论:0      收藏:0      [点我收藏+]

项目中需要集成unity,摸索了大半周,碰到了很多坑,终于搞定。

我的方法是,通过unity导出一个空的iOS项目,然后再新建一个Xcode项目,针对配置页面一一对应。直到配置完全一样,然后倒入相关资源文件。从untiy导出的iOS项目我命名为UnityProject,原生应用我命名为Native。

技术分享

一、拷贝文件

将UnityProject项目下  Classes Data Libraries MapFileParser MapFileParser.sh  拷贝到Native主项目 根目录下

技术分享技术分享

技术分享

二、添加framework

技术分享

三、配置

1、添加run script

技术分享

2、添加Search Paths

Header Search Paths 添加
"$(SRCROOT)/Classes"
"$(SRCROOT)"
$(SRCROOT)/Classes/Native
$(SRCROOT)/Libraries/bdwgc/include
$(SRCROOT)/Libraries/libil2cpp/include

Library Search Paths 添加
$(inherited)
"$(SRCROOT)"
"$(SRCROOT)/Libraries"

3、添加预处理文件

Classes/Prefix.pch

技术分享

4、添加 -DINIT_SCRIPTING_BACKEND=1

技术分享

四、修改main.m

  • 复制Classes/main.mm内容到main.m  修改main.m的扩展名为.mm
  • 删除Unity生成main.mm
  • return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));

五、修改 unityAppController

inline UnityAppController* GetAppController()
{
return (UnityAppController*)[[UIApplication sharedApplication] valueForKeyPath:@"delegate.unityAppController"];

}

 

六、修改 appdelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    BOOL returnBool;
    if (_unityAppController == nil) {
        
        _unityAppController = [[UnityAppController alloc] init];
    }
    returnBool = [_unityAppController application:application didFinishLaunchingWithOptions:launchOptions];
//    self.window = _unityAppController.window;
    
    HelloViewController *vc = [[HelloViewController alloc] init];
    self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:vc];
    self.window.rootViewController = nav;
    [self.window makeKeyAndVisible];
    
    return YES;
    
}

- (void)applicationWillResignActive:(UIApplication *)application {
    [_unityAppController applicationWillResignActive:application];
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    [_unityAppController applicationDidEnterBackground:application];

    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    [_unityAppController applicationWillEnterForeground:application];

    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    [_unityAppController applicationDidBecomeActive:application];

    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application {
    [_unityAppController applicationWillTerminate:application];
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

错误总结

1、Expected identifier or ‘(‘

修改UnityViewControllerBaseiOS.h

技术分享

#ifdef __cplusplus
extern "C" {
#endif
    void AddViewControllerRotationHandling(Class class_, IMP willRotateToInterfaceOrientation, IMP didRotateFromInterfaceOrientation, IMP viewWillTransitionToSize);
#ifdef __cplusplus
}
#endif

#ifdef __cplusplus
extern "C" {
#endif
    void AddViewControllerDefaultRotationHandling(Class class_);
#ifdef __cplusplus
}
#endif

 

Xcode中如何集成Unity

原文:http://www.cnblogs.com/ymonke/p/5676981.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!