1、将Unity
项目下面的五个文件复制到iOS
项目的根目录
C86C701F-2F34-4EE2-AA55-6E9ED801F9F4.png
复制到iOS
的项目后的目录如下:
2、在自己iOS
项目中引用这几个文件,但是引用跟我们平时引用的不一样,右键Add File to...
分别选择Classes
和Libraries
、MapFileParser.sh
,在Options
里面勾选Create groups
,不要选 Copy items if needed
1ED93EDD-EABF-472A-928B-55D2C30F900F.png
2.1剩下的Data
文件,右键Add Files to...
,在Options
里面勾选Create folder references
,不要选Copy items if needed
563F0D23-9089-4F80-AA64-F6EE23223883.png
完成之后的文件夹目录如下:
523249BB-C56A-4CEA-91F6-415A8CA8027C.png
2.2,删除Library
->libil2cpp
这个文件的引用
C68EDE7C-191E-4D36-BD77-3D18DBFD44BC.png
3,对ios
工程环境的配置,这里的配置都是以Unity
的配置为参考
3.1,添加应用库
EF90FD74-7EB1-4A8C-8992-71899CE7E3D7.png这里添加应用库文件,最好参照Unity项目工程里面的来~
3.2,添加Run Script
93C1BBA7-D0A3-4624-9111-D60BC5687FDB.png3.2,添加头文件和库的搜索路径
59E26554-D9DD-478C-A463-78778C138710.png3.3, 其他一些配置
D8181506-DADA-4606-84B2-3C99D01DB29D.png 99663DDE-865B-47FB-8541-70FFACC276A1.png C93CECC9-0FFC-49AD-BA89-2720B6E6DCFE.png ACFBB4BE-359E-45A9-B958-7582B9E48866.png 07882B20-D3FA-4FC8-9B1A-9029D19721A8.png上面注意:如果自己的iOS
项目有pch
文件,那就把Prefix.pch
里面的文件拷贝到自己的pch
文件中,反之也行(注意pch路径),并添加#import"UnityAppController.h"
FC8772AB-DE80-478C-BAE7-D221ACD8B34B.png
4、修改main.m文件,把Classes/
文件夹里面的main.mm
里面的代码,拷贝到Supporting Files/
下的main.m
文件中,并把后缀改成.mm
,修改如下图
image.png
然后删除
Classes
目录下单main.mm
文件。注意:一样是删除引用,到了这里基本集成完毕了~~~
5、修改AppDelegate
文件
AppDelegate.h
文件
#import "AppDelegate.h"
#import "ViewController.h"
@interface AppDelegate ()
@end
@implementation AppDelegate
- (UIWindow *)unityWindow {
return UnityGetMainWindow();
}
- (void)showUnityWindow {
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setTitle:@"返回iOS界面" forState:UIControlStateNormal];
[button setFrame:CGRectMake(100, 100, 200, 100)];
button.backgroundColor = [UIColor redColor];
[button addTarget:self action:@selector(hideUnityWindow) forControlEvents:UIControlEventTouchUpInside];
[self.unityWindow addSubview:button];
[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 whiteColor];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:[[ViewController alloc] init]];
self.window.rootViewController = nav;
self.unityController = [[UnityAppController alloc] init];
[self.unityController application:application didFinishLaunchingWithOptions:launchOptions];
[self.window makeKeyAndVisible];
return YES;
}
- (void)applicationWillResignActive:(UIApplication *)application {
[_unityController applicationWillTerminate:application];
}
- (void)applicationDidEnterBackground:(UIApplication *)application {
[_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 {
[_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 {
[_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 {
[_unityController applicationWillTerminate:application];
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}
@end
6、修改UnityAppController.h
文件
#import "AppDelegate.h"
inline UnityAppController* GetAppController()
{
AppDelegate *delegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
return delegate.unityController;
// return _UnityAppController;
}
7、启动Unity
界面
进入Unity
界面
[(AppDelegate *) [UIApplication sharedApplication].delegate showUnityWindow];
UnityPause(false);
跳出Unity
界面
[(AppDelegate *) [UIApplication sharedApplication].delegate hideUnityWindow];
UnityPause(true);
网友评论