当前位置: 首页>>代码示例>>C#>>正文


C# Transition.Update方法代码示例

本文整理汇总了C#中Transition.Update方法的典型用法代码示例。如果您正苦于以下问题:C# Transition.Update方法的具体用法?C# Transition.Update怎么用?C# Transition.Update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Transition的用法示例。


在下文中一共展示了Transition.Update方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TestDelay

        public void TestDelay()
        {
            Transition t = new Transition();
              StateMachine sm = new StateMachine();

              var s = new State();
              s.Transitions.Add(t);
              sm.States.Add(s);
              Assert.AreEqual(s, t.SourceState);

              t.Delay = TimeSpan.FromSeconds(-1);
              Assert.AreEqual(t.Update(TimeSpan.FromSeconds(1)), false);

              t.Fire();
              Assert.AreEqual(t.Update(TimeSpan.FromSeconds(1)), true);

              t.Delay = TimeSpan.FromSeconds(10);
              Assert.AreEqual(t.Update(TimeSpan.FromSeconds(1)), false);
              t.Fire();
              Assert.AreEqual(t.Update(TimeSpan.FromSeconds(1)), false);  // Fire is registered. deltaTime of this update does not count.
              Assert.AreEqual(t.Update(TimeSpan.FromSeconds(1)), false);
              t.Fire();                                                   // A second fire is ignored - timer does not restart.
              Assert.AreEqual(t.Update(TimeSpan.FromSeconds(1)), false);
              Assert.AreEqual(t.Update(TimeSpan.FromSeconds(8)), true);   // 1 + 1 + 8 = 10 => Fire
              Assert.AreEqual(t.Update(TimeSpan.FromSeconds(1)), false);

              // Test with other time steps.
              t.Delay = TimeSpan.FromSeconds(10);
              t.Fire();
              Assert.AreEqual(t.Update(TimeSpan.FromSeconds(7)), false);
              Assert.AreEqual(t.Update(TimeSpan.FromSeconds(7)), true);

              // Test again with a reset in the middle.
              t.Delay = TimeSpan.FromSeconds(10);
              t.Fire();
              Assert.AreEqual(t.Update(TimeSpan.FromSeconds(1)), false);
              Assert.AreEqual(t.Update(TimeSpan.FromSeconds(1)), false);
              Assert.AreEqual(t.Update(TimeSpan.FromSeconds(1)), false);
              t.SourceState.EnterState(null, new StateEventArgs());             // Reset. Transition should not fire anymore.
              Assert.AreEqual(t.Update(TimeSpan.FromSeconds(10)), false);
              Assert.AreEqual(t.Update(TimeSpan.FromSeconds(10)), false);
        }
开发者ID:,项目名称:,代码行数:42,代码来源:

示例2: TestBasics

        public void TestBasics()
        {
            Transition t = new Transition();
              t.SourceState = new State();

              // Not fired.
              Assert.AreEqual(t.Update(TimeSpan.FromSeconds(1)), false);

              // Fired.
              t.Fire();
              Assert.AreEqual(t.Update(TimeSpan.FromSeconds(1)), true);
              Assert.AreEqual(t.Update(TimeSpan.FromSeconds(1)), false);

              // Fired.
              t.Fire(null, null);
              Assert.AreEqual(t.Update(TimeSpan.FromSeconds(1)), true);
              Assert.AreEqual(t.Update(TimeSpan.FromSeconds(1)), false);

              // FireAlways
              t.FireAlways = true;
              Assert.AreEqual(t.Update(TimeSpan.FromSeconds(1)), true);

              // FireAlways with Guard
              t.Guard = () => false;
              Assert.AreEqual(t.Update(TimeSpan.FromSeconds(1)), false);
              t.Guard = () => true;
              Assert.AreEqual(t.Update(TimeSpan.FromSeconds(1)), true);

              // Fire with Guard
              t.FireAlways = false;
              t.Guard = () => false;
              t.Fire();
              Assert.AreEqual(t.Update(TimeSpan.FromSeconds(1)), false);
              t.Guard = () => true;
              t.Fire();
              Assert.AreEqual(t.Update(TimeSpan.FromSeconds(1)), true);
        }
开发者ID:,项目名称:,代码行数:37,代码来源:


注:本文中的Transition.Update方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。