using System; using System.Collections; using System.Collections.Generic; using com.workman.cm3d2.task; using UnityEngine; public class TaskMgr : MonoBehaviour { public void SetTimeUntilStart(float timeUntilStart) { this.timeUntilStart = timeUntilStart; } public void StartTask(Action onFinished = null) { this.coroutine = this.DoTask(onFinished); base.StartCoroutine(this.coroutine); } private IEnumerator DoTask(Action onFinished = null) { yield return new WaitForSeconds(this.timeUntilStart); foreach (Task task in this.listTask) { task.Execute(); yield return new WaitForSeconds(task.interval); } if (onFinished != null) { onFinished(); } this.Clear(); yield break; } private void Clear() { this.coroutine = null; } public void Stop() { if (this.coroutine != null) { base.StopCoroutine(this.coroutine); } } public List listTask; private IEnumerator coroutine; private float timeUntilStart; }