Table of Contents

Class MonoBehaviourExtensions

Namespace
Gamelogic.Extensions
Assembly
Assembly-CSharp.dll

Provides useful extension methods for MonoBehaviours.

[Version(1, 0, 0)]
public static class MonoBehaviourExtensions
Inheritance
MonoBehaviourExtensions
Inherited Members

Methods

CancelInvoke(MonoBehaviour, Action)

Cancels the action if it was scheduled.

[Obsolete("The new Invoke is implemented as a coroutine. Store and cancel the coroutine instead.")]
public static void CancelInvoke(this MonoBehaviour _1, Action _2)

Parameters

_1 MonoBehaviour
_2 Action

Clone<T>(T)

Clones an object.

public static T Clone<T>(this T obj) where T : MonoBehaviour

Parameters

obj T

Returns

T

Type Parameters

T

Clone<T>(T, int)

Clones an object.

public static List<T> Clone<T>(this T obj, int count) where T : MonoBehaviour

Parameters

obj T
count int

Returns

List<T>

Type Parameters

T

FindChild(Component, string)

public static GameObject FindChild(this Component component, string childName)

Parameters

component Component
childName string

Returns

GameObject

FindChild(Component, string, bool)

public static GameObject FindChild(this Component component, string childName, bool recursive)

Parameters

component Component
childName string
recursive bool

Returns

GameObject

GetComponentInChildrenAlways<T>(Component)

Finds a component of the type T in on the same object, or on a child down the hierarchy. This method also works in the editor and when the game object is inactive.

[Version(1, 1, 0)]
public static T GetComponentInChildrenAlways<T>(this Component component) where T : Component

Parameters

component Component

Returns

T

Type Parameters

T

GetComponentsInChildrenAlways<T>(Component)

Finds all components of the type T on the same object and on a children down the hierarchy. This method also works in the editor and when the game object is inactive.

[Version(1, 1, 0)]
public static T[] GetComponentsInChildrenAlways<T>(this Component component) where T : Component

Parameters

component Component

Returns

T[]

Type Parameters

T

GetInterfaceComponent<TInterface>(Component)

Gets an attached component that implements the interface of the type parameter.

public static TInterface GetInterfaceComponent<TInterface>(this Component thisComponent) where TInterface : class

Parameters

thisComponent Component

The this component.

Returns

TInterface

TInterface.

Type Parameters

TInterface

The type of the t interface.

GetRequiredComponentInChildren<T>(Component)

Gets a component of the given type in one of the children, or fail if no such component is attached to the given component.

public static T GetRequiredComponentInChildren<T>(this Component thisComponent) where T : Component

Parameters

thisComponent Component

The component to check.

Returns

T

A component of type T attached to the given component if it exists.

Type Parameters

T

The type of component to get.

Exceptions

InvalidOperationException

When the no component of the required type exist on any of the given components children.

GetRequiredComponent<T>(Component)

Gets a component of the given type, or fail if no such component is attached to the given component.

public static T GetRequiredComponent<T>(this Component thisComponent) where T : Component

Parameters

thisComponent Component

The component to check.

Returns

T

A component of type T attached to the given component if it exists.

Type Parameters

T

The type of component to get.

Exceptions

InvalidOperationException

When the no component of the required type exist on the given component.

Invoke(MonoBehaviour, Action, float)

Invokes the given action after the given amount of time.

public static Coroutine Invoke(this MonoBehaviour monoBehaviour, Action action, float time)

Parameters

monoBehaviour MonoBehaviour
action Action
time float

Returns

Coroutine

InvokeRepeating(MonoBehaviour, Action, IGenerator<float>)

Invokes the given action after the given amount of time, and repeats the action after every repeatTime seconds.

public static Coroutine InvokeRepeating(this MonoBehaviour monoBehaviour, Action action, IGenerator<float> repeatTime)

Parameters

monoBehaviour MonoBehaviour
action Action
repeatTime IGenerator<float>

Returns

Coroutine

InvokeRepeating(MonoBehaviour, Action, float, float)

Invokes the given action after the given amount of time, and repeats the action after every repeatTime seconds.

public static Coroutine InvokeRepeating(this MonoBehaviour monoBehaviour, Action action, float time, float repeatTime)

Parameters

monoBehaviour MonoBehaviour
action Action
time float
repeatTime float

Returns

Coroutine

IsInvoking(MonoBehaviour, Action)

Returns whether an invoke is pending on an action.

[Obsolete("The new Invoke is implemented as a coroutine. Store and cancel the coroutine instead.")]
public static bool IsInvoking(this MonoBehaviour _1, Action _2)

Parameters

_1 MonoBehaviour
_2 Action

Returns

bool

Tween<T>(MonoBehaviour, T, T, float, Func<T, T, float, T>, Action<T>)

public static Coroutine Tween<T>(this MonoBehaviour monoBehaviour, T start, T finish, float totalTime, Func<T, T, float, T> lerp, Action<T> action)

Parameters

monoBehaviour MonoBehaviour
start T
finish T
totalTime float
lerp Func<T, T, float, T>
action Action<T>

Returns

Coroutine

Type Parameters

T

Tween<T>(MonoBehaviour, T, T, float, Func<T, T, float, T>, Action<T>, Func<float>)

public static Coroutine Tween<T>(this MonoBehaviour monoBehaviour, T start, T finish, float totalTime, Func<T, T, float, T> lerp, Action<T> action, Func<float> deltaTime)

Parameters

monoBehaviour MonoBehaviour
start T
finish T
totalTime float
lerp Func<T, T, float, T>
action Action<T>
deltaTime Func<float>

Returns

Coroutine

Type Parameters

T