Unity iOS - Launch Native Window Instead of Unity

Hello,

When you build your Unity Application for iOS - it builds an Xcode project, in which the Unity app runs ontop of xcode. Because of this, I want to know if its possible to build a page natively within the Unity-Xcode project with a button, then when pressed will then launch the unity application:

15301-ss.png

Forgive my lack of understanding in the matter, but I imagine there would be a file within the Unity-Xcode that controls which files to launch during startup (in this case, its all the Unity files). Could I not modify this file, so it will only launch a ‘View’, with a button. Then when the button is pressed - to launch the Unity files, etc.

Thanks, Ollie.

If you are running Unity 4.2, then you can simply subclass the UnityAppController and assign the UnityView property to the UIView of your choosing. You just have to be sure to have the following at the bottom of your implementing class:

IMPL_APP_CONTROLLER_SUBCLASS(MyAppController)

Then, make sure you override the createViewHierarchyImpl function. For example:

- (void)createViewHierarchyImpl
{
    SomeViewController *someVC = [[SomeViewController alloc] initWithNibName:@"SomeViewController" bundle:nil];
    _rootController = someVC;
    _rootView       = someVC.view;
}

You really shouldn’t have to change the main.mm class at all.

HTH.

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.

I think this thread will be useful for you. I’m also having the same requirement. Finally found this.
http://forum.unity3d.com/threads/191971-Unity-AppController-subclassing