Class ComponentExtensions
Extensions methods for the Unity Component class. This also includes some component-related extensions for the GameObject class.
Inherited Members
Namespace: Microsoft.MixedReality.Toolkit
Assembly: cs.temp.dll.dll
Syntax
public static class ComponentExtensions
Methods
EnsureComponent(GameObject, Type)
Ensure that a component of type exists on the game object. If it doesn't exist, creates it.
Declaration
public static Component EnsureComponent(this GameObject gameObject, Type component)
Parameters
Type | Name | Description |
---|---|---|
GameObject | gameObject | |
Type | component | A component on the game object for which a component of type should exist. |
Returns
Type | Description |
---|---|
Component | The component that was retrieved or created. |
EnsureComponent<T>(Component)
Ensure that a component of type T
exists on the game object.
If it doesn't exist, creates it.
Declaration
public static T EnsureComponent<T>(this Component component)
where T : Component
Parameters
Type | Name | Description |
---|---|---|
Component | component | A component on the game object for which a component of type |
Returns
Type | Description |
---|---|
T | The component that was retrieved or created. |
Type Parameters
Name | Description |
---|---|
T | Type of the component. |
EnsureComponent<T>(GameObject)
Ensure that a component of type T
exists on the game object.
If it doesn't exist, creates it.
Declaration
public static T EnsureComponent<T>(this GameObject gameObject)
where T : Component
Parameters
Type | Name | Description |
---|---|---|
GameObject | gameObject | Game object on which component should be. |
Returns
Type | Description |
---|---|
T | The component that was retrieved or created. |
Type Parameters
Name | Description |
---|---|
T | Type of the component. |
Remarks
This extension has to remain in this class as it is required by the EnsureComponent<T>(Component) method
FindAncestorComponent<T>(Component, Boolean)
Find the first component of type T
in the ancestors of the game object of the specified component.
Declaration
public static T FindAncestorComponent<T>(this Component component, bool includeSelf = true)
where T : Component
Parameters
Type | Name | Description |
---|---|---|
Component | component | Component for which its game object's 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. |