Xcode9原生工程接入unity2017導出工程


1、unity導出工程設置如下

2、把導出工程的以下幾個文件拷到原生的工程下面。

 

3、原生目錄如下

4、把拷貝的unity文件拉到面板,除了data文件夾reference選項,其他都是createGroup,都要選copy items if needed,拉完如下

5、庫跟着xcode工程添加

6、

7、這里切記,不要添加$(inherited),而且順序不能倒,不然編譯會找不到CoreMotion文件,什么原理我也不知道,知道的可以留言告訴我謝謝。

 

 

 

 

8、這兩個路徑參考unity工程,前提是你拷過來的文件擺放相對路徑得跟unity導出的工程一樣。

 

 

 9、other C flags只添加這一行,可以到unity工程拷貝

 

 

 

10、

 

11、Classes里面的預編譯文件路徑添加到這來,預編譯文件加上下面一句。如果源工程已經有pch文件,就拷到一起只留一個吧。

    #import <Foundation/Foundation.h>

    #import <UIKit/UIKit.h>

    #import "UnityAppController.h"

12、可從unity工程拷過來

 

13、加RunScripts

 

 14、Classes里面的main.mm內容考到原生的main.m里面,並把原生的后綴改成.mm,然后把Classes里面的main刪啦。直接move to trash。

15、修改main.mm:

//const char* AppControllerClassName = "UnityAppController";

const char* AppControllerClassName = "AppDelegate"

 16、修改UnityAppController.h

//inline UnityAppController*  GetAppController()

//{

//    return (UnityAppController*)[UIApplication sharedApplication].delegate;

//}

#import "AppDelegate.h"

inline UnityAppController*  GetAppController()

{

    AppDelegate *delegate=(AppDelegate *)[UIApplication sharedApplication].delegate;

    return delegate.unityController;

}

 

17、AppDelegate.h修改:

 

#import <UIKit/UIKit.h>

@class UnityAppController; 

@interface AppDelegate : UIResponder <UIApplicationDelegate>

 

@property (strong, nonatomic) UIWindow *window;

@property (strong, nonatomic) UIWindow *unityWindow;

 

@property (strong, nonatomic) UnityAppController *unityController;

 

- (void)showUnityWindow;

- (void)hideUnityWindow;

 18、AppDelegate.m修改:

 

#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];

    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:.

}

@end

 

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM