Table of Contents

Class GameObjectExtensions

Namespace
Nautilus.Extensions
Assembly
Nautilus.dll
Contains extension methods for Unity objects.
public static class GameObjectExtensions
Inheritance
GameObjectExtensions
Inherited Members

Methods

AddAndCopyComponent<TNewComponent, TCopiedComponent>(GameObject)

Adds a component with the TNewComponent type, then copies the field values of the TCopiedComponent into it.
public static TNewComponent AddAndCopyComponent<TNewComponent, TCopiedComponent>(this GameObject obj) where TNewComponent : Component, TCopiedComponent

Parameters

obj GameObject
The Game object to perform this action on.

Returns

TNewComponent
The new component with the correct field values.

Type Parameters

TNewComponent
The type of the new component.
TCopiedComponent
The type of the copied component.

Remarks

This method only takes effect on public fields that are serializable, or non-public fields with the UnityEngine.SerializeField attribute.
See Also

CopyComponent<TSelfComponent, TCopiedComponent>(TSelfComponent, TCopiedComponent)

Copies the field values from the specified component to the current component.
public static TSelfComponent CopyComponent<TSelfComponent, TCopiedComponent>(this TSelfComponent @this, TCopiedComponent copyFrom) where TSelfComponent : Component, TCopiedComponent

Parameters

this TSelfComponent
The current instance to copy to.
copyFrom TCopiedComponent
The specified instance to copy from.

Returns

TSelfComponent
The current component with the correct field values.

Type Parameters

TSelfComponent
The type of this component.
TCopiedComponent
The type of the copied component.

Remarks

This method only takes effect on public fields that are serializable, or non-public fields with the UnityEngine.SerializeField attribute.
See Also

EnsureAndCopyComponent<TNewComponent, TCopiedComponent>(GameObject)

Ensures a component with the TNewComponent type exists, then copies the field values of the TCopiedComponent into it.
public static TNewComponent EnsureAndCopyComponent<TNewComponent, TCopiedComponent>(this GameObject obj) where TNewComponent : Component, TCopiedComponent

Parameters

obj GameObject
The Game object to perform this action on.

Returns

TNewComponent
The new component with the correct field values.

Type Parameters

TNewComponent
The type of the new component.
TCopiedComponent
The type of the copied component.

Remarks

This method only takes effect on public fields that are serializable, or non-public fields with the UnityEngine.SerializeField attribute.
See Also

Exists<T>(T)

Checks if the object exists. This method is a wrapper to allow null-coalescing operator usage by respecting Unity's object life cycle.
public static T Exists<T>(this T @object) where T : Object

Parameters

object T
the object

Returns

T
The object if exists, otherwise null.

Type Parameters

T
the UnityEngine.Object type

ForceValid<TAssetReference>(TAssetReference)

Forces the passed UnityEngine.AddressableAssets.AssetReferenceGameObject's RuntimeKey to always pass the IsRuntimeKeyValid check.
public static TAssetReference ForceValid<TAssetReference>(this TAssetReference @this) where TAssetReference : AssetReference

Parameters

this TAssetReference
The UnityEngine.AddressableAssets.AssetReferenceGameObject to convert

Returns

TAssetReference
A reference to this instance after the operation is completed.

Type Parameters

TAssetReference

IsPrefab(GameObject)

Checks if this game object is a proper prefab. Proper prefabs are those that are made via the Unity Editor and are .prefab formatted.
public static bool IsPrefab(this GameObject gameObject)

Parameters

gameObject GameObject
The game object to check.

Returns

bool
True if this game object is a proper prefab, otherwise false.

Exceptions

NullReferenceException
gameObject is null.

SearchChild(GameObject, string)

Searches the hierarchy under this GameObject recursively and returns a child GameObject with the matching name if any is found.
public static GameObject SearchChild(this GameObject gameObject, string name)

Parameters

gameObject GameObject
The root object of the search.
name string
The name of the object that is being searched for.

Returns

GameObject
If found, a reference to the game object, otherwise; null.

SearchChild(Transform, string)

Searches the hierarchy under this Transform recursively and returns a child Transform with the matching name if any is found.
public static Transform SearchChild(this Transform transform, string name)

Parameters

transform Transform
The root object of the search.
name string
The name of the object that is being searched for.

Returns

Transform
If found, a reference to the transform, otherwise; null.