[MenuItem("Util/PrintChildNode")]
public static void PrintChildNodeM()
{
GameObject obj = Selection.activeGameObject;
string str = "";
TransformSort(obj.transform, "", ref str);
Debug.LogWarning(str);
}
static void TransformSort(Transform transform, string gap, ref string str)
{
foreach (Transform item in transform)
{
var path = GetHierarchyRelation(item);
str += "\"" + path + "\", ";
TransformSort(item, gap + " ", ref str);
}
}
static string GetHierarchyRelation(Transform trans)
{
StringBuilder hierarchyStrBuilder = new StringBuilder();
hierarchyStrBuilder.Append(trans.name);
string separator = "/";
Transform currentTrans = trans;
while (currentTrans.parent != null)
{
hierarchyStrBuilder.Insert(0, separator);
hierarchyStrBuilder.Insert(0, currentTrans.parent.name);
currentTrans = currentTrans.parent;
}
string hierarchyStr = hierarchyStrBuilder.ToString();
return hierarchyStr;
}
unity 获取节点下所有子节点路径
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。