Skip to content

Commit

Permalink
GetChildren
Browse files Browse the repository at this point in the history
  • Loading branch information
MegaPiggy committed Sep 14, 2024
1 parent bb56f5b commit dc9e284
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions Winch/Util/WinchExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2138,6 +2138,20 @@ public static Transform FindChildWithExactName(this Transform parent, string nam
return null;
}

public static Transform[] GetChildren(this Transform parent, bool dive = false)
{
List<Transform> childList = new List<Transform>();
int count = parent.childCount;
for (int i = 0; i < count; i++)
{
Transform child = parent.GetChild(i);
childList.Add(child);
if (child.childCount > 0 && dive)
childList.AddRange(child.GetChildren(dive));
}
return childList.ToArray();
}

public static void DestroyAllComponents<T>(this GameObject obj) where T : Component
{
foreach (var component in obj.GetComponents<T>())
Expand Down

0 comments on commit dc9e284

Please sign in to comment.