29 lines
799 B
C#
29 lines
799 B
C#
// An interface to represent a pre-configured action performed asynchronously
|
|
// on a block. Implements a Run() method that executes the action and provides an
|
|
// Enumerator to monitor when the action is complete.
|
|
|
|
using System.Collections.Generic;
|
|
|
|
namespace IngameScript
|
|
{
|
|
partial class Program
|
|
{
|
|
public abstract class BlockAction
|
|
{
|
|
public bool Running { get; private set; } = false;
|
|
|
|
public IEnumerator<bool> Run()
|
|
{
|
|
if (Running) yield break;
|
|
Running = true;
|
|
|
|
IEnumerator<bool> childRun = onRun();
|
|
while (childRun.MoveNext()) yield return true;
|
|
|
|
Running = false;
|
|
}
|
|
|
|
protected abstract IEnumerator<bool> onRun();
|
|
}
|
|
}
|
|
} |