using Cysharp.Threading.Tasks; using PMaker.Extension; using System.Linq; using System.Threading; using UnityEngine; namespace PMaker.Await.UI { public class UISequence : AwaitBehaviour { public AsyncReactiveProperty current = new AsyncReactiveProperty(0); [SerializeField] private AwaitBehaviour[] _behaviours; private void Reset() { this._behaviours = this .transform .Children() .Select(_ => { if (_.TryGetComponent(out var behaviour) == true) { return behaviour; } else { return null; } }) .Where(x => x != null) .ToArray(); } public override async UniTask WaitAsync(CancellationToken cancellationToken = default) { this.gameObject.SetActive(true); foreach (var behaviour in _behaviours) { await behaviour.WaitAsync(cancellationToken); current.Value++; } this.gameObject.SetActive(false); } } }