Skip to content

Commit

Permalink
com.utilities.extensions 1.1.17 (#25)
Browse files Browse the repository at this point in the history
- added Transform.FindChildRecursive
  • Loading branch information
StephenHodgson authored Dec 25, 2024
1 parent 4c73832 commit 55c35bd
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
19 changes: 19 additions & 0 deletions Runtime/Extensions/TransformExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -464,5 +464,24 @@ public static void ScaleAround(this Transform target, Vector3 pivot, Vector3 new
target.localScale = newScale;
target.localPosition = finalPosition;
}

/// <summary>
/// Find a child transform with the specified name.
/// </summary>
/// <param name="parent">The parent to start search from.</param>
/// <param name="name">The name of the transform to find.</param>
/// <returns><see cref="Transform"/> that matches <see cref="name"/> or null.</returns>
public static Transform FindChildRecursive(this Transform parent, string name)
{
for (int i = 0; i < parent.childCount; i++)
{
var child = parent.GetChild(i);
if (child.name.Contains(name)) { return child; }
var result = child.FindChildRecursive(name);
if (result != null) { return result; }
}

return null;
}
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"displayName": "Utilities.Extensions",
"description": "Common extensions for Unity types (UPM)",
"keywords": [],
"version": "1.1.16",
"version": "1.1.17",
"unity": "2021.3",
"documentationUrl": "https://github.com/RageAgainstThePixel/com.utilities.extensions#documentation",
"changelogUrl": "https://github.com/RageAgainstThePixel/com.utilities.extensions/releases",
Expand Down

0 comments on commit 55c35bd

Please sign in to comment.