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