using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public static class Tools {
/// <summary>
/// 通过递归调用,实现在root中递归查找名字等于name的子物体
/// </summary>
/// <param name="root"></param>
/// <param name="name"></param>
/// <returns></returns>
public static Transform FindRecursively(this Transform root,string name)
{
if (root.name == name) { return root; }
foreach (Transform child in root)
{
Transform t = FindRecursively(child, name);
if (t!=null)
{
return t;
}
}
return null;
}
public static T FindRecursively<T>(this Transform root, string name)where T : MonoBehaviour
{
Transform t = root.transform.FindRecursively(name);
if (t==null)
{
Debug.LogErr
对unity的find方法的扩展,递归查找子物体上的组件
最新推荐文章于 2022-07-30 23:06:50 发布