Archived
backup
This commit is contained in:
@@ -99,19 +99,42 @@ namespace XericLibrary.Runtime.MacroLibrary
|
||||
/// <returns></returns>
|
||||
public static IEnumerable<Transform> GetChildren(this Transform trans)
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
if(trans == null)
|
||||
throw new Exception("在准备获取所有子成员时,节点为空");
|
||||
#endif
|
||||
|
||||
for(int i = 0; i < trans.childCount; i++)
|
||||
{
|
||||
yield return trans.GetChild(i);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 递归获取一个变换节点下所有的子成员
|
||||
/// </summary>
|
||||
/// <param name="trans"></param>
|
||||
/// <param name="recursion">递归深度,1表示仅在第一子集中寻找,2表示在包含下一级在内的所有成员中寻找</param>
|
||||
/// <returns></returns>
|
||||
public static IEnumerable<Transform> GetChildrenRecursion(this Transform trans, int recursion = 1)
|
||||
{
|
||||
int newdepth = recursion - 1;
|
||||
foreach(var child in trans.GetChildren())
|
||||
{
|
||||
if(newdepth > 0)
|
||||
foreach(var item in child.GetChildrenRecursion(newdepth))
|
||||
yield return item;
|
||||
yield return child;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 在所有子成员中深度优先找到第一个组件;
|
||||
/// 注意这只会在子项中查找。
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="trans"></param>
|
||||
/// <param name="recursion">遍历深度,0表示仅在子集中寻找,1表示在子集中寻找,如果找不到的将在子集的子集中寻找,以此类推</param>
|
||||
/// <param name="recursion">遍历深度,1表示仅在子集中寻找,2表示在子集中寻找,如果找不到的将在子集的子集中寻找,以此类推</param>
|
||||
/// <returns></returns>
|
||||
public static IEnumerable<T> GetComponentsInRecursionChildren<T>(this Transform trans, int recursion = 1)
|
||||
where T : Component
|
||||
|
||||
Reference in New Issue
Block a user