public static void ResetRenderQueueRecursively(GameObject root) { XUtility.ForeachComponentRecursively <Renderer>(root, r => { foreach (Material m in r.materials) { if (m == null) { continue; } m.renderQueue = m.shader.renderQueue; } }); }
public static void ForeachComponentRecursively <T>(GameObject root, System.Action <T> func) where T : Component { if (root == null || func == null) { return; } T[] components = root.GetComponents <T>(); foreach (var c in components) { func(c); } foreach (Transform t in root.transform) { XUtility.ForeachComponentRecursively(t.gameObject, func); } }
public static void SetColliderEnabledRecursively(GameObject root, bool enabled) { XUtility.ForeachComponentRecursively <Collider>(root, c => c.enabled = enabled); }
public static void SetLayerRecursively <T>(GameObject root, string layerName) where T : Component { int layer = LayerMask.NameToLayer(layerName); XUtility.ForeachComponentRecursively <T>(root, c => c.gameObject.layer = layer); }