<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>
除系統(tǒng)外的庫為第三方庫.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.reibang.com/p/a941230b626d
http://www.cnblogs.com/Erma-king/p/5544502.html