123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- 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<Task> listTask;
- private IEnumerator coroutine;
- private float timeUntilStart;
- }
|