您的位置:首页 > 编程语言 > C#

U3D开发学习之路——递归算法

2016-08-29 22:36 281 查看
使用此方法类可以在一个父物体的下面递归去查找名字为childName的子物体

public static Transform GetChild(Transform parentTF, string childName)
{
//在子物体中根据名称查找
Transform childTF = parentTF.Find(childName);
if (childTF != null) return childTF;

int count = parentTF.childCount;
for (int i = 0; i < count; i++)
{//将问题转移给子物体
childTF = GetChild(parentTF.GetChild(i), childName);
if (childTF != null)
return childTF;
}

return null;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  递归 C#