Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections;
- using System.Threading.Tasks;
- using UnityEngine;
- namespace Hoge
- {
- public class CoroutineRunner : MonoBehaviour
- {
- private static MonoBehaviour instance;
- public static Task<T> Run<T>(Func<TaskCompletionSource<T>, IEnumerator> coroutine)
- {
- if (instance == null)
- {
- var go = new GameObject("CoroutineRunner");
- instance = go.AddComponent<CoroutineRunner>();
- DontDestroyOnLoad(go);
- }
- var taskCompletionSource = new TaskCompletionSource<T>();
- instance.StartCoroutine(coroutine(taskCompletionSource));
- return taskCompletionSource.Task;
- }
- }
- }
Add Comment
Please, Sign In to add comment