diff --git a/src/LoveMachine.Core/Game/GameAdapter.cs b/src/LoveMachine.Core/Game/GameAdapter.cs index de30e6e..0700d04 100644 --- a/src/LoveMachine.Core/Game/GameAdapter.cs +++ b/src/LoveMachine.Core/Game/GameAdapter.cs @@ -260,14 +260,17 @@ protected static Transform FindBoneByPath(GameObject root, string path) => // If even that fails, search the entire game ?? GameObject.Find(path.Split('/').Last())?.transform; - protected static Transform[] FindDeepChildrenByPath(GameObject root, string path) => - root? + protected static Transform[] FindDeepChildrenByPath(GameObject root, string path) + { + var pathFragments = path.Split('/').Reverse().ToArray(); + return root? .GetComponentsInChildren() - .Where(child => GetPath(child).EndsWith("/" + path)) + .Where(child => HasPath(child, pathFragments)) .ToArray() ?? new Transform[] {}; - - private static string GetPath(Transform t) => - t == null ? "" : GetPath(t.parent) + "/" + t.name; + } + + private static bool HasPath(Transform tf, string[] path, int index = 0) => + index == path.Length || (tf?.name == path[index] && HasPath(tf?.parent, path, ++index)); public class HEventArgs : EventArgs { }