Skip to content

Commit

Permalink
Merge branch 'master' into docs
Browse files Browse the repository at this point in the history
  • Loading branch information
LeeTwentyThree committed Jun 20, 2023
2 parents 3e13c40 + 3043c71 commit 860f3ee
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion Nautilus/Extensions/GameObjectExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Linq;
using System.Linq;
using System.Reflection;
using HarmonyLib;
using Nautilus.Utility;
Expand Down Expand Up @@ -100,4 +100,32 @@ public static TNewComponent EnsureAndCopyComponent<TNewComponent, TCopiedCompone

return obj.EnsureComponent<TNewComponent>().CopyComponent(origComponent);
}

/// <summary>
/// Searches the hierarchy under this Transform recursively and returns a child Transform with the matching name if any is found.
/// </summary>
/// <param name="transform">The root object of the search.</param>
/// <param name="name">The name of the object that is being searched for.</param>
/// <returns></returns>
public static Transform SearchChild(this Transform transform, string name)
{
foreach (Transform child in transform)
{
if (child.gameObject.name == name)
return child;

var recursive = SearchChild(child, name);
if (recursive != null)
return recursive;
}
return null;
}

/// <summary>
/// Searches the hierarchy under this GameObject recursively and returns a child GameObject with the matching name if any is found.
/// </summary>
/// <param name="gameObject">The root object of the search.</param>
/// <param name="name">The name of the object that is being searched for.</param>
/// <returns></returns>
public static GameObject SearchChild(this GameObject gameObject, string name) => SearchChild(gameObject.transform, name).gameObject;
}

0 comments on commit 860f3ee

Please sign in to comment.