You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
1.0 KiB
31 lines
1.0 KiB
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public static class Utils {
|
|
public static GameObject FindRecursive(this GameObject go, string child) {
|
|
var foundChild = go.transform.Find(child);
|
|
if (foundChild != null) {
|
|
return foundChild.gameObject;
|
|
}else {
|
|
var found = false;
|
|
GameObject newChild = null;
|
|
foreach (Transform newGo in go.transform) {
|
|
if (newGo.childCount > 0)
|
|
newChild = newGo.gameObject.FindRecursive(child);
|
|
found = child == newChild?.name;
|
|
if (found)
|
|
break;
|
|
}
|
|
if (found)
|
|
return newChild;
|
|
else
|
|
return null;
|
|
}
|
|
}
|
|
|
|
public static Transform FindRecursive(this Transform transform, string child) {
|
|
var foundChild = transform.gameObject.FindRecursive(child);
|
|
return foundChild != null ? foundChild.transform : null;
|
|
}
|
|
}
|
|
|