CoroutineHelper

Description
This is a set of helper classes which allows you to run a delegate at specific times. You can simply delay a call, call it repeatedly or even schedule it as OnGUI call.

The supported methods are:

* Run.EachFrame(delegate) * Run.Every(initialDelay, repeatDelay, delegate) * Run.After(delay, delegate) * Run.Lerp(duration, float-delegate) * Run.OnDelegate(SimpleEvent, delegate) * Run.OnGUI(duration, delegate) * Run.Coroutine(someUnityIEnumerator)

Each of these calls retun a Run instance which can be used to abort the scheduled task or to wait for it to complete.

To wait for a task you can use the "WaitFor" property inside a coroutine or use "ExecuteWhenDone(delegate)" to run a delegate when the task is finished.

Additionally there's another little helperclass to create a GUI window on-the-fly:

* Run.CreateGUIWindow(rect, title, CTempWindow-delegate)

Run.Every
After running this code once after 10 seconds it will print "Something" every 2 seconds.

Run.After
This will print "See you in 4 seconds" and 4 seconds later it prints "4 Seconds later"

Run.Lerp
This will execute the Debug.Log every frame for 3 seconds. The value t is increasing linearly from 0.0f to 1.0f during this time.

Run.OnDelegate
when "someEvent.Run;" is executed it will print "Hello World"

Run.OnGUI
If you execute this it will display the GUI button for 5 seconds. The passed delegate will be executed inside OnGUI. If you pass 0 as duration it will run "forever" or until you call Abort on the returned Run instance. This will display the button at the given coordinates until you click the button. Note: Since the delegate in this example is a closure the "instance" variable has to be declared before you create the closure. So this is not possible:

Run.Coroutine
This is basically a replacement for StartCoroutine. It can be used everywhere since it's static. It also returns a Run instance which can be used to wait for the coroutine even multiple times or let you execute something when it's finished. Note: The passed coroutine will be run on the CoroutineHelper gameobject.

Run.CreateGUIWindow
This creates an instance of the Run.CTempWindow class which just holds the basic information required for a GUI.Window like title, windowid, position and a Run instance which displays the window utilizing Run.OnGUI. The CTempWindow instance is passed to the delegate and also returned by the CreateGUIWindow function.

Zip archive
[[Media:CoroutineHelperPack.zip]]