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
gameObjectGameObject
EnableAllComponents(GameObject, bool)
Enable all MonoBehaviour components on this GameObject and its children.
public static void EnableAllComponents(this GameObject gameObject, bool recursive = true)
Parameters
gameObjectGameObjectThe GameObject to enable components on
recursiveboolWhether 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
gameObjectGameObjectThe GameObject containing the component
componentNamestringName of the component type
setupMethodNamestringOptional method name to invoke after enabling
recursiveboolWhether 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
gameObjectGameObjectThe GameObject to enable components on
componentNamesstring[]Array of component type names to enable
recursiveboolWhether 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
gameObjectGameObjectThe GameObject to search
componentNamestringName of the component type
recursiveboolWhether 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
gameObjectGameObject
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
gameObjectGameObject
Returns
Type Parameters
T
Hide(GameObject)
Hide the GameObject by setting active to false.
public static GameObject Hide(this GameObject gameObject)
Parameters
gameObjectGameObject
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
gameObjectGameObjectlayerint
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
gameObjectGameObjectlayerNamestring
Returns
- GameObject
Show(GameObject)
Show the GameObject by setting active to true.
public static GameObject Show(this GameObject gameObject)
Parameters
gameObjectGameObject
Returns
- GameObject