ConcurrentTools-Package is a simple yet powerful task management tool for the Unity Game Engine. It enables seamless execution of asynchronous tasks, delayed tasks, and concurrent operations within Unity. Designed to simplify task handling, this package helps developers manage tasks efficiently while ensuring they run on the main thread when necessary.
- Simplifies Async Operations: Easily execute and manage asynchronous tasks without blocking Unity's main thread.
- Delayed Task Execution: Schedule tasks to run after a specified delay.
- Concurrency Handling: Run tasks concurrently while maintaining thread safety.
- Main Thread Execution: Ensure tasks are executed on the main thread for compatibility with Unity APIs.
- Timeout Support: Prevent long-running tasks from hanging indefinitely by setting execution timeouts.
To install ConcurrentTools-Package in your Unity project:
- Open Unity Package Manager (
Window > Package Manager). - Click Add package from git URL.
- Enter the repository URL and click Add.
The package initializes automatically when the game starts. No manual setup is required.
Use EnumeratorRunner.Run to execute a simple action on the main thread.
EnumeratorRunner.Run(() =>
{
Debug.Log("Executing on the main thread!");
});Run an asynchronous task and specify a callback when the task is complete.
async Task ExampleTask()
{
await Task.Delay(2000);
Debug.Log("Task finished after 2 seconds.");
}
EnumeratorRunner.Run(ExampleTask, () =>
{
Debug.Log("Task completed callback.");
});Run an async function that returns a result and handle the output.
async Task<int> ComputeSum()
{
await Task.Delay(1000);
return 10 + 20;
}
EnumeratorRunner.Run(ComputeSum, (result) =>
{
Debug.Log($"Sum computed: {result}");
});Run a task after a specified delay.
EnumeratorRunner.Run(() =>
{
Debug.Log("This runs after 3 seconds.");
}, 3f);If a task takes too long, it gets abandoned.
async Task<int> SlowOperation()
{
await Task.Delay(6000);
return 42;
}
EnumeratorRunner.Run(SlowOperation, (result) =>
{
Debug.Log($"This will not log because of timeout.");
}, 5f);ConcurrentTools-Package is a simple yet effective tool for managing tasks in Unity. Whether you need to run asynchronous operations, execute delayed tasks, or handle concurrency, this package makes task management smooth and efficient. Start using it today to improve the performance and organization of your Unity projects!