日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

unity导出工程导入到iOS原生工程中详细步骤

發(fā)布時間:2025/3/15 编程问答 54 豆豆
生活随笔 收集整理的這篇文章主要介紹了 unity导出工程导入到iOS原生工程中详细步骤 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

一直想抽空整理一下unity原生工程導(dǎo)入iOS原生工程中的詳細(xì)步驟。做iOS+vuforia+unity開發(fā)這么長時間了。從最初的小小白到現(xiàn)在的小白。中間趟過了好多的坑。也有一些的小小收貨。做一個喜歡總結(jié)的人。好了廢話不多說了。上干貨。本人用的是unity?5.4.0f3 + Xcode 7.2。個人認(rèn)為這個版本的影響不是很大的。以下的導(dǎo)入資源過程大家根據(jù)實際需要去選擇是否拷貝資源到原生工程中。(copy if need)

?

一、unity導(dǎo)出工程一開始是這樣子的:

?

?

二、unity導(dǎo)入原生工程的準(zhǔn)備工作。

1.將一些必要的文件導(dǎo)入iOS Native工程中去

1>將Classes 和 Libraries 文件夾以 下面的方式導(dǎo)入自己的工程中

?

2>將Data 文件夾以下面的方式導(dǎo)入工程中

?

3>刪除Native文件夾下的所有.h文件的引用。并將cpp文件導(dǎo)入工程引入。

?

清除native中所有的.h引用。為了更快的刪除定位到這些.h文件。首先選定Native文件夾

?

然后進(jìn)行這樣的操作,注意一定要選擇Remove Reference。千萬不要選擇Move to Trash(下面截圖只是為了演示一下刪除框。類名忽略不要對號刪除,并不是Native中的頭文件)然后再將Native中的cpp文件拖入到工程。勾選1、2、4方框。

?

4>.然后對應(yīng)刪除Libraries-->libil2cpp文件夾。刪除方法同Native中的.h文件的移除。

?

?

三、添加引用庫文件

?

其中因為我用了pod的緣故。libPods庫可以忽略。

?

四、關(guān)閉bitcode

在build settings中bitcode關(guān)閉。

?

五、在 other Linker Flags 添加

-weak_framework CoreMotion -weak-lSystem

?

?

六、在Header Search Path 添加下面這些頭文件引用~

SRCROOT/../../iOS/unity2iOSSRCROOT/../../iOS/unity2iOS{SRCROOT}/../../iOS/unity2iOS/Classes
SRCROOT/../../iOS/unity2iOS/Classes/NativeSRCROOT/../../iOS/unity2iOS/Classes/Native{SRCROOT}/../../iOS/unity2iOS/Libraries
SRCROOT/../../iOS/unity2iOS/Libraries/libil2cpp/includeSRCROOT/../../iOS/unity2iOS/Libraries/libil2cpp/include{SRCROOT}/../../iOS/unity2iOS/Libraries/Plugins/iOS

?

?

?

七、在Library Search Path 中添加

SRCROOT/../../iOS/unity2iOSSRCROOT/../../iOS/unity2iOS{SRCROOT}/../../iOS/unity2iOS/Libraries
${SRCROOT}/../../iOS/unity2iOS/Libraries/Plugins/iOS

?

?

?

八、在other C Flags 中添加 -DINIT_SCRIPTING_BACKEND=1 同是在 other C++ Flags中出現(xiàn)

?

改為C99

?

改PCH(將兩個pch文件合并)

跟著下面的圖片做設(shè)置更改

?

在user-Defined 添加如下

GCC_THUMB_SUPPORT NO
GCC_USE_INDIRECT_FUNCTION_CALLS NO
UNITY_RUNTIME_VERSION?5.4.0f3
UNITY_SCRIPTING_BACKEND il2cpp

以上都要根據(jù)自己工程的具體情況添加。大家切記。

?

九、添加配置腳本RUN SCRIPT(注意按照自己工程中的腳本位置配置)

?

?

十、更改main.m文件為main.mm文件。將Classes中的main.mm中的內(nèi)容合并到原來工程的main.mm工程中。然后刪除Classes中的main文件。

// // main.m //// // Created by Aaron on 16/11/17. // Copyright ? 2016年 Aaron. All rights reserved. // #import <UIKit/UIKit.h> #import "AppDelegate.h" #include "RegisterMonoModules.h" #include "RegisterFeatures.h" #include <csignal>// Hack to work around iOS SDK 4.3 linker problem // we need at least one __TEXT, __const section entry in main application .o files // to get this section emitted at right time and so avoid LC_ENCRYPTION_INFO size miscalculation static const int constsection = 0;void UnityInitTrampoline();// WARNING: this MUST be c decl (NSString ctor will be called after +load, so we cant really change its value) /*** VuforiaNativeRendererController*/ const char* AppControllerClassName = "AppDelegate";int main(int argc, char* argv[]) {@autoreleasepool{UnityInitTrampoline();UnityParseCommandLine(argc, argv);RegisterMonoModules();NSLog(@"-> registered mono modules %p\n", &constsection);RegisterFeatures();std::signal(SIGPIPE, SIG_IGN);NSString *ss = NSStringFromClass([AppDelegate class]);UIApplicationMain(argc, argv, nil,ss);}return 0; }#if TARGET_IPHONE_SIMULATOR && TARGET_TVOS_SIMULATOR#include <pthread.h>extern "C" int pthread_cond_init$UNIX2003(pthread_cond_t *cond, const pthread_condattr_t *attr) { return pthread_cond_init(cond, attr); } extern "C" int pthread_cond_destroy$UNIX2003(pthread_cond_t *cond) { return pthread_cond_destroy(cond); } extern "C" int pthread_cond_wait$UNIX2003(pthread_cond_t *cond, pthread_mutex_t *mutex) { return pthread_cond_wait(cond, mutex); } extern "C" int pthread_cond_timedwait$UNIX2003(pthread_cond_t *cond, pthread_mutex_t *mutex,const struct timespec *abstime) { return pthread_cond_timedwait(cond, mutex, abstime); }#endif // TARGET_IPHONE_SIMULATOR && TARGET_TVOS_SIMULATOR

?

十一、在pch文件中添加?#import "UnityAppController.h"。然后更改AppDelegate

// // AppDelegate.h // // // Created by Aaron on 16/11/17. // Copyright ? 2016年 Aaron. All rights reserved. //#import <UIKit/UIKit.h> @class UnityAppController;@interface AppDelegate : UIResponder <UIApplicationDelegate>@property (strong, nonatomic) UIWindow *window; @property (nonatomic , strong)UIWindow *unityWindow; @property (nonatomic , strong)UnityAppController *unityVC;- (void)showUnityWindow; - (void)hideUnityWindow; - (void)shouldAttachRenderDelegate;@end

?在AppDelegate.mm(因為有混編,本來變一個main.mm文件就可以了。這里也變過來雙保險)

首先添加:

// // AppDelegate.m // // // Created by Aaron on 16/11/17. // Copyright ? 2016年 Aaron. All rights reserved. //#import "AppDelegate.h" #import "HomeViewController.h" #import "UnityAppController.h" #import "VuforiaRenderDelegate.h"extern "C" void VuforiaSetGraphicsDevice(void* device, int deviceType, int eventType); extern "C" void VuforiaRenderEvent(int marker);@interface AppDelegate () {UIButton *_backBtn; }@end@implementation AppDelegate- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];// Override point for customization after application launch.self.window.backgroundColor = [UIColor whiteColor];[application setStatusBarStyle:UIStatusBarStyleLightContent];//unityself.unityVC = [[UnityAppController alloc] init];[self.unityVC application:application didFinishLaunchingWithOptions:launchOptions];HomeViewController *homeVC = [[HomeViewController alloc] init];BaseNavViewController *mainNav = [[BaseNavViewController alloc] initWithRootViewController:homeVC];self.window.rootViewController = mainNav;[self.window makeKeyAndVisible];return YES; }- (void)applicationWillResignActive:(UIApplication *)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 throttle down OpenGL ES frame rates. Games should use this method to pause the game.[self.unityVC applicationWillResignActive:application]; }- (void)applicationDidEnterBackground:(UIApplication *)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.[self.unityVC applicationDidEnterBackground:application]; }- (void)applicationWillEnterForeground:(UIApplication *)application {// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.[self.unityVC applicationWillEnterForeground:application]; }- (void)applicationDidBecomeActive:(UIApplication *)application {[self.unityVC applicationDidBecomeActive:application]; }- (void)applicationWillTerminate:(UIApplication *)application {// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.[self.unityVC applicationWillTerminate:application]; }#pragma mark - #pragma mark ---------------unity開啟與隱藏 - (UIWindow *)unityWindow {if (!_unityWindow) {_unityWindow = UnityGetMainWindow();}return _unityWindow; } - (void)showUnityWindow {[self.unityWindow makeKeyAndVisible];_backBtn = [UIButton buttonWithType:UIButtonTypeCustom];[_backBtn setImage:[UIImage imageNamed:@"返回icon"] forState:UIControlStateNormal];[self.unityWindow addSubview:_backBtn];[_backBtn addTarget:self action:@selector(hideUnityWindow) forControlEvents:UIControlEventTouchUpInside];[_backBtn mas_makeConstraints:^(MASConstraintMaker *make){make.top.equalTo(_unityWindow).offset(30);make.left.equalTo(_unityWindow).offset(15);make.width.mas_equalTo(50);make.height.mas_equalTo(50);}]; } - (void)hideUnityWindow {[self.window makeKeyAndVisible]; } - (void)shouldAttachRenderDelegate {UnityRegisterRenderingPlugin(&VuforiaSetGraphicsDevice, &VuforiaRenderEvent); }@end

?

十二、在unityappcontroller中需要做的配置就是,首先在unityAppController.h中更改GetAppController()方法(當(dāng)然要先引入#import "AppDelegate.h")

NS_INLINE UnityAppController* GetAppController() {AppDelegate *dele = (AppDelegate *)[UIApplication sharedApplication].delegate;return (UnityAppController *)dele.unityVC; }

在.mm文件中重寫shouldAttachRenderDelegate

方法

- (void)shouldAttachRenderDelegate {AppDelegate *deleg = [UIApplication sharedApplication].delegate;[deleg shouldAttachRenderDelegate]; }

至此,導(dǎo)入工作已經(jīng)做完了。愉快地去玩耍吧。

轉(zhuǎn)載于:https://www.cnblogs.com/fuunnyy/p/6227740.html

與50位技術(shù)專家面對面20年技術(shù)見證,附贈技術(shù)全景圖

總結(jié)

以上是生活随笔為你收集整理的unity导出工程导入到iOS原生工程中详细步骤的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。