Class ComponentUtilities
Utility functions regarding MonoBehaviour components
Inheritance
object
ComponentUtilities
Namespace: i5.Toolkit.Core.Utilities
Assembly: cs.temp.dll.dll
Syntax
public static class ComponentUtilities
Methods
EnsureComponentReference<T>(GameObject, ref T, bool)
Makes sure that the given component reference is set to a component if the reference is not yet set
Declaration
public static void EnsureComponentReference<T>(GameObject gameObject, ref T componentReference, bool addComponent) where T : Component
Parameters
Type | Name | Description |
---|---|---|
GameObject | gameObject | The gameobject which contains the component |
T | componentReference | The reference to the component |
bool | addComponent | If true, the component will be added if it does not exist; otherwise the componentReference may still be null after this call if the component does not exist |
Type Parameters
Name | Description |
---|---|
T | The type of component to search for |
GetOrAddComponent<T>(GameObject)
Tries to get the reference to a component and adds the component if it does not exist
Declaration
public static T GetOrAddComponent<T>(GameObject gameObject) where T : Component
Parameters
Type | Name | Description |
---|---|---|
GameObject | gameObject | The gameobject on which the component should be searched or added |
Returns
Type | Description |
---|---|
T | The reference to the component which already existed or was just created |
Type Parameters
Name | Description |
---|---|
T | The type of component to search for |