Class GameObjectExtensions
Extension methods for Unity's GameObject class
Inherited Members
Namespace: Microsoft.MixedReality.Toolkit
Assembly: cs.temp.dll.dll
Syntax
public static class GameObjectExtensions
Methods
ApplyLayerCacheRecursively(GameObject, Dictionary<GameObject, Int32>)
Reapplies previously cached hierarchy layers
Declaration
public static void ApplyLayerCacheRecursively(this GameObject root, Dictionary<GameObject, int> cache)
Parameters
Type | Name | Description |
---|---|---|
GameObject | root | Start point of the traverse |
Dictionary<GameObject, Int32> | cache | The previously set layer for each object |
ApplyToHierarchy(GameObject, Action<GameObject>)
Apply the specified delegate to all objects in the hierarchy under a specified game object.
Declaration
public static void ApplyToHierarchy(this GameObject root, Action<GameObject> action)
Parameters
Type | Name | Description |
---|---|---|
GameObject | root | Root game object of the hierarchy. |
Action<GameObject> | action | Delegate to apply. |
DestroyGameObject(GameObject, Single)
Destroys gameobject appropriately depending if in edit or playmode
Declaration
public static void DestroyGameObject(GameObject gameObject, float t = 0F)
Parameters
Type | Name | Description |
---|---|---|
GameObject | gameObject | gameobject to destroy |
Single | t | time in seconds at which to destroy GameObject if applicable |
FindAncestorComponent<T>(GameObject, Boolean)
Find the first component of type T
in the ancestors of the specified game object.
Declaration
public static T FindAncestorComponent<T>(this GameObject gameObject, bool includeSelf = true)
where T : Component
Parameters
Type | Name | Description |
---|---|---|
GameObject | gameObject | Game object for which ancestors must be considered. |
Boolean | includeSelf | Indicates whether the specified game object should be included. |
Returns
Type | Description |
---|---|
T | The component of type |
Type Parameters
Name | Description |
---|---|
T | Type of component to find. |
ForEachComponent<T>(GameObject, Action<T>)
Perform an action on every component of type T that is on this GameObject
Declaration
public static void ForEachComponent<T>(this GameObject gameObject, Action<T> action)
Parameters
Type | Name | Description |
---|---|---|
GameObject | gameObject | this gameObject |
Action<T> | action | Action to perform. |
Type Parameters
Name | Description |
---|---|
T | Component Type |
IsInLayerMask(GameObject, LayerMask)
Determines whether or not a game object's layer is included in the specified layer mask.
Declaration
public static bool IsInLayerMask(this GameObject gameObject, LayerMask layerMask)
Parameters
Type | Name | Description |
---|---|---|
GameObject | gameObject | The game object whose layer to test. |
LayerMask | layerMask | The layer mask to test against. |
Returns
Type | Description |
---|---|
Boolean | True if |
SetChildrenActive(GameObject, Boolean)
Declaration
public static void SetChildrenActive(this GameObject root, bool isActive)
Parameters
Type | Name | Description |
---|---|---|
GameObject | root | |
Boolean | isActive |
SetLayerRecursively(GameObject, Int32)
Set the layer to the given object and the full hierarchy below it.
Declaration
public static void SetLayerRecursively(this GameObject root, int layer)
Parameters
Type | Name | Description |
---|---|---|
GameObject | root | Start point of the traverse |
Int32 | layer | The layer to apply |
SetLayerRecursively(GameObject, Int32, out Dictionary<GameObject, Int32>)
Set the layer to the given object and the full hierarchy below it and cache the previous layers in the out parameter.
Declaration
public static void SetLayerRecursively(this GameObject root, int layer, out Dictionary<GameObject, int> cache)
Parameters
Type | Name | Description |
---|---|---|
GameObject | root | Start point of the traverse |
Int32 | layer | The layer to apply |
Dictionary<GameObject, Int32> | cache | The previously set layer for each object |