5 using System.Collections.Generic;
20 public static string GetFullPath(
this Transform transform,
string delimiter =
".",
string prefix =
"/")
22 StringBuilder stringBuilder =
new StringBuilder();
23 GetFullPath(stringBuilder, transform, delimiter, prefix);
24 return stringBuilder.ToString();
27 private static void GetFullPath(StringBuilder stringBuilder, Transform transform,
string delimiter,
string prefix)
29 if (transform.parent == null)
31 stringBuilder.Append(prefix);
35 GetFullPath(stringBuilder, transform.parent, delimiter, prefix);
36 stringBuilder.Append(delimiter);
38 stringBuilder.Append(transform.name);
47 if (root == null) {
throw new ArgumentNullException(
"root"); }
48 return root.EnumerateHierarchyCore(
new List<Transform>(0));
56 public static IEnumerable<Transform>
EnumerateHierarchy(
this Transform root, ICollection<Transform> ignore)
58 if (root == null) {
throw new ArgumentNullException(
"root"); }
61 throw new ArgumentNullException(
"ignore",
"Ignore collection can't be null, use EnumerateHierarchy(root) instead.");
63 return root.EnumerateHierarchyCore(ignore);
71 private static IEnumerable<Transform> EnumerateHierarchyCore(
this Transform root, ICollection<Transform> ignore)
73 var transformQueue =
new Queue<Transform>();
74 transformQueue.Enqueue(root);
76 while (transformQueue.Count > 0)
78 var parentTransform = transformQueue.Dequeue();
80 if (!parentTransform || ignore.Contains(parentTransform)) {
continue; }
82 for (var i = 0; i < parentTransform.childCount; i++)
84 transformQueue.Enqueue(parentTransform.GetChild(i));
87 yield
return parentTransform;
99 Collider[] colliders = transform.GetComponentsInChildren<Collider>();
100 if (colliders.Length == 0) {
return new Bounds(); }
102 Bounds bounds = colliders[0].bounds;
103 for (
int i = 1; i < colliders.Length; i++)
105 bounds.Encapsulate(colliders[i].bounds);
116 return transform1.IsChildOf(transform2) || transform2.IsChildOf(transform1);