namespace Guru { using System; using System.Collections; using System.Collections.Generic; public class ThreadHandler: IUpdater { private Queue _actions; public Queue Actions { get { if(_actions == null) _actions = new Queue(10); return _actions; } set { if (value != null) _actions = value; } } private UpdaterState _state; public UpdaterState State => _state; /// /// 启动 Updater /// public void Start() { _state = UpdaterState.Running; } /// /// 执行方案 /// public void OnUpdate() { if (Actions.Count > 0) { // 消耗对垒 while (Actions.Count > 0) { Actions.Dequeue()?.Invoke(); } } } public void Pause(bool pause = true) { _state = pause ? UpdaterState.Pause : UpdaterState.Running; } /// /// 删除对象 /// public void Kill() { _state = UpdaterState.Kill; } public void Dispose() { _actions.Clear(); _state = UpdaterState.Kill; } public void AddAction(Action action) { if (action == null) return; Actions.Enqueue(action); } } }