69 lines
1.7 KiB
C#
69 lines
1.7 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using NBC;
|
|
|
|
namespace NBF
|
|
{
|
|
/// <summary>
|
|
/// 默认任务运行器
|
|
/// </summary>
|
|
public class DefRunner : Runner
|
|
{
|
|
private static DefRunner mUpdateRunner;
|
|
public static DefRunner Scheduler => mUpdateRunner ??= new DefRunner();
|
|
|
|
private readonly List<IProcess> _updateRoutines = new List<IProcess>();
|
|
|
|
private static bool _pause;
|
|
|
|
public event Action OnUpdate;
|
|
|
|
/// <summary>
|
|
/// 暂停运行器
|
|
/// </summary>
|
|
public static bool Pause
|
|
{
|
|
get => _pause;
|
|
set => _pause = value;
|
|
}
|
|
|
|
public DefRunner()
|
|
{
|
|
MonoManager.Inst.OnUpdate += Update;
|
|
StartCoroutine(new RunnerProcess("DefRunner", Coroutines, ReadyTask, FlushingOperation));
|
|
}
|
|
|
|
private void StartCoroutine(IProcess process)
|
|
{
|
|
var routines = _updateRoutines;
|
|
if (!routines.Contains(process))
|
|
{
|
|
routines.Add(process);
|
|
}
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
if (Pause) return;
|
|
ExecuteRoutines(_updateRoutines);
|
|
OnUpdate?.Invoke();
|
|
}
|
|
|
|
private void ExecuteRoutines(List<IProcess> arr)
|
|
{
|
|
if (arr != null && arr.Count > 0)
|
|
{
|
|
for (var index = 0; index < arr.Count; index++)
|
|
{
|
|
var task = arr[index];
|
|
var st = task.Process();
|
|
if (st == NTaskStatus.Success)
|
|
{
|
|
arr.RemoveAt(index);
|
|
index--;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} |