Global Task Runner
Run coroutines and long-running tasks without requiring a MonoBehaviour instance. Global Task Runner provides a lightweight API for starting, stopping, pausing, and resuming asynchronous operations globally within your Unity project. Ideal for managing background processes, animations, and timed events independently from game objects.
com.greener-games.global-task-runner 
Install via UPM
Add to Unity Package Manager using this URL
https://www.pkglnk.dev/global-task-runner.git?path=Assets/TaskRunner README Markdown
Copy this to your project's README.md
## Installation
Add **Global Task Runner** 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/global-task-runner.git?path=Assets%2FTaskRunner
```
[](https://www.pkglnk.dev/pkg/global-task-runner)README
Global Task Runner
A lightweight and easy-to-use Task/Coroutine runner for Unity.
This utility allows you to run and manage long-running processes (coroutines) without needing a MonoBehaviour instance. It provides a simple API to start, stop, pause, and resume tasks.
Installation
You can install this package via the Unity Package Manager.
- Open the Package Manager in
Window > Package Manager. - Click the
+button in the top-left corner and select "Add package from git URL...". - Enter the following URL:
https://github.com/Greener-Games/TaskRunner.git
The package will be installed in your project.
Usage
Here is a basic example of how to use the TaskRunner:
using UnityEngine;
using GG.GlobalTaskRunner;
using System.Collections;
public class Example : MonoBehaviour
{
void Start()
{
// Create and start a new task
TaskRunner.Create(MyCoroutine());
}
IEnumerator MyCoroutine()
{
Debug.Log("Task started!");
yield return new WaitForSeconds(5);
Debug.Log("Task finished after 5 seconds.");
}
}
You can also create a TaskRunner instance to have more control over the task:
using UnityEngine;
using GG.GlobalTaskRunner;
using System.Collections;
public class AdvancedExample : MonoBehaviour
{
private TaskRunner myTask;
void Start()
{
// Create a task without starting it immediately
myTask = new TaskRunner(MyCoroutine(), autoStart: false);
// Add a handler for when the task finishes
myTask.TaskFinishedHandler += OnTaskFinished;
// Start the task
myTask.Start();
}
void OnTaskFinished(bool manuallyStopped)
{
if (manuallyStopped)
{
Debug.Log("Task was stopped manually.");
}
else
{
Debug.Log("Task completed successfully.");
}
}
IEnumerator MyCoroutine()
{
Debug.Log("Task started!");
for (int i = 0; i < 5; i++)
{
Debug.Log("Working... " + i);
yield return new WaitForSeconds(1);
}
}
void OnDestroy()
{
// It's good practice to stop the task if the object is destroyed
if (myTask != null && myTask.Running)
{
myTask.Stop();
}
}
}
Documentation
For more detailed information and API reference, please see the full documentation.
License
This project is licensed under the MIT License - see the LICENSE.md file for details.
No comments yet. Be the first!