Skip to content

Commit

Permalink
GameObject: fix getComponentsInChildren() method
Browse files Browse the repository at this point in the history
  • Loading branch information
capdevon committed Sep 4, 2023
1 parent eebf7e7 commit 18d2d27
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions game/src/main/java/com/capdevon/engine/GameObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,20 +88,23 @@ public static <T extends Control> T getComponent(Spatial subtree, Class<T> clazz
/**
* Returns all components of Type type in the GameObject or any of its
* children using depth first search. Works recursively.
*
*
* @param <T>
* @param subtree
* @param clazz
* @param type
* @return
*/
public static <T extends Control> List<T> getComponentsInChildren(Spatial subtree, Class<T> clazz) {
List<T> lst = new ArrayList<>(5);
subtree.breadthFirstTraversal(new SceneGraphVisitor() {
@SuppressWarnings("unchecked")
public static <T extends Control> List<T> getComponentsInChildren(Spatial subtree, Class<T> type) {
List<T> lst = new ArrayList<>(3);
subtree.depthFirstTraversal(new SceneGraphVisitor() {
@Override
public void visit(Spatial sp) {
T control = sp.getControl(clazz);
if (control != null) {
lst.add(control);
for (int i = 0; i < sp.getNumControls(); i++) {
T control = (T) sp.getControl(i);
if (type.isAssignableFrom(control.getClass())) {
lst.add(control);
}
}
}
});
Expand Down

0 comments on commit 18d2d27

Please sign in to comment.