Unclaimed Package Is this your package? Claim it to unlock full analytics and manage your listing.
Claim This Package

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

Style
Preview
pkglnk installs badge
## 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
```

[![pkglnk](https://www.pkglnk.dev/badge/global-task-runner.svg?style=pkglnk)](https://www.pkglnk.dev/pkg/global-task-runner)

README

Global Task Runner

openupm

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.

  1. Open the Package Manager in Window > Package Manager.
  2. Click the + button in the top-left corner and select "Add package from git URL...".
  3. 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.

Comments

No comments yet. Be the first!