DinnerCoroutine
DinnerCoroutine extends Unity's built-in coroutine system with enhanced control and flexibility. Start, pause, resume, and stop coroutines with full status tracking while maintaining compatibility with standard yield instructions. Supports editor and runtime execution, global coroutines that persist across scene loads, and asynchronous operations—all with zero external dependencies.
com.canstudio.dinner-coroutine 
Install via UPM
Add to Unity Package Manager using this URL
https://www.pkglnk.dev/dinner-coroutine.git#upm README Markdown
Copy this to your project's README.md
## Installation
Add **DinnerCoroutine** to your Unity project via Package Manager:
1. Open **Window > Package Manager**
2. Click **+** > **Add package from git URL**
3. Enter:
```
https://www.pkglnk.dev/dinner-coroutine.git#upm
```
[](https://www.pkglnk.dev/pkg/dinner-coroutine)README
DinnerCoroutine
点击这里查看中文介绍
DinnerCoroutine is a simple enhancement of Unity's coroutine. The usage of DinnerCoroutine is similar with original Unity coroutine, you can change the original coroutine into DinnerCoroutine without modifying your coroutine code.
Features
- Support original yield instructions.
- Support original custom yield instructions.
- Support both editor and in game coroutine.
- Support yield return fixed update in editor.
- Provides full control to coroutine (manually start, pause and recover, stop or interrupt).
- Provides asynchronous coroutine (you cannot access some Unity methods in this kind of coroutine).
- Allow global coroutine (won't destroy when MonoBehaviour destroyed).
- No dependency.
- More features...
Installation
DinnerCoroutine is easy to install, you can use any of following methods to install it.
OpenUPM (Recommended)
If you are new to OpenUPM, install openupm-cli first.
Go to your Unity project root folder (you can find an
Assetsfolder under it), run this command:openupm add com.canstudio.dinner-coroutineOpen your Unity editor, DinnerCoroutine should be installed successfully.
UPM
If you haven't installed Git, download and install it here: download Git
Open your Unity editor, open
Window -> Package Managerin the toolbar.In Package Manager, click
+ -> add package from git URLin the top left corner.Add following package:
https://github.com/SUSTech-CANStudio/DinnerCoroutine.git#upm
Quick Start
A sample script
using System.Collections;
using UnityEngine;
using CANStudio.DinnerCoroutine;
public class MyScript : MonoBehaviour
{
public float time = 2f;
private void Start()
{
this.StartSpoon("MyCoroutine", time);
}
private IEnumerator MyCoroutine(float waitTime)
{
Debug.Log("Ping!");
yield return new WaitForSeconds(waitTime);
Debug.Log("Pong!");
}
}
Control a coroutine
// In a MonoBehaviour script
// The return value 'coroutine' is the handler of a coroutine
var coroutine = this.StartSpoon("MyCoroutine");
Get status
Debug.Log(coroutine.Status);
/** This can print one of followings:
* NotStarted
* Running
* Paused
* Finished
*/
Change status
// start a paused of not started coroutine
coroutine.Start();
// pause a coroutine
coroutine.Pause();
// stop a coroutine
coroutine.Stop();
// inturrupt a coroutine
// this behaves same as Stop(), but do not invoke callback event in the coroutine.
coroutine.Interrupt();
Samples
You can view samples here:
Limitations
As Unity doesn't have full event loop in editor made, some command works differently when coroutine runs in editor:
WaitForEndOfFrame: performs asyield return nullin editor.WaitForSecondsRealtime: won't work properly, will wait for a random time depends on the frame rate.
Time support in editor coroutines
Please pay attention when using the Time class, it doesn't work and always return a constant value in editor mode. Considering use DinnerTime instead of Time in your coroutines, this class is an alias of Time in playing mode, and can also provide partial time access in editor mode.
DinnerTime provides following functions in editor mode:
time,deltaTime,unscaledTime,unscaledDeltaTime,timeScale,fixedTime,fixedDeltaTime,fixedUnscaledTime,fixedUnscaledDeltaTime,inFixedTimeStep: These functions works properly in editor just like what they do in playing.- Other functions are currently not accessible in editor mode.
No comments yet. Be the first!