Read an read and read many times, test and erros many times, i finally do! Touch a UIButton and open or do whatever you imagine with it.
I will share here for those who need a more complete code.
Getting Started:
You need to create your own main file .h and .m to be "overruled" the Unity automatically:
mainAppController.h
#import "UnityAppController.h" #import "UI/UnityView.h" #import "iPhone_View.h" @interface mainAppController : UnityAppController { UnityAppController *_unityAppController; } - (void)createViewHierarchyImpl; @end
You have to import this H headers to controll Unity stuffs.
mainAppController.m
#import "mainAppController.h" @implementation mainAppController -(void)createViewHierarchyImpl { if(_unityAppController == nil) { _unityAppController = [[UnityAppController alloc] init]; NSLog(@"Unity Controller was set NICE!!!!"); } UIStoryboard *storyBoard; if ( UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad ) { storyBoard = [UIStoryboard storyboardWithName:@"iPadMain" bundle:nil]; } else { storyBoard = [UIStoryboard storyboardWithName:@"iPhoneMain" bundle:nil]; } UIViewController *mainVC = [storyBoard instantiateInitialViewController]; self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; self.window.rootViewController = mainVC; _rootController = [self.window rootViewController]; //_rootController.wantsFullScreenLayout = TRUE; _rootController.edgesForExtendedLayout = TRUE; _rootView = _rootController.view; [self.window makeKeyAndVisible]; } @end IMPL_APP_CONTROLLER_SUBCLASS(mainAppController) //THIS IS VERY IMPORTANT!!!
This last line is the Unity which will "read" and use.
So, see, I used the storyboard, so I have more control over the navigation visually. But you can use whatever you want.
In another any UIViewController, I'll call the Unity, as follows:
ShowARViewController.h
#import <UIKit/UIKit.h> #import "UnityAppController.h" #import "UI/UnityView.h" #import "iPhone_View.h" @interface ShowARViewController : UIViewController { UnityAppController *unityController; IBOutlet UIView *viewToUnity; // This is linked on Storyboard } @end
ShowARViewController.m
#import "ShowARViewController.h" @interface ShowARViewController () @end @implementation ShowARViewController - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { // Custom initialization } return self; } - (void)viewDidLoad { [super viewDidLoad]; unityController = (UnityAppController*)[[UIApplication sharedApplication] delegate]; [viewToUnity addSubview:unityController.unityView]; } // more methods and codes... @end
See, so I can have more control of Unity that I added in UIView and I can do what I want, for example, add a button above this view.
I hope I have helped really. If you have any questions or suggestions to make this code better, feel free to write me.
Regards