49 lines
1.3 KiB
C#
49 lines
1.3 KiB
C#
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<int> current = new AsyncReactiveProperty<int>(0);
|
|
[SerializeField]
|
|
private AwaitBehaviour[] _behaviours;
|
|
|
|
private void Reset()
|
|
{
|
|
this._behaviours = this
|
|
.transform
|
|
.Children()
|
|
.Select(_ => {
|
|
if (_.TryGetComponent<AwaitBehaviour>(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);
|
|
}
|
|
}
|
|
}
|