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 |
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. |
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 |
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 |
ExportOBJAsync(GameObject, String, Boolean)
Export mesh data of current GameObject, and children if enabled, to file provided in OBJ format
Declaration
public static Task ExportOBJAsync(this GameObject root, string filePath, bool includeChildren = true)
Parameters
Type | Name | Description |
---|---|---|
GameObject | root | |
String | filePath | |
Boolean | includeChildren |
Returns
Type | Description |
---|---|
Task |
ExportOBJAsync(GameObject, String, Boolean)
Export mesh data of current GameObject, and children if enabled, to file provided in OBJ format
Declaration
public static Task ExportOBJAsync(this GameObject root, string filePath, bool includeChildren = true)
Parameters
Type | Name | Description |
---|---|---|
GameObject | root | |
String | filePath | |
Boolean | includeChildren |
Returns
Type | Description |
---|---|
Task |
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. |
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 |
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 |
IsComponentRequired<T>(GameObject, out List<Type>)
Checks if any MonoBehaviour on the given GameObject is using the RequireComponentAttribute requiring type T
Declaration
public static bool IsComponentRequired<T>(this GameObject gameObject, out List<Type> requiringTypes)
where T : Component
Parameters
Type | Name | Description |
---|---|---|
GameObject | gameObject | the GameObject requiring the component |
List<Type> | requiringTypes | A list of types that do require the component in question |
Returns
Type | Description |
---|---|
Boolean | true if |
Type Parameters
Name | Description |
---|---|
T | The potentially required component |
Remarks
Only functions when called within a UNITY_EDITOR context. Outside of UNITY_EDITOR, always returns false
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 |
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)
Set all GameObject children active or inactive based on argument
Declaration
public static void SetChildrenActive(this GameObject root, bool isActive)
Parameters
Type | Name | Description |
---|---|---|
GameObject | root | GameObject parent to traverse from |
Boolean | isActive | Indicates whether children GameObjects should be active or not |
Remarks
Does not call SetActive on the top level GameObject, only its children
SetChildrenActive(GameObject, Boolean)
Set all GameObject children active or inactive based on argument
Declaration
public static void SetChildrenActive(this GameObject root, bool isActive)
Parameters
Type | Name | Description |
---|---|---|
GameObject | root | GameObject parent to traverse from |
Boolean | isActive | Indicates whether children GameObjects should be active or not |
Remarks
Does not call SetActive on the top level GameObject, only its children
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)
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 |
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 |