本文整理汇总了C#中StateMachine.AddTransitionCallback方法的典型用法代码示例。如果您正苦于以下问题:C# StateMachine.AddTransitionCallback方法的具体用法?C# StateMachine.AddTransitionCallback怎么用?C# StateMachine.AddTransitionCallback使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StateMachine
的用法示例。
在下文中一共展示了StateMachine.AddTransitionCallback方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Test1
public void Test1()
{
#region Creating the state machine instance called machine
var machine = new StateMachine<States>();
machine.AddState(States.R);
machine.AddState(States.G);
machine.AddState(States.B);
machine.AddTransition(States.R, States.G);
machine.AddTransition(States.G, States.B);
#endregion
string EnteringCallbackMsg = "", ExitingCallbackMsg = "", TransistionCallback = "";
string TransitingEventMsg = "", TransitedEventMsg = "";
#region Adding callbacks to machine
Action<States> EnteringCallback = (state) => EnteringCallbackMsg = String.Format("Entering state {0}", state);
machine.AddEnterStateCallback(States.R, EnteringCallback.Invoke);
machine.AddEnterStateCallback(States.G, EnteringCallback.Invoke);
machine.AddEnterStateCallback(States.B, EnteringCallback.Invoke);
Action<States> ExitingCallback = (state) => ExitingCallbackMsg = String.Format("Exiting state {0}", state);
machine.AddExitStateCallback(States.R, ExitingCallback.Invoke);
machine.AddExitStateCallback(States.G, ExitingCallback.Invoke);
machine.AddExitStateCallback(States.B, ExitingCallback.Invoke);
Action<States, States> TransitionCallback = (from, to) => TransistionCallback = String.Format("Going from {0} to {1}", from, to);
machine.AddTransitionCallback(States.R, States.G, TransitionCallback.Invoke);
machine.AddTransitionCallback(States.G, States.B, TransitionCallback.Invoke);
#endregion
#region Adding events to machine
machine.Transiting += new EventHandler<TransitingEventArgs<States>>((s, e) => TransitingEventMsg = String.Format("Event Fired: Transiting into state {0}", e.State));
machine.Transited += new EventHandler<TransitedEventArgs<States>>( (s, e) => TransitedEventMsg = String.Format("Event Fired: Transited into state {0}", e.State));
#endregion
#region Testing machine
Assert.AreEqual(machine.CurrentState, null);
machine.GoToState(States.R);
Assert.AreEqual(machine.CurrentState.Name, States.R);
Assert.AreEqual(ExitingCallbackMsg, "");
Assert.AreEqual(TransistionCallback, "");
Assert.AreEqual(EnteringCallbackMsg, "Entering state R");
Assert.AreEqual(TransitingEventMsg, "Event Fired: Transiting into state R");
Assert.AreEqual(TransitedEventMsg, "Event Fired: Transited into state R");
machine.GoToState(States.G);
Assert.AreEqual(machine.CurrentState.Name, States.G);
Assert.AreEqual(ExitingCallbackMsg, "Exiting state R");
Assert.AreEqual(TransistionCallback, "Going from R to G");
Assert.AreEqual(EnteringCallbackMsg, "Entering state G");
Assert.AreEqual(TransitingEventMsg, "Event Fired: Transiting into state G");
Assert.AreEqual(TransitedEventMsg, "Event Fired: Transited into state G");
machine.GoToState(States.B);
Assert.AreEqual(machine.CurrentState.Name, States.B);
Assert.AreEqual(ExitingCallbackMsg, "Exiting state G");
Assert.AreEqual(TransistionCallback, "Going from G to B");
Assert.AreEqual(EnteringCallbackMsg, "Entering state B");
Assert.AreEqual(TransitingEventMsg, "Event Fired: Transiting into state B");
Assert.AreEqual(TransitedEventMsg, "Event Fired: Transited into state B");
#endregion
}