Created
April 18, 2018 00:50
-
-
Save kyubuns/a4af575d164dd0d8328b06e4fad4a8f5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment