Created
February 10, 2015 10:45
-
-
Save leeprobert/3af816a70ca8b1dd1b9b to your computer and use it in GitHub Desktop.
UnityAppController subclass
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// CoolUnitySceneViewController.m | |
// Unity-iPhone | |
// | |
// Created by Frederik Jacques on 06/08/14. | |
// | |
// | |
#import "CoolUnitySceneViewController.h" | |
#import "GoodByeViewController.h" | |
@interface CoolUnitySceneViewController () | |
@end | |
@implementation CoolUnitySceneViewController | |
#pragma mark - Lifecycle | |
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { | |
self = [super initWithNibName:nil bundle:nil]; | |
if (self) { | |
// Custom initialization | |
} | |
return self; | |
} | |
- (void)viewDidLoad { | |
[super viewDidLoad]; | |
// Do any additional setup after loading the view. | |
[self.view addSubview:GetAppController().unityView]; | |
UIButton *btnNext = [UIButton buttonWithType:UIButtonTypeRoundedRect]; | |
btnNext.backgroundColor = [UIColor whiteColor]; | |
[btnNext setTitle:@"Go to last scene" forState:UIControlStateNormal]; | |
btnNext.frame = CGRectMake(0, 0, 400, 44); | |
btnNext.center = CGPointMake(self.view.bounds.size.height / 3, self.view.bounds.size.width / 2); | |
[self.view addSubview:btnNext]; | |
UIButton *btnSwitch = [UIButton buttonWithType:UIButtonTypeRoundedRect]; | |
btnSwitch.backgroundColor = [UIColor whiteColor]; | |
[btnSwitch setTitle:@"Switch scenes" forState:UIControlStateNormal]; | |
btnSwitch.frame = CGRectMake(0, 0, 400, 44); | |
btnSwitch.center = CGPointMake(self.view.bounds.size.height / 2, self.view.bounds.size.width/2); | |
[self.view addSubview:btnSwitch]; | |
[btnNext addTarget:self action:@selector(goToLastScene:) forControlEvents:UIControlEventTouchUpInside]; | |
[btnSwitch addTarget:self action:@selector(switchScenesTapped:) forControlEvents:UIControlEventTouchUpInside]; | |
} | |
- (void)didReceiveMemoryWarning { | |
[super didReceiveMemoryWarning]; | |
// Dispose of any resources that can be recreated. | |
} | |
- (void)switchScenesTapped:(id)sender { | |
NSLog(@"[TNAppController] Switch scenes tapped"); | |
[self callUnityObject:"dummy" Method:"ChangeScene" Parameter:"scene2"]; | |
} | |
- (void)callUnityObject:(const char*)object Method:(const char*)method Parameter:(const char*)parameter { | |
UnitySendMessage(object, method, parameter); | |
} | |
#pragma mark - NSCopying | |
#pragma mark - Private methods | |
- (void)goToLastScene:(id)sender { | |
NSLog(@"[CoolUnitySceneVC] Go to the last scene"); | |
GoodByeViewController *goodByeVC = [[GoodByeViewController alloc] initWithNibName:nil bundle:nil]; | |
[self.navigationController pushViewController:goodByeVC animated:YES]; | |
} | |
#pragma mark - Public methods | |
#pragma mark - Custom Accessors | |
#pragma mark - Delegate methods | |
#pragma mark - Debug | |
- (NSString *)description { | |
return [NSString stringWithFormat:@"[CoolUnitySceneViewController]"]; | |
} | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <UIKit/UIKit.h> | |
#import "UnityAppController.h" | |
#import "HelloViewController.h" | |
#import "CoolUnitySceneViewController.h" | |
@interface TNAppController : UnityAppController | |
@property (nonatomic, strong) UINavigationController *navController; | |
- (void)createViewHierarchyImpl; | |
@end | |
@implementation TNAppController | |
- (void)createViewHierarchyImpl { | |
_rootController = [[UIViewController alloc] init]; | |
_rootView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; | |
_rootController.view = _rootView; | |
HelloViewController *helloVC = [[HelloViewController alloc] initWithNibName:nil bundle:nil]; | |
self.navController = [[UINavigationController alloc] initWithRootViewController:helloVC]; | |
[_rootView addSubview:self.navController.view]; | |
} | |
@end | |
IMPL_APP_CONTROLLER_SUBCLASS(TNAppController) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment