1.導出unity項目
導出的項目如下圖
2.新建iOS工程名字為redConnect
3.嵌入相關配置一
3.1)unity導出的工程與已有工程置于相同根路徑下奶陈。
3.2)在已有工程引用三個文件夾戈鲁,Data 選擇Create folder references侣肄,Classes和Libraries 選擇Create groups。加入后目錄如圖
3.3)Remove Reference 掉Libraries中l(wèi)ibil2cpp 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如下圖
4.2)Header SearchPaths 中添加如下圖 (配置02)
4.3)Library Search Paths 中添加如下圖 (配置03)
4.4)language及c++相關設置如下圖(配置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;
}