62 lines
830 B
C#
62 lines
830 B
C#
using System.Collections;
|
|
|
|
namespace BF
|
|
{
|
|
public class Task
|
|
{
|
|
int taskID;
|
|
IEnumerator coroutine;
|
|
|
|
public bool Running { get; private set;}
|
|
public bool Paused { get; private set; }
|
|
|
|
public Task(int taskID, IEnumerator c)
|
|
{
|
|
this.taskID = taskID;
|
|
coroutine = c;
|
|
Running = true;
|
|
}
|
|
|
|
public void Stop()
|
|
{
|
|
Running = false;
|
|
}
|
|
|
|
public void Pause()
|
|
{
|
|
Paused = true;
|
|
}
|
|
|
|
public void Unpause()
|
|
{
|
|
Paused = false;
|
|
}
|
|
|
|
public IEnumerator CallWrapper()
|
|
{
|
|
yield return null;
|
|
|
|
while (Running)
|
|
{
|
|
if (Paused)
|
|
{
|
|
yield return null;
|
|
}
|
|
else
|
|
{
|
|
var e = coroutine;
|
|
if (e != null && e.MoveNext())
|
|
{
|
|
yield return e.Current;
|
|
}
|
|
else
|
|
{
|
|
Running = false;
|
|
}
|
|
}
|
|
}
|
|
|
|
BFMain.Instance.TaskMgr.RemoveTask(taskID);
|
|
}
|
|
}
|
|
} |