Skip to content

Commit

Permalink
[Core] Optimize deep child search
Browse files Browse the repository at this point in the history
  • Loading branch information
Sauceke committed Nov 28, 2023
1 parent 45dbc91 commit cc92a62
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/LoveMachine.Core/Game/GameAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Transform>()
.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
{ }
Expand Down

1 comment on commit cc92a62

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Robot Results

✅ Passed ❌ Failed ⏭️ Skipped Total Pass %
10 0 0 10 100

Passed Tests

Name ⏱️ Duration Suite
Linear Command Count 0.036 s Secrossphere Demo Test Suite
Linear Command Timing 0.046 s Secrossphere Demo Test Suite
Linear Command Position 0.001 s Secrossphere Demo Test Suite
Linear Command Duration 0.003 s Secrossphere Demo Test Suite
Vibrate Command Count 0.019 s Secrossphere Demo Test Suite
Vibrate Command Timing 0.053 s Secrossphere Demo Test Suite
Rotate Command Count 0.025 s Secrossphere Demo Test Suite
Rotate Command Timing 0.015 s Secrossphere Demo Test Suite
Battery Level 0.001 s Secrossphere Demo Test Suite
Kill Switch 6.012 s Secrossphere Demo Test Suite

Please sign in to comment.