首页 > 其他分享 >unity 获取transform的所有子节点

unity 获取transform的所有子节点

时间:2022-10-20 16:44:59浏览次数:58  
标签:trans GetAllChild nextPath transform unity var rootTrans 节点 dropDownList

如下,路径存储在dropDownList内

 

 1         ValueDropdownList<string> dropDownList = new ValueDropdownList<string>();
 2 
 3         public ValueDropdownList<string> GetActorPaths()
 4         {
 5             if (actor == null) return null;
 6             dropDownList.Clear();
 7             var actorTrans = actor.transform;
 8             dropDownList.Add("root");
 9             GetAllChild(actorTrans, "root");
10             return dropDownList;
11         }
12 
13         public void GetAllChild(Transform rootTrans, string rootPath = "")
14         {
15             if (rootTrans.childCount == 0) return;
16             var count = rootTrans.childCount;
17 
18             for (int i = 0; i < count; i++)
19             {
20                 var nextPath = rootPath;
21                 var trans = rootTrans.GetChild(i);
22                 nextPath = rootPath + "/" + trans.name;
23                 if (trans.GetComponent<BaseActor>())
24                 {
25                     dropDownList.Add(nextPath);
26                 }
27 
28                 GetAllChild(trans, nextPath);
29             }
30         }

 

标签:trans,GetAllChild,nextPath,transform,unity,var,rootTrans,节点,dropDownList
From: https://www.cnblogs.com/sun-shadow/p/16810431.html

相关文章

  • Transformers Pipelines
    pipelines是使用模型进行推理的一种很好且简单的方法。这些pipelines是从库中抽象出大部分复杂代码的对象,提供了一个简单的API,专门用于多个任务,包括命名实体识别、屏蔽语......
  • 【k8s】本地部署单节点测试集群
    前言k8s本地部署方式常见的有kubeadmin,minikube,rke等等,但是这几个在国内网络环境下都不好使,经常就是镜像拉取不下来。经过几轮测试,发现kind是最容易部署的部署方式......
  • Unity Character Controller移动控制(第一人称)
    目录CharacterController组件1.移动2.重力和跳跃2.1重力2.2跳跃实现第一人称视角控制CharacterController组件官方文档:https://docs.unity.cn/cn/2019.4/Manual/c......
  • 29. unity代码种树之删除树
    从treeinstance[]  treeInstances里删除树 然后设置terraindata.treeinstances=treeInstances 更新terraindata   再刷新地图数据  terrain.Flush();......
  • winXP immunity debugger 运行mona插件报错,解决方法
    报错内容报错内容提示如下:AttributeError:'list'objecthasnoattribute'update'找到问题所在为:File"C:\DocumentsandSettings\lrt\桌面\ImmunityDebugger-mast......
  • Jenkins 创建节点 java-web方式
                    登陆节点机器,下载jar包[root@bogon~]#wgethttp://192.168.228.147:8081/jnlpJars/agent.jar    ......
  • Transformer源码
    title:Transformer源码date:2022-10-0918:30:35mathjax:truetags:EncoderDecoderTransformerTransformer代码(源码Pytorch版本)从零解读(Pytorch版本)_哔哩......
  • Unity IO 加载图片
    ///<summary>///以IO方式进行加载///</summary>privatevoidLoadByIo(stringurl,GameObjectImageOBJ){//创建文件读取流FileStream......
  • unity3D mirror网络游戏开发笔记
    最近想开发一款多人在线网络游戏,使用unity3d的mirror插件可以提高开发效率,并且该插件免费。但是由于使用插件开发效率太低,经过研究,ummorpg开发模板是居于该插件开发而来,使......
  • C#与unity学习
    C#与unity学习unity中产创建c#文件在unity中新建project,为方便管理可以在assets文件内创建scripts文件夹,将所有的c#文件集中在此文件夹中管理。在vsstudio中创建c#​ ......