123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading;
- using System.Threading.Tasks;
- namespace StageController
- {
- public class Moveflow : List<Workflow>
- {
- public bool Done => this.All((e) => e.Done == true);
- public bool IsStoped = false;
- public bool IsPause = false;
- private bool Running = false;
- public event Action OnMoveflowDone;
- public void Start()
- {
- if (Done || IsStoped)
- throw new Exception("AlreadyDone");
- if (Running)
- throw new Exception("AlreadyStart");
- Running = true;
- new Task(() =>
- {
- foreach (var workflow in this)
- {
- workflow.Process();
- while ((!workflow.Judgement() || IsPause) && !IsStoped)
- {
- Thread.Sleep(50);
- }
- workflow.Done = true;
- if (IsStoped) return;
- }
- OnMoveflowDone?.Invoke();
- }).Start();
- }
- public void Stop()
- {
- IsStoped = true;
- }
- /// <summary>
- /// 暂停/继续
- /// </summary>
- public void Pause()
- {
- IsPause = !IsPause;
- }
- public void Add(Action a = null, Func<bool> j = null)
- {
- var workflow = new Workflow(this);
- if (a != null)
- workflow.Process = a;
- if (j != null)
- workflow.Judgement = j;
- Add(workflow);
- }
- }
- //public interface IMoveFlow
- //{
- // public static Moveflow ToCenter()
- // {
- // }
- // public static Moveflow OutStage() { }
- // public static Moveflow InStage() { }
- // public static Moveflow ResetStage() { }
- //}
- }
|