Table of Contents

Class GameObjectExtensions

Namespace
S1MAPI.Extensions
Assembly
S1MAPI_Mono.dll

Extension methods for GameObject operations.

public static class GameObjectExtensions
Inheritance
GameObjectExtensions
Inherited Members

Methods

Destroy(GameObject)

Safe destroy that handles null checks.

public static void Destroy(this GameObject gameObject)

Parameters

gameObject GameObject

EnableAllComponents(GameObject, bool)

Enable all MonoBehaviour components on this GameObject and its children.

public static void EnableAllComponents(this GameObject gameObject, bool recursive = true)

Parameters

gameObject GameObject

The GameObject to enable components on

recursive bool

Whether to enable components on children (default: true)

EnableAndSetup(GameObject, string, string?, bool)

Enable a component by name and optionally invoke a setup method on it.

public static bool EnableAndSetup(this GameObject gameObject, string componentName, string? setupMethodName = null, bool recursive = true)

Parameters

gameObject GameObject

The GameObject containing the component

componentName string

Name of the component type

setupMethodName string

Optional method name to invoke after enabling

recursive bool

Whether to search children (default: true)

Returns

bool

True if component was found and enabled

EnableComponentsByName(GameObject, string[], bool)

Enable specific component types by name on this GameObject and its children.

public static void EnableComponentsByName(this GameObject gameObject, string[] componentNames, bool recursive = true)

Parameters

gameObject GameObject

The GameObject to enable components on

componentNames string[]

Array of component type names to enable

recursive bool

Whether to search children (default: true)

GetComponentByName(GameObject, string, bool)

Get a component by name without requiring a type reference.

public static MonoBehaviour? GetComponentByName(this GameObject gameObject, string componentName, bool recursive = true)

Parameters

gameObject GameObject

The GameObject to search

componentName string

Name of the component type

recursive bool

Whether to search children (default: true)

Returns

MonoBehaviour

The component if found, null otherwise

GetOrAddComponent<T>(GameObject)

Get existing component or add one if missing. Returns the component.

public static T GetOrAddComponent<T>(this GameObject gameObject) where T : Component

Parameters

gameObject GameObject

Returns

T

Type Parameters

T

HasComponent<T>(GameObject)

Check if GameObject has a component of type T.

public static bool HasComponent<T>(this GameObject gameObject) where T : Component

Parameters

gameObject GameObject

Returns

bool

Type Parameters

T

Hide(GameObject)

Hide the GameObject by setting active to false.

public static GameObject Hide(this GameObject gameObject)

Parameters

gameObject GameObject

Returns

GameObject

SetLayerRecursively(GameObject, int)

Set the layer for this GameObject and all its children.

public static GameObject SetLayerRecursively(this GameObject gameObject, int layer)

Parameters

gameObject GameObject
layer int

Returns

GameObject

SetLayerRecursively(GameObject, string)

Set the layer by name for this GameObject and all its children.

public static GameObject SetLayerRecursively(this GameObject gameObject, string layerName)

Parameters

gameObject GameObject
layerName string

Returns

GameObject

Show(GameObject)

Show the GameObject by setting active to true.

public static GameObject Show(this GameObject gameObject)

Parameters

gameObject GameObject

Returns

GameObject