




已阅读5页,还剩18页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
IOS项目嵌入Unity工程开发文档目录:1. Unity导出Xcode工程 2. 将Unity导出的项目整合到已有的IOS项目中 3. 在IOS应用里反复打开和关闭Unity4. 拍照结束后分享照片概要说明:unity版本:5.3.3f1Xcode版本:7.3.1Vuforia版本:5.5.91、Unity导出Xcode工程1.1 点击File-Build Settings1.2 设置Player Settings1、点击Player Settings按钮,在Other Settings选项中设置Scripting Backend为“Mono2x”,再设置Stripping Level*为“Strip Byte Code”,再将Scripting Backend设置回“IL2CPP”,去掉Strip Engine code* 的勾选。2、设置Graphics API 为OpenGLES2,选中其他多余的选项点击右下角“-”移除。注意:只有先将Scripting Backend设置为“Mono2x”才会出现Stripping Level*选项;Graphics API 的Metal选项必须移除否则影响渲染速度可能渲染不出来1.3选择导出设备类型确保你的机器中装有 Xcode 4及以上版本 ,IOS 设备连接在电脑中,然后选中IOS设备,单机Build and Run。导出成功后自动打开Xcode 并且运行我们导出的这个项目。1.4添加Unity和IOS交互的工具类在IOS项目中添加保存图片到相册和提供Unity和IOS功能切换的工具类PhotoManager、UnityTools,编译导出的项目2、将Unity导出的项目整合到已有的IOS项目中2.1 添加辅助文件添加文件UnityIntegration.xcconfig到ios项目中并设置Configuration2.2 设置UNITY_IOS_EXPORTED_PATH和UNITY_RUNTIME_VERSIONtargets - Build Settings - User-DefinedUNITY_IOS_EXPORTED_PATH:设置为unity导出项目的路径UNITY_RUNTIME_VERSION:设置为unity的版本(demo中使用的为版本为5.3.3f1)2.3 删除Main.storyboard文件h,在info.plist中移除Main storyboard file base name2.4 映射文件将Unity3d导出的IOS项目下的Classes、Data 、Libraries 目录映射到IOS主项目中(别着急,2.4看完再下手)注意:复制Classes和Liariaries目录选择Create groups,复制Data目录选择Create folder references;切记不能勾选Copy items if needed2.4.1 导入Classes和Libraries目录2.4.2 导入Data2.5 移除不必要的文件移除非link必要的文件可以加快运行速度,也可不移除。2.5.1 移除Classes中非必要文件先筛选出.h的文件,在Classes - Native 选中非Vuforia和zxing开头的.h文件删除*注意:选择的是Remove References2.5.2 移除Libraries中非必要文件Libraries中选择libil2cpp目录删除*注意:选择的是Remove References(同上)2.6 添加Link Binary With Libraries2.7 添加预处理文件PrefixHeader.pch创建一个新的PrefixHeader.pch文件,拷贝以下代码替换原来的代码,并将次头文件引入到项目中#ifndef PrefixHeader_pch #define PrefixHeader_pch #ifdef _OBJC_ #import #import #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 #endif2.8 修改main.m文件2.8.1替换Supporting Files 中main.m中的内容复制Classes/main.mm中的内容替换main.m中的内容,并修改后缀名 为.mm;修改main函数,替换代码“const char* AppControllerClassName = UnityAppController;”为“const char* AppControllerClassName = AppDelegate;”如下图:2.8.2 移除Classes中的main.mm文件*注意:不是直接删除Classes目录下的main.mm文件,具体操作如图:2.9 Unity源文件中的必要必要文件至Unity导出的xcode项目中unity源文件 - Assets - Plugins - iOS 拷贝以下4个文件:再将拷贝的4个文件粘贴在unity导出的Xcode项目中 Libraries - Plugins - iOS目录下,如图:最后将这4个文件添加到IOS项目中去2.10 修改VuforiaNativeRendererController.mm打开VuforiaNativeRendererController.mm文件注释最后一行代码:2.11 修改UnityAppController2.11.1 在UnityAppController.h中修改内联函数:将如下代码:inline UnityAppController* GetAppController() return (UnityAppController*)UIApplication sharedApplication.delegate; 替换为:NS_INLINE UnityAppController* GetAppController()NSObject* delegate = UIApplication sharedApplication.delegate;UnityAppController* currentUnityController = (UnityAppController *)delegate valueForKey:unityController; return currentUnityController; 2.11.2 修改UnityAppController.m中的shouldAttachRenderDelegate函数引入头文件#import AppDelegate.h并将空函数- (void)shouldAttachRenderDelegate 替换为- (void)shouldAttachRenderDelegate AppDelegate *delegate = (AppDelegate *)UIApplication sharedApplication.delegate; delegate shouldAttachRenderDelegate; 2.12 修改AppDelegate2.12.1 替换AppDelegate.h代码打开AppDelegate.h文件将正文代码用一下代码替换:#import #import UnityAppController.hinterface AppDelegate : UIResponder property (strong, nonatomic) UIWindow *window;property (strong, nonatomic) UIWindow *unityWindow;property (strong, nonatomic) UnityAppController *unityController;/* * 显示UnityWindow */- (void)showUnityWindow;/* * 注册Vuforia Event */- (void)shouldAttachRenderDelegate;end2.12.2 修改AppDelegate.m文件将文件名AppDelegate.m修改为AppDelegate.mm 将正文代码替换为以下代码:#import AppDelegate.h#import ViewController.h#import VuforiaRenderDelegate.hinterface AppDelegate ()endextern C void VuforiaRenderEvent(int marker);implementation AppDelegate#pragma mark - ShowUnityWindow- (UIWindow *)unityWindow return UnityGetMainWindow();- (void)showUnityWindow self.unityWindow makeKeyAndVisible;#pragma mark - UIAplicationDelegate- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions self.window = UIWindow alloc initWithFrame:UIScreen mainScreen.bounds; self.window.backgroundColor = UIColor clearColor; self.window.rootViewController = ViewController alloc init; self.unityController = UnityAppController alloc init; self.unityController application:application didFinishLaunchingWithOptions:launchOptions; self.window makeKeyAndVisible; return YES;- (void)shouldAttachRenderDelegate self.unityController.renderDelegate = VuforiaRenderDelegate alloc init; UnityRegisterRenderingPlugin(NULL, &VuforiaRenderEvent); #if UNITY_VERSION434 UnityRegisterRenderingPlugin(NULL, &VuforiaRenderEvent); #endif - (void)applicationWillResignActive:(UIApplication *)application self.unityController applicationWillResignActive:application;- (void)applicationDidEnterBackground:(UIApplication *)application self.unityController applicationDidEnterBackground:application;- (void)applicationWillEnterForeground:(UIApplication *)application self.unityController applicationWillEnterForeground:application;- (void)applicationDidBecomeActive:(UIApplication *)application self.unityController applicationDidBecomeActive:application;- (void)applicationWillTerminate:(UIApplication *)application self.unityController applicationWillTerminate:application;end3、在IOS应用中反复打开和关闭Unity页面3.1 设置从IOS页面启动在UnityAppController.mm中注释启动Unity的代码,打开应用之后不直接启动Unity3.2 启动(重启)、退出Unity3.2.1 注册启动(重启)、退出Unity的通知在UnityAppController.mm中注册通知3.2.2 添加判断启动和重启Unity的变量在UnityAppController.mm中添加变量 _isReStart(BOOL)3.2.3添加重启、退出Unity的实现方法在UnityAppController.mm中添加代码:/启动(重启)Unity的通知方法- (void) Start:(UIApplication *)application if (_isReStart) self reStartUnity:application; else self startUnity:application; _isReStart = true; - (void)StartWithInfo:(UIApplication *)application UnitySendMessage(_GameManager, LoadModel, d34c3d8b469bf2ea8767d4a955852852); if (_isReStart) self reStartUnity:application; else self startUnity:application; _isReStart = true; /重启Unity- (void)reStartUnity:(UIApplication*)application UnityPause(0); _didResignActive = NO; /设置Unity视图为当前视图 UnityGetMainWindow() rootViewController view setHidden:NO; _window setRootViewController:_rootController; UnityGetMainWindow() makeKeyAndVisible; NSLog(n-RESTART UNITY-);/退出Unity的通知方法-(void)exitUnity UnityPause(1); _didResignActive = YES; Profiler_UninitProfiler(); _window setRootViewController:ViewController alloc init; NSLog(n-EXIT UNITY-);4、拍照结束后分享照片4.1 友盟分享相关配置4.1.1接入友盟分享的sdk和第三方framework 详细步骤及SDK请参考/social/ios/operation4
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
评论
0/150
提交评论