上海虹口龙之梦项目
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

52 lines
1.3 KiB

using System;
using UnityEngine;
public static class MyTools
{
public static void SetChildrenActive(this GameObject theGameObject, bool theActive)
{
foreach (Transform ChildTransform in theGameObject.transform)
{
ChildTransform.gameObject.SetActive(theActive);
}
}
public static void SetChildren<T>(this Transform theGameObject, Action<T> action)
{
foreach (Transform child in theGameObject)
{
T obj = child.GetComponent<T>();
action?.Invoke(obj);
}
}
/// <summary>
/// 递归查找子物体
/// </summary>
/// <param name="tr"></param>
/// <param name="childName"></param>
/// <returns></returns>
public static Transform FindChildren(Transform tr, string childName)
{
for (int i = 0; i < tr.childCount; i++)
{
if (tr.GetChild(i).name == childName)
{
Transform t = tr.GetChild(i);
if (t != null)
{
return t;
}
}
else
{
Transform t = FindChildren(tr.GetChild(i), childName);
if (t != null)
{
return t;
}
}
}
return null;
}
}