unity 怎么unity获取子对象对象的rot

君,已阅读到文档的结尾了呢~~
unity3D技术之导出Unity场景的所有游戏对象信息技术,游戏,对象,Unity,游戏对象,场景的,导出对象,导出场景,场景导出
扫扫二维码,随身浏览文档
手机或平板扫扫即可继续访问
unity3D技术之导出Unity场景的所有游戏对象信息
举报该文档为侵权文档。
举报该文档含有违规或不良信息。
反馈该文档无法正常浏览。
举报该文档为重复文档。
推荐理由:
将文档分享至:
分享完整地址
文档地址:
粘贴到BBS或博客
flash地址:
支持嵌入FLASH地址的网站使用
html代码:
&embed src='/DocinViewer--144.swf' width='100%' height='600' type=application/x-shockwave-flash ALLOWFULLSCREEN='true' ALLOWSCRIPTACCESS='always'&&/embed&
450px*300px480px*400px650px*490px
支持嵌入HTML代码的网站使用
您的内容已经提交成功
您所提交的内容需要审核后才能发布,请您等待!
3秒自动关闭窗口你的浏览器禁用了JavaScript, 请开启后刷新浏览器获得更好的体验!
假如有A,B,C,B是A的父类,C又是B的父类,那么如果在A的脚本上用transform.parent返回的是不是B?用transform.root返回的是不是C?
首先,这个描述有点儿问题。transform.parent和root描述的并不是父子类(Class)关系,而是transform结构上的从属关系。
然后回答root和parent的区别:
1.假设你在场景中新建了个GameObject(假设名字叫RootObject),在上面挂了个脚本C。
2. 然后在这个物体下面又新建了个GameObject,假设叫ChildObject1_1,并在ChildObjectA上挂了脚本B
3. 然后又在ChildObject1_1下面新建了个GameObject,假设叫ChildObject2_1,并在ChildObjectB上挂了脚本A。
[*] parent表示(所在物体)上一级的变换(transform),root表示(所在物体)层次最高的变换。
那么对于A来说,transform.parent就是ChildObject1_1;而A的transform.root是RootObject。
对于B来说,transform.parent是RootObject;B的transform.root是RootObject
对于C来说,transform.parent是null;C的transform.root是RootObject(他自己)
不是继承关系,parent和root相当于是一个目录一样的关系。。。
root根目录
parent父目录
要回复问题请先或
浏览: 1424
关注: 3 人< has moved
< has moved . Please
if you are not redirected in 5 seconds获取工程中window上面的RootViewController
获取工程中window上面的RootViewController,你一般怎么获取工程中window上面的RootViewController。
第一种方法:
UIWindow *window = [UIApplication sharedApplication].keyW
UIViewController *rootViewController = window.rootViewC
第二种方法:
AppDelegate *appdelegate = (AppDelegate *)[UIApplication sharedApplication].
UIViewController *rootViewController1 = appdelegate.window.rootViewC
这两种写法,在平常的时候是没有区别的,但是这两种写法在有的时候就不一样了。
keyWindow这个属性是什么意思?
Paste_Image.png
个人理解的意思是,在windows数组中,最近时间调用makeKeyAndVisible方法的属性。
alertView的出现是因为,生成了一个新的window,加在了界面上面。这个时候获取到的keyWindow就是UIAlertControllerShimPresenterWindow。可以通过如下代码实验:
Appdelegate中的代码,设置RootViewController
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
self.window.backgroundColor = [UIColor whiteColor];
ViewController *view = [[ViewController alloc] init];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:view];
self.window.rootViewController =
[self.window makeKeyAndVisible];
return YES;
ViewController中的代码
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
UIButton *tempBtn = [UIButton buttonWithType:UIButtonTypeSystem];
tempBtn.frame = CGRectMake(100, 100, 100, 100);
tempBtn.backgroundColor = [UIColor cyanColor];
[tempBtn setTitle:@&测试1& forState:UIControlStateNormal];
[tempBtn addTarget:self action:@selector(clickBtn:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:tempBtn];
- (void)clickBtn:(UIButton *)sender{
// 创建一个测试的alertView
UIAlertView *alterView = [[UIAlertView alloc] initWithTitle:@&测试& message:@&测试& delegate:nil cancelButtonTitle:@&取消& otherButtonTitles:nil, nil];
[alterView show];
UIWindow *window1 = [UIApplication sharedApplication].keyW
AppDelegate *appdelegate = (AppDelegate *)[UIApplication sharedApplication].
UIWindow *window2 = appdelegate.
NSLog(@&\n\nwindow1 = %@
\n\nwindow2 = %@
\n\nwindow1.rootViewController = %@ \n\nwindow2.rootViewController = %@&,window1,window2,window1.rootViewController,window2.rootViewController);
打印结果:
window1 = &_UIAlertControllerShimPresenterWindow: 0x7fb4ab720c80; frame = (0 0; 375 667); opaque = NO; gestureRecognizers = ; layer = &
window2 = ; layer = &
window1.rootViewController =
window2.rootViewController =
结果明显不一样,其实我们一般情况下想获取的rootViewController是第二种,希望我们获取到在appdelegate中设置的appdelaget.window.rootViewController。
所以了建议获取rootViewController的时候还是采用
第二种方法:
AppDelegate *appdelegate = (AppDelegate *)[UIApplication sharedApplication].
UIViewController *rootViewController1 = appdelegate.window.rootViewC
其实,和alertView类似的,UIActionSheet也是这样的。
一般人说无所谓,但是如果在AlertView弹出的时候去获取RootViewController,并且对你认为获取正确的RootViewController做相关的操作,你会死的很惨。
还有就是建议:即时通过第二种方法获取到了RootViewController,在使用之前建议再判断一下获取到的类是不是就是自己想要的类型,更保险一些。
AppDelegate *appdelegate = (AppDelegate *)[UIApplication sharedApplication].
if ([appdelegate.window.rootViewController isKindOfClass:[&想要获取到的rootVC& class]] == YES) {
// 为所欲为
说的很有道理,今天在弹出alertView的时候就遇到了这个问题,获取的rootViewContraller不是之前认为的控制器了。

我要回帖

更多关于 unity 获取所有子对象 的文章

 

随机推荐