Exemple #1
0
        public void CancelTest()
        {
            var timer      = App.Instance.Make <ITimerManager>();
            var statu      = 0;
            var isComplete = false;

            ITimerQueue queue = null;

            queue = timer.MakeQueue(() =>
            {
                timer.Make(() =>
                {
                    timer.Cancel(queue);
                    statu++;
                }).DelayFrame(1);

                timer.Make(() =>
                {
                    statu++;
                }).Delay(0.1f);

                timer.Make(() =>
                {
                    statu++;
                }).Delay(0.3f);
            }).OnComplete(() =>
            {
                isComplete = true;
            });

            RunFrame(App.Instance, 5);

            Assert.AreEqual(2, statu);
            Assert.AreEqual(false, isComplete);
        }
Exemple #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="TriggerBasedUpdate"/> class. After creating this instance, set some of the timing parameters, and then subscribe to the <see cref="UpdateAction"/> event. This will activate the instance.
        /// </summary>
        /// <param name="queue">The underlying queue (in most cases you should use <see cref="Current.TimerQueue"/>.</param>
        /// <exception cref="System.ArgumentNullException">queue</exception>
        public TriggerBasedUpdate(ITimerQueue queue)
        {
            if (null == queue)
            {
                throw new ArgumentNullException("queue");
            }

            _timerQueue = queue;
        }
        public void PauseTest()
        {
            var timer      = App.Make <ITimerManager>();
            var statu      = 0;
            var isComplete = false;

            ITimerQueue queue = null;

            queue = timer.MakeQueue(() =>
            {
                timer.Make(() =>
                {
                    timer.Pause(queue);
                    statu++;
                }).DelayFrame(1);

                timer.Make(() =>
                {
                    statu++;
                }).Delay(0.1f);

                timer.Make(() =>
                {
                    statu++;
                }).Delay(0.3f);
            }).OnCompleted(() =>
            {
                isComplete = true;
            });

            RunFrame(App.Handler, 5);

            Assert.AreEqual(2, statu);
            Assert.AreEqual(false, isComplete);
            Assert.AreEqual(true, queue.IsPause);

            timer.Play(queue);

            RunFrame(App.Handler, 5);

            Assert.AreEqual(3, statu);
            Assert.AreEqual(true, isComplete);
            Assert.AreEqual(false, queue.IsPause);
        }
Exemple #4
0
 /// <summary>
 /// 创建一个计时器
 /// </summary>
 /// <param name="task">任务实现</param>
 /// <param name="queue">当前逻辑帧</param>
 /// <returns>执行的任务</returns>
 public Timer(ITimerQueue queue, Action task)
 {
     this.task  = task;
     Queue      = queue;
     isComplete = false;
 }