ComponentExtensions.EnsureComponent Method

Definition

Overloads

EnsureComponent(GameObject, Type)

Ensure that a component of type exists on the game object. If it doesn't exist, creates it.

EnsureComponent<T>(Component)

Ensure that a component of type T exists on the game object. If it doesn't exist, creates it.

EnsureComponent<T>(GameObject)

Ensure that a component of type T exists on the game object. If it doesn't exist, creates it.

EnsureComponent(GameObject, Type)

Ensure that a component of type exists on the game object. If it doesn't exist, creates it.

C++
public:
[System::Runtime::CompilerServices::Extension]
 static UnityEngine::Component ^ EnsureComponent(UnityEngine::GameObject ^ gameObject, Type ^ component);

Parameters

gameObject
UnityEngine.GameObject
component
Type

A component on the game object for which a component of type should exist.

Returns

UnityEngine.Component

The component that was retrieved or created.

Applies to

MRTK2 Unity 2018 2.7.0 およびその他のバージョン
製品 バージョン
MRTK2 Unity 2018 2.5.0, 2.5.1, 2.5.2, 2.5.3, 2.5.4, 2.6.0, 2.7.0
MRTK2 Unity 2019 2.5.0, 2.5.1, 2.5.2, 2.5.3, 2.5.4, 2.6.0, 2.7.0, 2.8.0
MRTK2 Unity 2020 2.5.2, 2.5.3, 2.5.4, 2.6.0, 2.7.0, 2.8.0

EnsureComponent<T>(Component)

Ensure that a component of type T exists on the game object. If it doesn't exist, creates it.

C++
public:
generic <typename T>
 where T : UnityEngine::Component[System::Runtime::CompilerServices::Extension]
 static T EnsureComponent(UnityEngine::Component ^ component);

Type Parameters

T

Type of the component.

Parameters

component
UnityEngine.Component

A component on the game object for which a component of type T should exist.

Returns

T

The component that was retrieved or created.

Applies to

MRTK2 Unity 2018 2.7.0 およびその他のバージョン
製品 バージョン
MRTK2 Unity 2018 2.5.0, 2.5.1, 2.5.2, 2.5.3, 2.5.4, 2.6.0, 2.7.0
MRTK2 Unity 2019 2.5.0, 2.5.1, 2.5.2, 2.5.3, 2.5.4, 2.6.0, 2.7.0, 2.8.0
MRTK2 Unity 2020 2.5.2, 2.5.3, 2.5.4, 2.6.0, 2.7.0, 2.8.0

EnsureComponent<T>(GameObject)

Ensure that a component of type T exists on the game object. If it doesn't exist, creates it.

C++
public:
generic <typename T>
 where T : UnityEngine::Component[System::Runtime::CompilerServices::Extension]
 static T EnsureComponent(UnityEngine::GameObject ^ gameObject);

Type Parameters

T

Type of the component.

Parameters

gameObject
UnityEngine.GameObject

Game object on which component should be.

Returns

T

The component that was retrieved or created.

Remarks

This extension has to remain in this class as it is required by the EnsureComponent<T>(Component) method

Applies to

MRTK2 Unity 2018 2.7.0 およびその他のバージョン
製品 バージョン
MRTK2 Unity 2018 2.5.0, 2.5.1, 2.5.2, 2.5.3, 2.5.4, 2.6.0, 2.7.0
MRTK2 Unity 2019 2.5.0, 2.5.1, 2.5.2, 2.5.3, 2.5.4, 2.6.0, 2.7.0, 2.8.0
MRTK2 Unity 2020 2.5.2, 2.5.3, 2.5.4, 2.6.0, 2.7.0, 2.8.0