Skip to content
This repository was archived by the owner on Jun 24, 2025. It is now read-only.

Creating new Task

Wildan Mubarok edited this page Jul 17, 2016 · 1 revision

Creating a new Task

Introduction

Creating a new task will triggers an automatic handling for your Coroutine, we'll take care for the math and logic behind the scene while still on the top performance.

Task.Get()

You can create a new Task by calling Task.Get(), here's each parameter's explanation:

Parameter Default Value Description
IEnumerator c Required Parameter for inserting a Coroutine
bool autoStart true Should coroutine started immedially?
string id null Optional parameter for detecting if there's duplicate coroutines run
bool overrideIfExist true If duplicate found, Should we interrupt and override the existed coroutine?

Optionally if you choose to use delegate variant, there are more options available:

Parameter Default Value Description
CallBack c Required Another c with is using delegates
float totalTime Required Used in conjuction with delegates, Required for entering total time in seconds
InterpolationType interpolType InterpolationType.Linear How curves along time is interpolated?
bool inverted false should final interpolation time be inverted to 1..0?

Returns

Every parameter will returns a class instance named Task, so you can handle the coroutine in much simpler way. If corountine has stopped and it's flushAtFinish set to true (default), then you should never use that class anymore since it's resources are released and marked as inactive.

Example

void Update()
{
   if(Input.GetKey(KeyCode.Space))
       Task.Get(delegate (float t) {
           transform.position = new Vector3(t, 0, 0);
           transform.scale = new Vector3(t, 1, t);
       }, 5, "SmoothMovement", InterpolationType.SmootherStep);
}

Clone this wiki locally