unity项目集成到iOS项目

1.导出unity项目

导出的项目如下图

unity 项目导出文件目录

2.新建iOS工程名字为redConnect

3.嵌入相关配置一

3.1)unity导出的工程与已有工程置于相同根路径下。

3.2)在已有工程引用三个文件夹,Data 选择Create folder references,Classes和Libraries 选择Create groups。加入后目录如图

引入后目录

3.3)Remove Reference 掉Libraries中libil2cpp group,和Classes—>Native下的所有.h文件。

3.4)新建PrefixHeader.pch文件。在Classes下Prefix.pch文件代码拷贝至新生成的pct文件。添加 UnityAppController.h 的引用。如下图


预编译文件

3.5)添加脚本文件,目录如下图 (脚本文件),并在工程中添加对.sh文件引用,最后添加如图

脚本文件


脚本文件设置

3.6)引用framework(注意Optional的三个)。如下图


库的添加

4.相关配置二配置Build Setting。

4.1)配置Build Setting如下图


配置01

4.2)Header SearchPaths 中添加如下图 (配置02)


配置02

4.3)Library Search Paths 中添加如下图 (配置03)


配置03

4.4)language及c++相关设置如下图(配置04)

配置04

4.5)Other Linker Flags中添加$(inherited)

5.iOS项目main文件修改

main.m修改为main.mm,删除Classes下的main.mm文件


6. UnityAppController.h中修改

NS_INLINE UnityAppController* GetAppController(){NSObject* delegate = [UIApplication sharedApplication].delegate;

UnityAppController* currentUnityController = (UnityAppController *)[delegate valueForKey:@"unityController"];

return currentUnityController;

}

//inline UnityAppController*    GetAppController()

//{

//    return (UnityAppController*)[UIApplication sharedApplication].delegate;

//    return (UnityAppController*)[[UIApplication sharedApplication] valueForKeyPath:@"delegate.UnityAppController"];

//}

7.AppDelegate.h中修改

#import "UnityAppController.h"

@interface AppDelegate : UIResponder

@property (strong, nonatomic) UIWindow *window;

@property (strong,nonatomic) UIWindow *unityWindow;

@property (strong,nonatomic) UnityAppController *unityController;

-(void)showUnityWindow;

-(void)hideUnityWindow;

8.AppDelegate.m中修改

-(UIWindow *)unityWindow

{

return UnityGetMainWindow();

}

-(void)showUnityWindow

{

[self.unityWindow makeKeyAndVisible];

}

-(void)hideUnityWindow

{

[self.window makeKeyAndVisible];

}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];

self.window.backgroundColor = [UIColor orangeColor];

self.window.rootViewController = [[UINavigationController alloc]initWithRootViewController:[[ViewController alloc]init]];

self.unityController = [[UnityAppController alloc]init];

[self.unityController application:application didFinishLaunchingWithOptions:launchOptions];

[self.window makeKeyAndVisible];

return YES;

}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 集成步骤 所有的配置参考Unity导出来的工程的配置 1. iOS工程中新建Vendor group 2. 添加U...
    沃伦盖茨阅读 7,282评论 0 0
  • 最近遇到一个识别图像后显示3D模型的需求,权衡再三选择了国内的easyAR SDK。Unity建模完成后,导出相应...
    Lotheve阅读 7,939评论 11 6
  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 135,323评论 19 139
  • 一.配置相关 1.首先将资源文件和代码拖入工程;(注意:代码(Code)拖到工程时选择Create groups,...
    不浪漫的罪名阅读 4,719评论 2 2
  • 今天的听记笔记《满满的正能量》题目深深的吸引了我,在听的过程中,也是一气呵成,介绍不同的人的经历给作者带来的...
    chenxi66阅读 1,391评论 0 0