5 using System.Collections.Generic;
15 [Obsolete(
"Use the more extensive TransformExtensions.GetFullPath instead.")]
18 return go.transform.GetFullPath(
"/",
"");
30 throw new ArgumentNullException(
"root",
"Root transform can't be null.");
33 foreach (var child
in root.transform.EnumerateHierarchy())
35 child.gameObject.layer = layer;
45 public static void SetLayerRecursively(
this GameObject root,
int layer, out Dictionary<GameObject, int> cache)
47 if (root == null) {
throw new ArgumentNullException(
"root"); }
49 cache =
new Dictionary<GameObject, int>();
51 foreach (var child
in root.transform.EnumerateHierarchy())
53 cache[child.gameObject] = child.gameObject.layer;
54 child.gameObject.layer = layer;
65 if (root == null) {
throw new ArgumentNullException(
"root"); }
66 if (cache == null) {
throw new ArgumentNullException(
"cache"); }
68 foreach (var child
in root.transform.EnumerateHierarchy())
71 if (!cache.TryGetValue(child.gameObject, out layer)) {
continue; }
72 child.gameObject.layer = layer;
73 cache.Remove(child.gameObject);
84 if (child.transform.parent == null)
90 return GetParentRoot(child.transform.parent.gameObject);