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
_1MonoBehaviour_2Action
Clone<T>(T)
Clones an object.
public static T Clone<T>(this T obj) where T : MonoBehaviour
Parameters
objT
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
objTcountint
Returns
- List<T>
Type Parameters
T
FindChild(Component, string)
public static GameObject FindChild(this Component component, string childName)
Parameters
Returns
FindChild(Component, string, bool)
public static GameObject FindChild(this Component component, string childName, bool recursive)
Parameters
Returns
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
componentComponent
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
componentComponent
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
thisComponentComponentThe this component.
Returns
- TInterface
TInterface.
Type Parameters
TInterfaceThe 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
thisComponentComponentThe component to check.
Returns
- T
A component of type T attached to the given component if it exists.
Type Parameters
TThe 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
thisComponentComponentThe component to check.
Returns
- T
A component of type T attached to the given component if it exists.
Type Parameters
TThe 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
monoBehaviourMonoBehaviouractionActiontimefloat
Returns
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
monoBehaviourMonoBehaviouractionActionrepeatTimeIGenerator<float>
Returns
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
monoBehaviourMonoBehaviouractionActiontimefloatrepeatTimefloat
Returns
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
_1MonoBehaviour_2Action
Returns
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
monoBehaviourMonoBehaviourstartTfinishTtotalTimefloatlerpFunc<T, T, float, T>actionAction<T>
Returns
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
monoBehaviourMonoBehaviourstartTfinishTtotalTimefloatlerpFunc<T, T, float, T>actionAction<T>deltaTimeFunc<float>
Returns
Type Parameters
T