当前位置:   article > 正文

unity // *** 清空子节点_unity 删除子节点

unity 删除子节点
  1.         /// <summary>
  2.         /// // *** 清空子节点
  3.         /// </summary>
  4.         public static void ClearChildren(this Transform _tra)
  5.         {
  6.             int childcount = _tra.childCount;
  7.             for (int i = 0; i < childcount; i++)
  8.             {
  9.                 GameObject.DestroyImmediate(_tra.GetChild(0).gameObject);
  10.             }
  11.         }
  1. /// <summary>
  2. /// // *** 清空可见子节点
  3. /// </summary>
  4. public static void ClearActiveChildren(this Transform _tra)
  5. {
  6. int childcount = _tra.childCount;
  7. int tempindex = 0;
  8. for (int i = 0; i < childcount; i++)
  9. {
  10. if (_tra.GetChild(tempindex).gameObject.activeSelf)
  11. {
  12. GameObject.DestroyImmediate(_tra.GetChild(tempindex).gameObject);
  13. }
  14. else
  15. {
  16. tempindex++;
  17. }
  18. }
  19. }

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/知新_RL/article/detail/332918
推荐阅读
相关标签
  

闽ICP备14008679号