Class TransformExtensions
Extension methods for Unity's Transform class
Inherited Members
Namespace: Microsoft.MixedReality.Toolkit
Assembly: cs.temp.dll.dll
Syntax
public static class TransformExtensions
Methods
EnumerateAncestors(Transform, Boolean)
Enumerates the ancestors of the specified transform.
Declaration
public static IEnumerable<Transform> EnumerateAncestors(this Transform startTransform, bool includeSelf)
Parameters
| Type | Name | Description |
|---|---|---|
| Transform | startTransform | Transform for which ancestors must be returned. |
| Boolean | includeSelf | Indicates whether the specified transform should be included. |
Returns
| Type | Description |
|---|---|
| IEnumerable<Transform> | An enumeration of all ancestor transforms of the specified start transform. |
EnumerateHierarchy(Transform)
Enumerates all children in the hierarchy starting at the root object.
Declaration
public static IEnumerable<Transform> EnumerateHierarchy(this Transform root)
Parameters
| Type | Name | Description |
|---|---|---|
| Transform | root | Start point of the traversion set |
Returns
| Type | Description |
|---|---|
| IEnumerable<Transform> |
EnumerateHierarchy(Transform, ICollection<Transform>)
Enumerates all children in the hierarchy starting at the root object except for the branches in ignore.
Declaration
public static IEnumerable<Transform> EnumerateHierarchy(this Transform root, ICollection<Transform> ignore)
Parameters
| Type | Name | Description |
|---|---|---|
| Transform | root | Start point of the traversion set |
| ICollection<Transform> | ignore | Transforms and all its children to be ignored |
Returns
| Type | Description |
|---|---|
| IEnumerable<Transform> |
FindAncestorComponent<T>(Transform, Boolean)
Find the first component of type T in the ancestors of the specified transform.
Declaration
public static T FindAncestorComponent<T>(this Transform startTransform, bool includeSelf = true)
where T : Component
Parameters
| Type | Name | Description |
|---|---|---|
| Transform | startTransform | Transform for which ancestors must be considered. |
| Boolean | includeSelf | Indicates whether the specified transform should be included. |
Returns
| Type | Description |
|---|---|
| T | The component of type |
Type Parameters
| Name | Description |
|---|---|
| T | Type of component to find. |
GetChildRecursive(Transform, String)
Walk hierarchy looking for named transform
Declaration
public static Transform GetChildRecursive(Transform t, string name)
Parameters
| Type | Name | Description |
|---|---|---|
| Transform | t | root transform to start searching from |
| String | name | name to look for |
Returns
| Type | Description |
|---|---|
| Transform | returns found transform or null if none found |
GetColliderBounds(Transform)
Calculates the bounds of all the colliders attached to this GameObject and all it's children
Declaration
public static Bounds GetColliderBounds(this Transform transform)
Parameters
| Type | Name | Description |
|---|---|---|
| Transform | transform | Transform of root GameObject the colliders are attached to |
Returns
| Type | Description |
|---|---|
| Bounds | The total bounds of all colliders attached to this GameObject. If no colliders attached, returns a bounds of center and extents 0 |
GetDepth(Transform)
Gets the hierarchical depth of the Transform from its root. Returns -1 if the transform is the root.
Declaration
public static int GetDepth(this Transform t)
Parameters
| Type | Name | Description |
|---|---|---|
| Transform | t | The transform to get the depth for. |
Returns
| Type | Description |
|---|---|
| Int32 |
GetFullPath(Transform, String, String)
An extension method that will get you the full path to an object.
Declaration
public static string GetFullPath(this Transform transform, string delimiter = ".", string prefix = "/")
Parameters
| Type | Name | Description |
|---|---|---|
| Transform | transform | The transform you wish a full path to. |
| String | delimiter | The delimiter with which each object is delimited in the string. |
| String | prefix | Prefix with which the full path to the object should start. |
Returns
| Type | Description |
|---|---|
| String | A delimited string that is the full path to the game object in the hierarchy. |
InverseTransformSize(Transform, Vector3)
Transforms the size from world to local.
Declaration
public static Vector3 InverseTransformSize(this Transform transform, Vector3 worldSize)
Parameters
| Type | Name | Description |
|---|---|---|
| Transform | transform | The transform. |
| Vector3 | worldSize | The world size |
Returns
| Type | Description |
|---|---|
| Vector3 | World size. |
IsParentOrChildOf(Transform, Transform)
Checks if the provided transforms are child/parent related.
Declaration
public static bool IsParentOrChildOf(this Transform transform1, Transform transform2)
Parameters
| Type | Name | Description |
|---|---|---|
| Transform | transform1 | |
| Transform | transform2 |
Returns
| Type | Description |
|---|---|
| Boolean | True if either transform is the parent of the other or if they are the same |
TransformSize(Transform, Vector3)
Transforms the size from local to world.
Declaration
public static Vector3 TransformSize(this Transform transform, Vector3 localSize)
Parameters
| Type | Name | Description |
|---|---|---|
| Transform | transform | The transform. |
| Vector3 | localSize | The local size. |
Returns
| Type | Description |
|---|---|
| Vector3 | World size. |
TryGetDepth(Transform, Transform, ref Int32)
Tries to get the hierarchical depth of the Transform from the specified parent. This method is recursive.
Declaration
public static bool TryGetDepth(Transform target, Transform parent, ref int depth)
Parameters
| Type | Name | Description |
|---|---|---|
| Transform | target | The transform to get the depth for |
| Transform | parent | The starting transform to look for the target transform in |
| Int32 | depth | The depth of the target transform |
Returns
| Type | Description |
|---|---|
| Boolean | 'true' if the depth could be retrieved, or 'false' because the transform is a root transform. |