项目中需要集成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. Git 基本原理与经常使用命令

    平时使用过两种版本号控制软件 SVN 和 Git,平心而论,假设纯粹自己使用,那么绝对 Git 更加适合,本地库.远程库.离线工作.强大而灵活的分支.大名鼎鼎的Github, 这些都是选择 Git 的 ...

  2. Linq的Distinct太不给力了[转]

    假设我们有一个类:Product public class Product { public string Id { get; set; } public string Name { get; set ...

  3. oracle_oracle中修改日期的显示格式

    我的现在的日期格式是          ,要改成英文的需要输入一下命令: ALTER SESSION SET NLS_DATE_LANGUAGE=AMERICAN; 修改后变为: 同样也得若是英文要想 ...

  4. linux_shell_类似sql的orderby 取最大值

    {} {} {} {} {} {} {} {} {} {} 需求场景 ,通过shell 筛选 每分钟的最大一条输出(最后一条) : .info | head

  5. Mobile开发的饕餮盛宴-Zoomla!波CMS2 x2.1正式宣布

    饕餮 [tāo tiè] 古代汉族神话传说中龙的第五子,是一种存在于传说.想象的神奇怪兽. 古书<山海经>介绍其特点是:其形状如羊身人面,其目在腋下,虎齿人爪.其音如婴儿. 作为中国本土软 ...

  6. java 字符串反转

    描述:给我一个字符串,例如I love java,输出: java love I   方法一 public class StringReverse { public void swap(char[] ...

  7. Php设计模式(三):行为型模式part1

    原文详见:http://www.ucai.cn/blogdetail/7023?mid=1&f=5 可以在线运行查看效果哦! 在上一篇我们讲了结构型模式,结构型模式是讨论类和对象的结构的.总共 ...

  8. C++中public,protected,private访问

    对于公有继承方式: (1)父类的public成员成为子类的public成员,允许类以外的代码访问这些成员:(2)父类的private成员仍旧是父类的private成员,子类成员不可以访问这些成员:(3 ...

  9. Access denied for user: &#39;root@localhost&#39; (Using password: YES)

    centos 设备mysql成功后 首次使用root登录发生:Access denied for user: 'root@localhost' (Using password: YES) 因为mysq ...

  10. cocos2d-x 3.1.1 学习笔记[13] listen 监听器

    文章出自于  http://blog.csdn.net/zhouyunxuan //创建监听器 auto listen = EventListenerTouchOneByOne::create(); ...