<b>一.配置问题<b>
<b>1.将unity工程中的这几个文件夹copy到ios工程中的根目录下面</b>
文件夹截图.png
<b>2.在工程中引入,class,libraries,data,MapFileParse.sh。并且删除class-native-所有.h文件</b>
data引入与其他不一样.png
<b>3.在工程中添加需要的库</b>
除系统外的库为第三方库.png
<b>4.build setting中更改配置选项</b>
1.enable Bitcode NO
2
3
4.可以略过,如果冲突
5
6
10
7
8
9
11
<b>二.代码部分</b>
//AppDelegate.h
#import "AppDelegate.h"
inline UnityAppController* GetAppController()
{
AppDelegate*delegate = (AppDelegate*)[UIApplication sharedApplication].delegate;
return delegate.unityController;
}
//pch文件
#ifdef __OBJC__
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import "UnityAppController.h"
#endif
#include "Preprocessor.h"
#include "UnityTrampolineConfigure.h"
#include "UnityInterface.h"
#ifndef __OBJC__
#if USE_IL2CPP_PCH
#include "il2cpp_precompiled_header.h"
#endif
#endif
#ifndef TARGET_IPHONE_SIMULATOR
#define TARGET_IPHONE_SIMULATOR 0
#endif
#define printf_console printf
//删除unity的 main.mm 复制到ios工程的main.m并改为main.mm
//修改的地方
#import "AppDelegate.h"
UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
//AppDelegate.h添加部分
#import <UIKit/UIKit.h>
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) UIWindow *unityWindow;
@property (strong, nonatomic) UnityAppController *unityController;
- (void)showUnityWindow;
- (void)hideUnityWindow;
#import "AppDelegate.h"
@interface AppDelegate ()
@end
@implementation AppDelegate
-(UIWindow *)unityWindow{
return UnityGetMainWindow();
}
-(void)showUnityWindow{
[self.unityWindow makeKeyAndVisible];
}
-(void)hideUnityWindow{
[self.window makeKeyAndVisible];
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
self.window.backgroundColor = [UIColor whiteColor];
self.unityController = [[UnityAppController alloc]init];
[self.unityController application:application didFinishLaunchingWithOptions:launchOptions];
[self showUnityWindow];
// [[DownloadNetWorkForUnity sharedInstance] downLoadMode:@"https://api-871ar.eschervr.com/resource/get_list?device_type=ios"];
return YES;
}
- (void)applicationWillResignActive:(UIApplication *)application {
[self.unityController 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 invalidate graphics rendering callbacks. Games should use this method to pause the game.
}
- (void)applicationDidEnterBackground:(UIApplication *)application {
[self.unityController 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 {
[self.unityController applicationWillEnterForeground:application];
// Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
}
- (void)applicationDidBecomeActive:(UIApplication *)application {
[self.unityController 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 {
[self.unityController applicationWillTerminate:application];
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}
</b>
</b>
<b>三.常见坑<b>
1.clang: error: no such file or directory: 'CoreMotion'
位置不能改变
-weak_framework
CoreMotion
-weak-lSystem
-licucore
2.main.mm
3.UnityAppController
AppDelegate*delegate = (AppDelegate*)[UIApplication sharedApplication].delegate;
return delegate.unityController;
4.相机权限
Privacy - Camera Usage Description
Camera access required for target detection and tracking
</b>
<h3>三.互相调用代码整理</h3>
<b>参考<b>:
http://blog.csdn.net/dylan_lwb_/article/details/51452470
http://www.jianshu.com/p/a941230b626d
http://www.cnblogs.com/Erma-king/p/5544502.html