public static void ForeachGameObjectRecursively(GameObject root, System.Action <GameObject> func) { if (root == null || func == null) { return; } func(root); foreach (Transform t in root.transform) { XUtility.ForeachGameObjectRecursively(t.gameObject, func); } }
public static void SetLayerRecursively(GameObject root, string layerName) { int layer = LayerMask.NameToLayer(layerName); XUtility.ForeachGameObjectRecursively(root, go => go.layer = layer); }