标签:style http color 使用 os io 文件 数据
今天和盆友们讨论IOS的高级界面与先把Move脚本的代码贴出来,这里面我写了4个方法分别处理这个箱子的旋转,这4个方法是由IOS上的代码向Unity发送消息后调用的,下面我会介绍具体操作的方法。
// Create a full-screen window _window = [[UIWindow alloc] initWithFrame:rect]; EAGLView* view = [[EAGLView alloc] initWithFrame:rect]; [_window addSubview:view]; MyView * myView = [[MyView alloc] init]; [_window addSubview:myView.view]; 贴出MyView的代码,写完发现忘释放内存了,呵呵,懒得改了,本章主要的介绍的不是这个哦。 // MyView.m // Unity-iPhone // // Created by 雨松MOMO on 11-11-1. // Copyright 2011 __MyCompanyName__. All rights reserved. // #import "MyView.h" @implementation MyView // Implement viewDidLoad to do additional setup after loading the view, typically from a nib. - (void)viewDidLoad { [super viewDidLoad]; //创建label视图 UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 320, 40)]; //设置显示内容 label.text = @"雨松MOMO的程序世界"; //设置背景颜色 label.backgroundColor = [UIColor blueColor]; //设置文字颜色 label.textColor = [UIColor whiteColor]; //设置显示位置居中 label.textAlignment = UITextAlignmentCenter; //设置字体大小 label.font = [UIFont fontWithName:[[UIFont familyNames] objectAtIndex:10] size:20]; //创建按钮 UIButton *button0 = [UIButton buttonWithType:1]; //设置按钮范围 button0.frame = CGRectMake(0, 40, 100, 30); //设置按钮显示内容 [button0 setTitle:@"矩形左旋转" forState:UIControlStateNormal]; //设置按钮改变后 绑定响应方法 [button0 addTarget:self action:@selector(LeftButtonPressed) forControlEvents:UIControlEventTouchUpInside]; //创建按钮 UIButton *button1 = [UIButton buttonWithType:1]; //设置按钮范围 button1.frame = CGRectMake(0, 100, 100, 30); //设置按钮显示内容 [button1 setTitle:@"矩形右旋转" forState:UIControlStateNormal]; //设置按钮改变后 绑定响应方法 [button1 addTarget:self action:@selector(RightButtonPressed) forControlEvents:UIControlEventTouchUpInside]; //创建按钮 UIButton *button2 = [UIButton buttonWithType:1]; //设置按钮范围 button2.frame = CGRectMake(0, 160, 100, 30); //设置按钮显示内容 [button2 setTitle:@"矩形上旋转" forState:UIControlStateNormal]; //设置按钮改变后 绑定响应方法 [button2 addTarget:self action:@selector(UpButtonPressed) forControlEvents:UIControlEventTouchUpInside]; //创建按钮 UIButton *button3 = [UIButton buttonWithType:1]; //设置按钮范围 button3.frame = CGRectMake(0, 220, 100, 30); //设置按钮显示内容 [button3 setTitle:@"矩形下旋转" forState:UIControlStateNormal]; //设置按钮改变后 绑定响应方法 [button3 addTarget:self action:@selector(DownButtonPressed) forControlEvents:UIControlEventTouchUpInside]; //向view添加 [self.view addSubview:label]; [self.view addSubview:button0]; [self.view addSubview:button1]; [self.view addSubview:button2]; [self.view addSubview:button3]; } //向左按钮 -(void)LeftButtonPressed{ UnitySendMessage("Cube","MoveLeft",""); } //向右按钮 -(void)RightButtonPressed{ UnitySendMessage("Cube","MoveRight",""); } //向上按钮 -(void)UpButtonPressed{ UnitySendMessage("Cube","MoveUp",""); } //向下按钮 -(void)DownButtonPressed{ UnitySendMessage("Cube","MoveDown",""); } - (void)didReceiveMemoryWarning { // Releases the view if it doesn't have a superview. [super didReceiveMemoryWarning]; // Release any cached data, images, etc. that aren't in use. } - (void)viewDidUnload { [super viewDidUnload]; } - (void)dealloc { [super dealloc]; }
EAGLView 是Unity3D 背景的那个View, 下面我们添加一个我们自己写的View 覆盖在它上面。
// Create a full-screen window _window = [[UIWindow alloc] initWithFrame:rect]; EAGLView* view = [[EAGLView alloc] initWithFrame:rect]; [_window addSubview:view]; MyView * myView = [[MyView alloc] init]; [_window addSubview:myView.view]; 贴出MyView的代码,写完发现忘释放内存了,呵呵,懒得改了,本章主要的介绍的不是这个哦。 // MyView.m // Unity-iPhone // // Created by 雨松MOMO on 11-11-1. // Copyright 2011 __MyCompanyName__. All rights reserved. // #import "MyView.h" @implementation MyView // Implement viewDidLoad to do additional setup after loading the view, typically from a nib. - (void)viewDidLoad { [super viewDidLoad]; //创建label视图 UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 320, 40)]; //设置显示内容 label.text = @"雨松MOMO的程序世界"; //设置背景颜色 label.backgroundColor = [UIColor blueColor]; //设置文字颜色 label.textColor = [UIColor whiteColor]; //设置显示位置居中 label.textAlignment = UITextAlignmentCenter; //设置字体大小 label.font = [UIFont fontWithName:[[UIFont familyNames] objectAtIndex:10] size:20]; //创建按钮 UIButton *button0 = [UIButton buttonWithType:1]; //设置按钮范围 button0.frame = CGRectMake(0, 40, 100, 30); //设置按钮显示内容 [button0 setTitle:@"矩形左旋转" forState:UIControlStateNormal]; //设置按钮改变后 绑定响应方法 [button0 addTarget:self action:@selector(LeftButtonPressed) forControlEvents:UIControlEventTouchUpInside]; //创建按钮 UIButton *button1 = [UIButton buttonWithType:1]; //设置按钮范围 button1.frame = CGRectMake(0, 100, 100, 30); //设置按钮显示内容 [button1 setTitle:@"矩形右旋转" forState:UIControlStateNormal]; //设置按钮改变后 绑定响应方法 [button1 addTarget:self action:@selector(RightButtonPressed) forControlEvents:UIControlEventTouchUpInside]; //创建按钮 UIButton *button2 = [UIButton buttonWithType:1]; //设置按钮范围 button2.frame = CGRectMake(0, 160, 100, 30); //设置按钮显示内容 [button2 setTitle:@"矩形上旋转" forState:UIControlStateNormal]; //设置按钮改变后 绑定响应方法 [button2 addTarget:self action:@selector(UpButtonPressed) forControlEvents:UIControlEventTouchUpInside]; //创建按钮 UIButton *button3 = [UIButton buttonWithType:1]; //设置按钮范围 button3.frame = CGRectMake(0, 220, 100, 30); //设置按钮显示内容 [button3 setTitle:@"矩形下旋转" forState:UIControlStateNormal]; //设置按钮改变后 绑定响应方法 [button3 addTarget:self action:@selector(DownButtonPressed) forControlEvents:UIControlEventTouchUpInside]; //向view添加 [self.view addSubview:label]; [self.view addSubview:button0]; [self.view addSubview:button1]; [self.view addSubview:button2]; [self.view addSubview:button3]; } //向左按钮 -(void)LeftButtonPressed{ UnitySendMessage("Cube","MoveLeft",""); } //向右按钮 -(void)RightButtonPressed{ UnitySendMessage("Cube","MoveRight",""); } //向上按钮 -(void)UpButtonPressed{ UnitySendMessage("Cube","MoveUp",""); } //向下按钮 -(void)DownButtonPressed{ UnitySendMessage("Cube","MoveDown",""); } - (void)didReceiveMemoryWarning { // Releases the view if it doesn't have a superview. [super didReceiveMemoryWarning]; // Release any cached data, images, etc. that aren't in use. } - (void)viewDidUnload { [super viewDidUnload]; } - (void)dealloc { [super dealloc]; }
文章出自:http://www.unitymanual.com/thread-20376-1-1.html
Unity3D 研究院之IOS高级界面发送消息与Unity3D消息的接收,布布扣,bubuko.com
Unity3D 研究院之IOS高级界面发送消息与Unity3D消息的接收
标签:style http color 使用 os io 文件 数据
原文地址:http://blog.csdn.net/u013951435/article/details/38337351