using System.Collections; using System.Collections.Generic; using UnityEngine; using System; public class CreateRoleTimeLine { public bool busying { get; private set; } Action onComplete; List nodes = new List(); LogicUpdate update; public CreateRoleTimeLine() { update = new LogicUpdate(); update.Start(OnUpdate); } public void AddNone(float time, Action task) { nodes.Add(new Node() { time = Time.time + time, task = task }); } public void Begin() { busying = true; } public void Stop() { Reset(); busying = false; } public void OnComplete(Action onComplete) { this.onComplete = onComplete; } public void ClearNode() { nodes.Clear(); } public void Dispose() { ClearNode(); if (update != null) { update.Destroy(); } } private void Reset() { foreach (var node in nodes) { node.executed = false; } } private void OnUpdate() { var allExecuted = true; foreach (var node in nodes) { if (!node.executed) { if (Time.time >= node.time) { node.Execute(); } } else { allExecuted = false; } } if (allExecuted) { if (this.onComplete != null) { this.onComplete(); } busying = false; } } public class Node { public bool executed; public float time; public Action task; public void Execute() { executed = true; if (task != null) { task(); } } } }