This is a pretty complicated question. It’s possible, but instead of wording in the sense that you’re “launching unity,” you’re actually just adding the UIViewcontroller exposed through the UnityAppController.h and UnityAppController.mm files.
As you can see from the aforementioned XCode files:
- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions
{
printf_console("-> applicationDidFinishLaunching()
");
// get local notification
if (&UIApplicationLaunchOptionsLocalNotificationKey != nil)
{
UILocalNotification *notification = [launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey];
if (notification)
UnitySendLocalNotification(notification);
}
// get remote notification
if (&UIApplicationLaunchOptionsRemoteNotificationKey != nil)
{
NSDictionary *notification = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
if (notification)
UnitySendRemoteNotification(notification);
}
if ([UIDevice currentDevice].generatesDeviceOrientationNotifications == NO)
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[DisplayManager Initialize];
_mainDisplay = [[DisplayManager Instance] mainDisplay];
[_mainDisplay createView:YES showRightAway:NO];
[KeyboardDelegate Initialize];
CreateViewHierarchy();
[self performSelector:@selector(startUnity:) withObject:application afterDelay:0];
return NO;
}
is where Unity is setup within the context of an iOS application. The way that I have done it, is to make a separate AppDelegate, subclass it from UnityAppController, and set the name of the AppDelegate accordingly in the main.mm file generated by Unity after build to XCode:
#import <UIKit/UIKit.h>
#include "RegisterClasses.h"
#include "RegisterMonoModules.h"
// 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;
bool UnityParseCommandLine(int argc, char *argv[]);
void UnityInitTrampoline();
// WARNING: this MUST be c decl (NSString ctor will be called after +load, so we cant really change its value)
const char* AppControllerClassName = "YourAppDelegateClassNameHere";
int main(int argc, char *argv[])
{
NSAutoreleasePool* pool = [NSAutoreleasePool new];
UnityInitTrampoline();
if(!UnityParseCommandLine(argc, argv))
return -1;
RegisterMonoModules();
NSLog(@"-> registered mono modules %p
", &constsection);
UIApplicationMain(argc, argv, nil, [NSString stringWithUTF8String:AppControllerClassName]);
[pool release];
return 0;
}
That should get you started.
After this setup is done, you’re basically forwarding Unity’s view controller into a completely new AppDelegate class, and thus, a basically fresh UIKit application. You set your own rootViewController and the rootView of the shared application’s window, and everything after that is just like regular old Cocoa Touch coding.