项目中需要集成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的更多相关文章

  1. iOS中支付宝集成

    iOS中支付宝集成 如今各种的App中都使用了三方支付的功能,现在将我在使用支付宝支付集成过程的心得分享一下,希望对大家都能有所帮助 要集成一个支付宝支付过程的环境,大致需要: 1>公司:先与支 ...

  2. Cocos开发中性能优化工具介绍之Xcode中Instruments工具使用

    Instruments是动态分析工具,它与Xcode集成在一起,可以在Xcode中通过菜单Product→Profile启动.启动如图所示,Instruments有很多跟踪模板可以动态分析和跟踪内存. ...

  3. xcode中的第三方库配置问题总结

    xcode中的第三方库配置总结 在导入第三方库的时候,总是会遇到许多的问题.在这里,我记录一下学到的一些知识点.写得比较乱.只要是想要记录下来,在第三方库导入的时候,遇到的一些问题. 参考网址: ht ...

  4. XCode中使用SVN 教程

    修改subversion.config方法: 可以直接在终端上输入:vi ~/.subversion/config来编辑. 也可以通过Finder搜索.subversion,点击下边的+号,进入高级搜 ...

  5. 盘点Xcode中开发者最喜爱的十大开源插件

    Xcode IDE拥有着诸如导航.重构.校准等众多非常高大上的工具,而予以辅助的插件更是在Xcode的基础上对相关功能进行改进与扩展.在应用开发过程中,通过开源包管理器Alcatraz对插件进行安装管 ...

  6. Xcode Server持续集成

    这是一篇2017-11-12 年我还在 ezbuy 的一篇文章,时间过去很早了,最近在整理笔记的时候发现了, 同步过来,文章内容现在是否有效不确定,应该大差不差,读者仅做参考 最后更新 2017-11 ...

  7. iOS开发时,在Xcode中添加多个Targets进行版本控制

    在iOS开发中,很可能有以下场景:需要开发多个版本,或因需区分收费版,免费版,或因为网络环境需要区分测试版,发布版,或因渠道不同需要区分企业版,AppStore版等等.解决办法无非就是CheckOut ...

  8. 在Xcode中使用Git进行源码版本控制

    http://www.cocoachina.com/ios/20140524/8536.html 资讯 论坛 代码 工具 招聘 CVP 外快 博客new 登录| 注册   iOS开发 Swift Ap ...

  9. Atitit.mybatis的测试  以及spring与mybatis在本项目中的集成配置说明

    Atitit.mybatis的测试  以及spring与mybatis在本项目中的集成配置说明 1.1. Mybatis invoke1 1.2. Spring的数据源配置2 1.3. Mybatis ...

随机推荐

  1. unity3d 学习笔记_____Native2d 刚体、冲击、联合使用

    Mass Mass of the rigidbody. Linear Drag Drag coefficient affecting positional movement. Angular Drag ...

  2. 2机器学习实践笔记(k-最近邻)

    1:算法是简单的叙述说明 由于训练数据样本和标签,为测试数据的示例,从最近的距离k训练样本,此k练样本中所属类别最多的类即为该測试样本的预測标签. 简称kNN.通常k是不大于20的整数,这里的距离通常 ...

  3. 使用Eclipse+Maven+Jetty构建Java Web开发环境(几个教程综合集成2014发行)

    工作需要使用Jetty由于web集装箱,得知Eclipse+Maven+Jetty该组合是非常好的,因此,要在网上找了很多教程,但不写或多或少特定的或过时的内容而导致最终的配置失败,易于配置为未来的同 ...

  4. 第11章 享元模式(Flyweight Pattern)

    原文 第11章 享元模式(Flyweight Pattern) 概述:   面向对象的思想很好地解决了抽象性的问题,一般也不会出现性能上的问题.但是在某些情况下,对象的数量可能会太多,从而导致了运行时 ...

  5. HTML5使用和实战分析HTML5 WebSocket API

    通过引入一个简单的界面(请参见下面的列表),开发替代技术,由于长轮询和"永远框架,从而进一步减少延迟. 后台代码 [Constructor(in DOMString url, optiona ...

  6. Repository模式

    Repository模式的两种写法与疑惑 现如今DDD越来越流行,园子里漫天都是介绍关于它的文章.说到DDD就不能不提Repository模式了,有的地方也叫它仓储模式. 很多时候我们对Reposit ...

  7. mac os x10.11.2系统eclipse无法读取环境变量的问题

    eclipse调试Android自动化脚本的时候一直无法找到adb,遇到这么坑的问题,折腾死了,记录一下. mac os x10.11.2系统GUI程序(eclipse)无法读取~/.bash_pro ...

  8. 怎么会Sql serverW数据库模型图转化成ord于--您还可以查看属性信息字段

    1. 于Sql server数据库,创建数据库模型图 -- Database Diagrams watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvamN4NTA ...

  9. 瘸腿蛤蟆笔记29-cocos2d-x-3.2 Box2d物理引擎dynamics模块介绍

    转载标明出处:http://blog.csdn.net/notbaron/article/details/38611335 上篇回想 本篇名言:奋斗.寻觅.发现,而不屈服.[诗人丁尼生] 上篇中,我们 ...

  10. Node.js与MongoDB的基本连接示例

    Node.js与MongoDB的基本连接示例 前提 已经安装了node.js和MongoDB,本文使用的node.js是v0.12.0,MongoDB是3.0.0. 初始化数据 启动MongoDB服务 ...