/// <summary> /// 取得节点下的所有T组件,存到List中 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="trans"></param> /// <param name="result"></param> /// <param name="includeInActive"></param> public static void GetComponentsInChildren <T>(Transform trans, List <T> result, bool includeInActive = false) { T[] components = trans.GetComponents <T>(); for (int i = 0; i < components.Length; i++) { result.Add(components[i]); } for (int j = 0; j < trans.childCount; j++) { Transform child = trans.GetChild(j); if (includeInActive || child.gameObject.activeSelf) { UnityTool.GetComponentsInChildren <T>(child, result, includeInActive); } } }