找出所有的控件子项,包括隐藏的GameObject

7 篇文章 0 订阅

今天正好碰见要写一个查找所有UISprite,包括active=fales的情况

同理也可以找出所有的GameObject啦~~~

贴上代码

UISprite[] chidItem = parentObj.transform.GetComponentsInChildren<UISprite>(true);
Debug.Log("查出所有子项 : " + chidItem.Length + " 个" );
UISprite[] chidItem2 = parentObj.transform.GetComponentsInChildren<UISprite>();
Debug.Log("查出所有子项 : " + chidItem2.Length + " 个" + );

我输出的  Log:

查出所有子项 : 90 个
UnityEngine.Debug:Log(Object)
查出所有子项 : 24 个
UnityEngine.Debug:Log(Object)


这两个有什么区别呢....

我们来看看API:

public Component[] GetComponentsInChildren(Type t,bool includeInactive = false);

Should Components on inactive GameObjects be included in the found set? includeInactive decides which children of the GameObject will be searched. The GameObject that you call GetComponentsInChildren on is always searched regardless.

来自有道的翻译是这样的     :

非活动的游戏对象的组件是否应该包含在已找到的集合中?includeInactive决定对游戏对象的哪个子对象进行搜索。

无论如何,您调用GetComponentsInChildren的GameObject总是被搜索。


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值