コード例 #1
0
        public void TaskStack_TwoTasksThenOne()
        {
            var taskStack = new MTaskStack();
            var num       = new MInt(5);
            var a         = new MTask((t) => num.Value == 4);
            var b         = new MTask((t) => num.Value == 3);
            var c         = new MTask((t) => num.Value == 2);

            c.OnComplete += () => num.Value = 0;
            taskStack.PushQueue(a);
            taskStack.PushQueue(b);

            num.Value--;
            taskStack.Evaluate();

            Assert.AreSame(b, taskStack.Current);

            num.Value--;
            taskStack.Evaluate();
            taskStack.Evaluate();

            taskStack.PushQueue(c);
            taskStack.Evaluate();
            num.Value = 2;
            taskStack.Evaluate();

            Assert.AreEqual(0, num.Value);
            Assert.AreEqual(0, taskStack.Count);
        }
コード例 #2
0
        public void TaskStack_ThreeQueuedThreeCapacity()
        {
            var taskStack = new MTaskStack(3);
            var num       = new MInt(5);
            var a         = new MTask((t) => num.Value == 4);
            var b         = new MTask((t) => num.Value == 3);
            var c         = new MTask((t) => num.Value == 2);

            c.OnComplete += () => num.Value = 0;
            taskStack.PushQueue(a);
            taskStack.PushQueue(b);
            taskStack.PushQueue(c);

            Assert.AreSame(c, taskStack.Next);

            Assert.AreEqual(3, taskStack.Count);
        }
コード例 #3
0
        public void TaskStack_SingleCompleted()
        {
            var taskStack = new MTaskStack();
            var num       = new MInt(5);
            var a         = new MTask((t) => num.Value == 4);

            a.OnComplete += () => num.Value = 0;
            taskStack.PushQueue(a);
            num.Value--;
            taskStack.Evaluate();

            Assert.That(num.Value == 0);
            Assert.AreEqual(0, taskStack.Count);
        }
コード例 #4
0
 private void OnMouseDown()
 {
     if (FSM.CurrentState == _red)
     {
         FSM.ChangeState(_green);
         Debug.Log("Green");
         var task = new MTimerTask((t) => t is MTimerTask tt && tt.Timer.Elapsed > 2);
         task.OnComplete += () => FSM.ChangeState(_blue);
         task.Timer.Start();
         _tasks.PushQueue(task);
     }
     else if (FSM.CurrentState == _green)
     {
         FSM.ChangeState(_blue);
         Debug.Log("Blue");
     }
     else
     {
         FSM.ChangeState(_red);
         Debug.Log("Red");
     }
 }