美文网首页
unity项目集成到iOS项目

unity项目集成到iOS项目

作者: 星空梦想 | 来源:发表于2017-03-08 16:00 被阅读646次

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项目集成到iOS项目

      本文链接:https://www.haomeiwen.com/subject/ojpzwttx.html