Class ComponentExtensions
Extensions for 'UnityEngine.Component'.
Inheritance
Inherited Members
Namespace: UnityEngine
Assembly: cs.temp.dll.dll
Syntax
public static class ComponentExtensions
Methods
GetTaskRunner(Component, TaskRunOptions)
Get a
Declaration
public static ITaskRunner GetTaskRunner(this Component component, TaskRunOptions options = TaskRunOptions.Default)
Parameters
Type | Name | Description |
---|---|---|
Component | component | Component to get the runner for. |
TaskRunOptions | options | Options for configuring how tasks are run on this runner. |
Returns
Type | Description |
---|---|
ITaskRunner |
Remarks
If a existing runner exists for the component then that is returned, otherwise a new runner is created.
Can only be called from the unity-thread in play-mode.
Exceptions
Type | Condition |
---|---|
NotPlayingException | Thrown when called in edit-mode. |
NonUnityThreadException | Thrown when called from a non-unity thread. |
StartTask(Component, Func<CancellationToken, Task>, TaskRunOptions)
Start a task scoped to the given component.
Declaration
public static Task StartTask(this Component component, Func<CancellationToken, Task> taskCreator, TaskRunOptions options = TaskRunOptions.Default)
Parameters
Type | Name | Description |
---|---|---|
Component | component | Component to run the task 'on'. |
System.Func<CancellationToken, System.Threading.Tasks.Task> | taskCreator | Function for creating the task. |
TaskRunOptions | options | Options for configuring how the task is run. |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task | Task that completes when the original task completes or when the component gets destroyed. |
Remarks
The task will run 'on' the component, meaning that the task gets paused when the component is disabled and the task will get cancelled when the component is destroyed.
Can only be called from the unity-thread in play-mode.
Exceptions
Type | Condition |
---|---|
NotPlayingException | Thrown when called in edit-mode. |
NonUnityThreadException | Thrown when called from a non-unity thread. |
TaskCreatorReturnedNullException | Thrown when null is returned from the 'taskCreator'. |
ComponentTaskCanceledException | Thrown when awaiting a component-task that gets cancelled. Can happen if you are awaiting a component that gets destroyed. |
InactiveGameObjectException | Thrown when attempting to start a task on a disabled gameobject. |
InactiveComponentException | Thrown when attempting to start a task on a disabled component. Does not happen when giving UpdateWhileComponentDisabled flag. |
StartTask(Component, Func<Task>, TaskRunOptions)
Start a task scoped to the given component.
Declaration
public static Task StartTask(this Component component, Func<Task> taskCreator, TaskRunOptions options = TaskRunOptions.Default)
Parameters
Type | Name | Description |
---|---|---|
Component | component | Component to run the task 'on'. |
System.Func<System.Threading.Tasks.Task> | taskCreator | Function for creating the task. |
TaskRunOptions | options | Options for configuring how the task is run. |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task | Task that completes when the original task completes or when the component gets destroyed. |
Remarks
The task will run 'on' the component, meaning that the task gets paused when the component is disabled and the task will get cancelled when the component is destroyed.
Can only be called from the unity-thread in play-mode.
Exceptions
Type | Condition |
---|---|
NotPlayingException | Thrown when called in edit-mode. |
NonUnityThreadException | Thrown when called from a non-unity thread. |
TaskCreatorReturnedNullException | Thrown when null is returned from the 'taskCreator'. |
ComponentTaskCanceledException | Thrown when awaiting a component-task that gets cancelled. Can happen if you are awaiting a component that gets destroyed. |
InactiveGameObjectException | Thrown when attempting to start a task on a disabled gameobject. |
InactiveComponentException | Thrown when attempting to start a task on a disabled component. Does not happen when giving UpdateWhileComponentDisabled flag. |
StartTask<TIn>(Component, Func<TIn, CancellationToken, Task>, TIn, TaskRunOptions)
Start a task scoped to the given component.
Declaration
public static Task StartTask<TIn>(this Component component, Func<TIn, CancellationToken, Task> taskCreator, TIn data, TaskRunOptions options = TaskRunOptions.Default)
Parameters
Type | Name | Description |
---|---|---|
Component | component | Component to run the task 'on'. |
System.Func<TIn, CancellationToken, System.Threading.Tasks.Task> | taskCreator | Function for creating the task. |
TIn | data | |
TaskRunOptions | options | Options for configuring how the task is run. |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task | Task that completes when the original task completes or when the component gets destroyed. |
Type Parameters
Name | Description |
---|---|
TIn |
Remarks
The task will run 'on' the component, meaning that the task gets paused when the component is disabled and the task will get cancelled when the component is destroyed.
Can only be called from the unity-thread in play-mode.
Exceptions
Type | Condition |
---|---|
NotPlayingException | Thrown when called in edit-mode. |
NonUnityThreadException | Thrown when called from a non-unity thread. |
TaskCreatorReturnedNullException | Thrown when null is returned from the 'taskCreator'. |
ComponentTaskCanceledException | Thrown when awaiting a component-task that gets cancelled. Can happen if you are awaiting a component that gets destroyed. |
InactiveGameObjectException | Thrown when attempting to start a task on a disabled gameobject. |
InactiveComponentException | Thrown when attempting to start a task on a disabled component. Does not happen when giving UpdateWhileComponentDisabled flag. |
StartTask<TIn>(Component, Func<TIn, Task>, TIn, TaskRunOptions)
Start a task scoped to the given component.
Declaration
public static Task StartTask<TIn>(this Component component, Func<TIn, Task> taskCreator, TIn data, TaskRunOptions options = TaskRunOptions.Default)
Parameters
Type | Name | Description |
---|---|---|
Component | component | Component to run the task 'on'. |
System.Func<TIn, System.Threading.Tasks.Task> | taskCreator | Function for creating the task. |
TIn | data | |
TaskRunOptions | options | Options for configuring how the task is run. |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task | Task that completes when the original task completes or when the component gets destroyed. |
Type Parameters
Name | Description |
---|---|
TIn |
Remarks
The task will run 'on' the component, meaning that the task gets paused when the component is disabled and the task will get cancelled when the component is destroyed.
Can only be called from the unity-thread in play-mode.
Exceptions
Type | Condition |
---|---|
NotPlayingException | Thrown when called in edit-mode. |
NonUnityThreadException | Thrown when called from a non-unity thread. |
TaskCreatorReturnedNullException | Thrown when null is returned from the 'taskCreator'. |
ComponentTaskCanceledException | Thrown when awaiting a component-task that gets cancelled. Can happen if you are awaiting a component that gets destroyed. |
InactiveGameObjectException | Thrown when attempting to start a task on a disabled gameobject. |
InactiveComponentException | Thrown when attempting to start a task on a disabled component. Does not happen when giving UpdateWhileComponentDisabled flag. |
StartTask<TOut>(Component, Func<CancellationToken, Task<TOut>>, TaskRunOptions)
Start a task scoped to the given component.
Declaration
public static Task<TOut> StartTask<TOut>(this Component component, Func<CancellationToken, Task<TOut>> taskCreator, TaskRunOptions options = TaskRunOptions.Default)
Parameters
Type | Name | Description |
---|---|---|
Component | component | Component to run the task 'on'. |
System.Func<CancellationToken, System.Threading.Tasks.Task<TOut>> | taskCreator | Function for creating the task. |
TaskRunOptions | options | Options for configuring how the task is run. |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<TOut> | Task that completes when the original task completes or when the component gets destroyed. |
Type Parameters
Name | Description |
---|---|
TOut |
Remarks
The task will run 'on' the component, meaning that the task gets paused when the component is disabled and the task will get cancelled when the component is destroyed.
Can only be called from the unity-thread in play-mode.
Exceptions
Type | Condition |
---|---|
NotPlayingException | Thrown when called in edit-mode. |
NonUnityThreadException | Thrown when called from a non-unity thread. |
TaskCreatorReturnedNullException | Thrown when null is returned from the 'taskCreator'. |
ComponentTaskCanceledException | Thrown when awaiting a component-task that gets cancelled. Can happen if you are awaiting a component that gets destroyed. |
InactiveGameObjectException | Thrown when attempting to start a task on a disabled gameobject. |
InactiveComponentException | Thrown when attempting to start a task on a disabled component. Does not happen when giving UpdateWhileComponentDisabled flag. |
StartTask<TOut>(Component, Func<Task<TOut>>, TaskRunOptions)
Start a task scoped to the given component.
Declaration
public static Task<TOut> StartTask<TOut>(this Component component, Func<Task<TOut>> taskCreator, TaskRunOptions options = TaskRunOptions.Default)
Parameters
Type | Name | Description |
---|---|---|
Component | component | Component to run the task 'on'. |
System.Func<System.Threading.Tasks.Task<TOut>> | taskCreator | Function for creating the task. |
TaskRunOptions | options | Options for configuring how the task is run. |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<TOut> | Task that completes when the original task completes or when the component gets destroyed. |
Type Parameters
Name | Description |
---|---|
TOut |
Remarks
The task will run 'on' the component, meaning that the task gets paused when the component is disabled and the task will get cancelled when the component is destroyed.
Can only be called from the unity-thread in play-mode.
Exceptions
Type | Condition |
---|---|
NotPlayingException | Thrown when called in edit-mode. |
NonUnityThreadException | Thrown when called from a non-unity thread. |
TaskCreatorReturnedNullException | Thrown when null is returned from the 'taskCreator'. |
ComponentTaskCanceledException | Thrown when awaiting a component-task that gets cancelled. Can happen if you are awaiting a component that gets destroyed. |
InactiveGameObjectException | Thrown when attempting to start a task on a disabled gameobject. |
InactiveComponentException | Thrown when attempting to start a task on a disabled component. Does not happen when giving UpdateWhileComponentDisabled flag. |
StartTask<TIn, TOut>(Component, Func<TIn, CancellationToken, Task<TOut>>, TIn, TaskRunOptions)
Start a task scoped to the given component.
Declaration
public static Task<TOut> StartTask<TIn, TOut>(this Component component, Func<TIn, CancellationToken, Task<TOut>> taskCreator, TIn data, TaskRunOptions options = TaskRunOptions.Default)
Parameters
Type | Name | Description |
---|---|---|
Component | component | Component to run the task 'on'. |
System.Func<TIn, CancellationToken, System.Threading.Tasks.Task<TOut>> | taskCreator | Function for creating the task. |
TIn | data | |
TaskRunOptions | options | Options for configuring how the task is run. |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<TOut> | Task that completes when the original task completes or when the component gets destroyed. |
Type Parameters
Name | Description |
---|---|
TIn | |
TOut |
Remarks
The task will run 'on' the component, meaning that the task gets paused when the component is disabled and the task will get cancelled when the component is destroyed.
Can only be called from the unity-thread in play-mode.
Exceptions
Type | Condition |
---|---|
NotPlayingException | Thrown when called in edit-mode. |
NonUnityThreadException | Thrown when called from a non-unity thread. |
TaskCreatorReturnedNullException | Thrown when null is returned from the 'taskCreator'. |
ComponentTaskCanceledException | Thrown when awaiting a component-task that gets cancelled. Can happen if you are awaiting a component that gets destroyed. |
InactiveGameObjectException | Thrown when attempting to start a task on a disabled gameobject. |
InactiveComponentException | Thrown when attempting to start a task on a disabled component. Does not happen when giving UpdateWhileComponentDisabled flag. |
StartTask<TIn, TOut>(Component, Func<TIn, Task<TOut>>, TIn, TaskRunOptions)
Start a task scoped to the given component.
Declaration
public static Task<TOut> StartTask<TIn, TOut>(this Component component, Func<TIn, Task<TOut>> taskCreator, TIn data, TaskRunOptions options = TaskRunOptions.Default)
Parameters
Type | Name | Description |
---|---|---|
Component | component | Component to run the task 'on'. |
System.Func<TIn, System.Threading.Tasks.Task<TOut>> | taskCreator | Function for creating the task. |
TIn | data | |
TaskRunOptions | options | Options for configuring how the task is run. |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<TOut> | Task that completes when the original task completes or when the component gets destroyed. |
Type Parameters
Name | Description |
---|---|
TIn | |
TOut |
Remarks
The task will run 'on' the component, meaning that the task gets paused when the component is disabled and the task will get cancelled when the component is destroyed.
Can only be called from the unity-thread in play-mode.
Exceptions
Type | Condition |
---|---|
NotPlayingException | Thrown when called in edit-mode. |
NonUnityThreadException | Thrown when called from a non-unity thread. |
TaskCreatorReturnedNullException | Thrown when null is returned from the 'taskCreator'. |
ComponentTaskCanceledException | Thrown when awaiting a component-task that gets cancelled. Can happen if you are awaiting a component that gets destroyed. |
InactiveGameObjectException | Thrown when attempting to start a task on a disabled gameobject. |
InactiveComponentException | Thrown when attempting to start a task on a disabled component. Does not happen when giving UpdateWhileComponentDisabled flag. |