因爲最近上有相似需求 因此這兩天研究了下。xcode
Data
Classes
MapFileParser.sh
Libraries
MapFileParser執行文件
注意:Data文件導入類型爲Creat folde references Classes MapFileParser.sh Libraries MapFileParser執行文件 經過Creat groups導入app
導入後以下圖所示ide
Remove Refernces
將classes中main.mm 中的代碼複製到項目的main.m中 並把後綴也改成mm 並將ui
UIApplicationMain(argc, argv, nil, [NSString stringWithUTF8String: AppControllerClassName]);
複製代碼
修改成atom
UIApplicationMain(argc, argv, nil, [NSString stringWithUTF8String: @"AppDelegate"]);
複製代碼
AppDelegate.hspa
@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) UIWindow *unityWindow;
@property (strong, nonatomic) UnityAppController *unityController;
-(void)StartUnity; //開啓unity
- (void)hideUnityWindow; //暫停
複製代碼
AppDelegate.mcode
#import "AppDelegate.h"
#import "SRViewController.h"
#import "UnityAppController.h"
@interface AppDelegate ()
@end
@implementation AppDelegate
-(UIWindow *)unityWindow{
UIWindow *window = UnityGetMainWindow();
return window;
}
-(void)showUnityWindow{
UnityPause(false);
}
-(void)hideUnityWindow{
UnityPause(true);
}
-(void)StartUnity {
[_unityController applicationDidBecomeActive:[UIApplication sharedApplication]];
[self showUnityWindow];
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
self.unityController = [[UnityAppController alloc] init];
[_unityController application:application didFinishLaunchingWithOptions:launchOptions];
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
self.window.backgroundColor = [UIColor redColor];
SRViewController *vc = [[SRViewController alloc] init];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:vc];
self.window.rootViewController = nav;
[self.window makeKeyAndVisible];
return YES;
}
- (void)applicationWillResignActive:(UIApplication *)application {
[_unityController applicationWillResignActive:application];
}
- (void)applicationDidEnterBackground:(UIApplication *)application {
[_unityController applicationDidEnterBackground:application];
}
- (void)applicationWillEnterForeground:(UIApplication *)application {
[_unityController applicationWillEnterForeground:application];
}
- (void)applicationDidBecomeActive:(UIApplication *)application {
[_unityController applicationDidBecomeActive:application];
}
- (void)applicationWillTerminate:(UIApplication *)application {
[_unityController applicationWillTerminate:application];
}
複製代碼
將orm
inline UnityAppController* GetAppController()
{
return _UnityAppController;
}
複製代碼
修改成cdn
#import "AppDelegate.h"
inline UnityAppController* GetAppController()
{
AppDelegate *delegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
return delegate.unityController;
}
複製代碼
@implementation SRViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.navigationItem.title = @"123";
self.view.backgroundColor = [UIColor greenColor];
UIButton * btn = [[UIButton alloc] initWithFrame:CGRectMake(50, 400, 100, 50)];
[btn addTarget:self action:@selector(test:) forControlEvents:UIControlEventTouchUpInside];
[btn setTitle:@"開始" forState:UIControlStateNormal];
btn.tag = 1;
[self.view addSubview:btn];
UIButton * btn2 = [[UIButton alloc] initWithFrame:CGRectMake(50, 450, 100, 50)];
[btn2 addTarget:self action:@selector(test:) forControlEvents:UIControlEventTouchUpInside];
btn2.tag = 2;
[btn2 setTitle:@"結束" forState:UIControlStateNormal];
[self.view addSubview:btn2];
}
- (void)test:(UIButton *) btn{
AppDelegate *delegate = [UIApplication sharedApplication].delegate;
delegate.unityWindow.frame = CGRectMake(0, 0, 100, 200);
if (btn.tag == 1) {
[self.view addSubview:delegate.unityWindow];
delegate.unityWindow.hidden = NO;
[delegate StartMyUnity];
}else {
[delegate hideUnityWindow];
delegate.unityWindow.hidden = YES;
}
}
複製代碼
添加這兩項的時候注意和unity的工程中保持一致blog
libiconv.2.dylib
添加