scornflake
New member
What's the recommended way to code up an action, such that it'll return TaskStatus.Running until its completed? I'm thinking here of a long running coroutine (over a number of seconds).
public class CoroutineAction : Action
{
public bool IsRunning = false;
public override void OnStart()
{
StartCoroutine(CoroutineWithEndingBit());
}
private IEnumerator CoroutineWithEndingBit()
{
IsRunning = true;
yield return TasksCoroutine();
IsRunning = false;
}
protected IEnumerator TasksCoroutine()
{
for (int i = 0; i < 50; i++)
{
yield return new WaitForSeconds(1);
Debug.Log($"Waiting.... {i}");
}
yield return null;
}
public override TaskStatus OnUpdate()
{
return IsRunning ? TaskStatus.Running : TaskStatus.Success;
}
}