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(this Transform theGameObject, Action action) { foreach (Transform child in theGameObject) { T obj = child.GetComponent(); action?.Invoke(obj); } } /// /// 递归查找子物体 /// /// /// /// 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; } }