本文整理汇总了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);
}
示例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);
}