/P31TaskManager

General purpose task manager that provides a lot more control and power than a standard coroutine

Primary LanguageC#

P31TaskManager for Unity

This is a lightweight task manager that lets you run a task either on the main thread (like a coroutine) or on a background thread. The general idea is for simple tasks you can use the built in P31ActionTask which will tick any Func (function that returns a boolean) you pass in each frame until you return false indicating the task is complete. For more complex tasks you can subclass P31AbstractTask for main thread tasks and P31AbstractBackgroundTask for background tasks. All non-background tasks can be paused, unpaused or cancelled (background tasks cannot be paused).

A task is defined as anything that requires work. It could be as simple as a method that needs to be called each frame (similar to Update but with the ability to pause/unpause/cancel) or as complex as something that needs to run on a background thread.

Tasks can also be chained. Each task has a nextTask property that you can set with any other task. This allows you to perform a series of work with each step needing the result of the previous task or to simply sequence any tasks.