/// <summary> /// Confirms the instance is ready for use /// </summary> public static void ConfirmInit() { if (_instance == null) { var old = FindObjectsOfType<TaskManager>(); foreach (var manager in old) { if (Application.isEditor) DestroyImmediate(manager.gameObject); else Destroy(manager.gameObject); } var go = new GameObject("_TaskManager"); DontDestroyOnLoad(go); _instance = go.AddComponent<TaskManager>(); MainThread = CurrentThread; } }
protected void Awake() { if (_instance == null) _instance = this; }
/// <summary> /// Adds a timeout to the task. Will raise an exception if still running /// </summary> /// <typeparam name="T"></typeparam> /// <param name="self"></param> /// <param name="seconds"></param> /// <param name="onTimeout"></param> /// <returns></returns> public static T AddTimeout <T>(this T self, int seconds, Action <UnityTask> onTimeout = null) where T : UnityTask { TaskManager.StartRoutine(TimeOutAsync(self, seconds, onTimeout)); return(self); }
static UnityTask() { TaskManager.ConfirmInit(); }
protected void RunOnMainThread() { Status = TaskStatus.Pending; TaskManager.RunOnMainThread(Execute); }
static AsyncTask() { #if UNITY TaskManager.ConfirmInit(); #endif }