2016-12-17/unity5.5.0f3/xcode_8.1 (8b62)/macbook/os X 10.11.6
Reference Address:
https://the-nerd.be/2015/11/13/integrate-unity-5-in-a-native-ios-app-with-xcode-7/
Http://www.jianshu.com/p/715adc38e451 recently received a lot of orders are required to embed AR module into the original app, instead of developing new apps, whether it is high-pass Vuforia or the Easyar, to achieve model animation, Either write the rendering yourself with opengles, or use unity directly, obviously, the amount of work that is rendered with opengles is large, and the amount of work embedded in unity is much smaller, and the rendering is better, and the advantage of the Opengles method may be more stable. This blog is mainly in accordance with the foreigner's video, that is, the content of the video text only, and Jane in the book on the big write almost. Recommended direct watch video, hands-on teaching.
Well, the official start: Unity Export iOS project, for convenience, called the exported iOS project for the Iunity project. Export playersetting settings to pay attention to the part of the main is the Scripting backend for Il2cpp, as for the graphics API basic disregard, such as for the sake of insurance, you can uncheck the previous tutorial, delete metal only to retain OpenGL ES2, But I did not make this change this time.
At this point, the preparation is finished, to create a new single View in Xcode (without referencing the UI and unit package) or open the existing project, for convenience, said the original project for the Inative project.
The classes and libraries in the Iunity project are introduced into the Inative project, and the Create Groups is selected.
3.1 Introduce data from the Iunity project into the inative and select Create Folder reference.
For security and compile speed, you can delete all the. h files under Classes/native in Inative.
4.1 Similarly, you can also delete the Libraries/libil2cpp folder in Inative.
The PCT file was added to the inative, this time named Prefixheader.pch.
5.1 Copy the contents of the Prefix.pch file in classes to PREFIXHEADER.PCH (not fully overwritten).
5.2 Add "#import" UnityAppController.h "" in prefixheader.pch.
The contents of the MAIN.MM in classes are all copied to the MAIN.M in supporting files (replace all, if there is a project, manual modification).
6.1 Modify MAIN.M to main.mm (. mm suffix to compile c,oc,c++), remove compile compilation of sources path to classes main.mm of build phase.
Referencing the framework (note optional items)
Configure build Setting, if the tutorial fails to open your own exported iunity project, this step is just to set the Inative build Setting to iunity build Setting.
You can also refer to the book of the Big picture.
8.1 Header Search Paths
8.2 Library Search Paths
8.3 C + + Language dialect:c++11,enable C + + Runtime Types No
8.4 precompile Prefix Header:yes, Prefix header:inative/prefixheader.pch (adjusted according to your own path).
8.5 C Language Dialect:c99
8.6 Other C Flags:-dinit_scripting_backend=1
8.7 user-defined:
Gcc_thumb_support:no
Gcc_use_indirect_function_calls:no
Unity_runtime_version:5.5.0f3
Unity_scripting_backend:il2cpp
8.8 Other Linker Flags:-weak_framework Coremotion-weak-lsystem Code Modification Section:
9.1unityappcontroller.h (in classes)
9.2appdelegate.h
9.3appdelegate.m
APPDELEGATE.M//iosnativeunity////Created by Develop on 2016/12/16. COPYRIGHT©2016 year Develop.
All rights reserved.
#import "AppDelegate.h" @interface appdelegate () @property (nonatomic, strong) Uinavigationcontroller *NAVVC;
@end @implementation appdelegate-(UIWindow *) Unitywindow {return Unitygetmainwindow ();}
Add by PGW-(void) Showunitywindow {[Self.unitywindow makekeyandvisible];}
-(void) Hideunitywindow {[Self.window makekeyandvisible];} -(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (Nsdictionary *) launchOptions {//Ove
Rride point to Customization after application launch.
Self.window = [[UIWindow alloc] Initwithframe:[uiscreen mainscreen].bounds];
Self.window.backgroundColor = [Uicolor Redcolor];
Viewcontroller *viewcontroller = [[Viewcontroller alloc] Initwithnibname:nil Bundle:nil]; SELF.NAVVC = [[Uinavigationcontroller alloc] Initwithrootviewcontroller:viewcontroller];
Self.window.rootViewController = SELF.NAVVC;
Self.unitycontroller = [[Unityappcontroller alloc] init];
[Self.unitycontroller application:application didfinishlaunchingwithoptions:launchoptions];
[Self.window makekeyandvisible];
return YES; }-(void) Applicationwillresignactive: (uiapplication *) application {//Sent when the application was about to move F Rom Active to inactive state. This can occur for certain types of temporary interruptions (such as a incoming phone call or SMS message) or when the US
Er quits the application and it begins the transition to the background state. Use the This method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks.
Games should use this method to pause the game.
[Self.unitycontroller applicationwillresignactive:application]; }-(void) Applicationdidenterbackground: (uiapplication *) application {//Use this method to release shared resource s, save user data, invalidate TimERS, and store enough application state information-to-restore your application to their current state in case it's Termina
Ted later. If your application supports background execution, this method is called instead of Applicationwillterminate:when the
User quits.
[Self.unitycontroller applicationdidenterbackground:application]; }-(void) Applicationwillenterforeground: (uiapplication *) application {//called as part of the transition from the Background to the active state;
Here's can undo many of the changes made on entering the background.
[Self.unitycontroller applicationwillenterforeground:application]; }-(void) Applicationdidbecomeactive: (uiapplication *) application {//Restart any tasks this were paused (or not ye T started) while the application was inactive.
If the application is previously in the background, optionally refresh the user interface.
[Self.unitycontroller applicationdidbecomeactive:application]; }-(void) applicationwilltermInate: (uiapplication *) application {//called when the application was about to terminate. Save data if appropriate.
See also Applicationdidenterbackground:.
[Self.unitycontroller applicationwillterminate:application];
} @end
9.4VIEWCONTROLLER.M
VIEWCONTROLLER.M//iosnativeunity////Created by Develop on 2016/12/16. COPYRIGHT©2016 year Develop.
All rights reserved.
#import "ViewController.h" @interface Viewcontroller () @property (nonatomic, strong) UIButton *showunitybutton;
@end @implementation Viewcontroller-(void) viewdidload {[Super viewdidload];
Additional setup after loading the view, typically from a nib.
Self.view.backgroundColor = [Uicolor Bluecolor];
Self.showunitybutton = [UIButton Buttonwithtype:uibuttontypesystem];
[Self.showunitybutton settitle:@ "Show Unity" forstate:uicontrolstatenormal];
Self.showUnityButton.frame = CGRectMake (0, 0, 100, 44);
Self.showUnityButton.center = Self.view.center;
[Self.view AddSubview:self.showUnityButton]; [Self.showunitybutton addtarget:self Action: @selector (showunitybuttontouched:) forControlEvents:
UIControlEventTouchUpInside]; }-(void) showunitybuttontouched: (UIButton *) Sender {NSLog (@ "[ViewcontrolLer button Touch] ");
[(Appdelegate *) [uiapplication sharedapplication].delegate Showunitywindow];
}-(void) didreceivememorywarning {[Super didreceivememorywarning];
Dispose of any resources the can be recreated.
} @end
At last:
10.1 must use the real machine debugging, no real machine, no matter the build or how, will be reported similar to "referenced from" error.
10.2 Lazy People Example: Link: Http://pan.baidu.com/s/1gfoidJP Password: SMJP