HelloWorldSDKViewController.h:
#ifndef HelloWorldSDKViewController_h
#define HelloWorldSDKViewController_h
#import <Foundation/Foundation.h>
@interface HelloWorldSDKViewController : UIViewController{
}
@end
#endif
HelloWorldSDKViewController.m:
#include "HelloWorldSDKViewController.h"
@implementation HelloWorldSDKViewController
// 用static声明一个类的静态实例;
static HelloWorldSDKViewController *_sharedInstance = nil;
//使用类方法生成这个类唯一的实例
+(HelloWorldSDKViewController *)sharedInstance{
if (!_sharedInstance) {
_sharedInstance =[[self alloc]init];
}
return _sharedInstance;
}
-(void) viewDidLoad{
[super viewDidLoad];
self.view.backgroundColor = [UIColor whiteColor];
UIButton *btnBack = [UIButton buttonWithType:UIButtonTypeSystem];
btnBack.frame = CGRectMake(0.5f * self.view.bounds.size.width - 100, 300, 200, 40);
btnBack.layer.borderWidth = 1;
[btnBack setTitle:@"返回" forState:UIControlStateNormal];
[btnBack addTarget:self
action:@selector(BackToUnityScene:)
forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btnBack];
UILabel *title = [[UILabel alloc]init];
title.frame = CGRectMake(0.5f * self.view.bounds.size.width - 100, 100, 200, 40);
title.text = @"Hello World";
[self.view addSubview:title];
}
-(void) ShowHelloWorld{
[GetAppController().rootViewController presentViewController:_sharedInstance
animated:true
completion:nil];
}
-(void) BackToUnityScene:(id)sender {
NSLog(@"[HelloWorldSDK] Back to unity scene");
[GetAppController().rootViewController dismissViewControllerAnimated:true completion:nil];
}
@end