本文整理汇总了C#中FSM.AddState方法的典型用法代码示例。如果您正苦于以下问题:C# FSM.AddState方法的具体用法?C# FSM.AddState怎么用?C# FSM.AddState使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FSM
的用法示例。
在下文中一共展示了FSM.AddState方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ShouldExecuteOnEnterWhenEnteringNextState
public void ShouldExecuteOnEnterWhenEnteringNextState()
{
var exit_here = false;
var fsm = new FSM<string>();
fsm.AddState("start_here");
fsm.AddState("exit_here", input => exit_here = true);
fsm.AddTransition("start_here", "exit_here", input => true);
fsm.Step();
Assert.That(exit_here, Is.True);
}
示例2: ShouldExecuteOnExitWhenLeavingCurrentState
public void ShouldExecuteOnExitWhenLeavingCurrentState()
{
var was_here = false;
var fsm = new FSM<string>();
fsm.AddState("start_here", null, input => was_here = true);
fsm.AddState("exit_here");
fsm.AddTransition("start_here", "exit_here", input => true);
fsm.Step();
Assert.That(was_here, Is.True);
}
示例3: ShouldEvaluateTransitionCondition
public void ShouldEvaluateTransitionCondition()
{
var conditionEvaluated = false;
var fsm = new FSM<string>();
fsm.AddState("initial");
fsm.AddState("end");
fsm.AddTransition("initial", "end", input => { conditionEvaluated = true; return false; });
fsm.Step();
Assert.That(conditionEvaluated, Is.True);
}
示例4: ShouldEvaluateMultipleTransitionsUntilConditionIsMet
public void ShouldEvaluateMultipleTransitionsUntilConditionIsMet()
{
var fsm = new FSM<string>();
fsm.AddState("one");
fsm.AddState("two");
fsm.AddState("three");
fsm.AddTransition("one", "two", input => false);
fsm.AddTransition("one", "three", input => true);
fsm.Step();
Assert.That(fsm.CurrentState, Is.EqualTo("three"));
}
示例5: Form1
public Form1()
{
InitializeComponent();
phase_label.Text = GameState.init.ToString();
attack.Enabled = false;
enemy_attack.Enabled = false;
GAMEFSM = new FSM<GameState>(GameState.init);
GAMEFSM.AddState(GameState.init);
GAMEFSM.AddState(GameState.player);
GAMEFSM.AddState(GameState.enemy);
GAMEFSM.AddState(GameState.end);
GAMEFSM.AddTransition(GameState.init, GameState.player);
GAMEFSM.AddTransition(GameState.player, GameState.enemy);
GAMEFSM.AddTransition(GameState.enemy, GameState.player);
GAMEFSM.AddTransition(GameState.player, GameState.end);
GAMEFSM.AddTransition(GameState.enemy, GameState.end);
SuperSave = new SaveGameData();
}
示例6: Start
// Use this for initialization
void Start()
{
mFSM = new FSM();
FSM.State state = mFSM.AddState("A");
state.SetEnterMethod(delegate() { Debug.Log("Enter A " + a); });
state.SetTickMethod(delegate(float dt) { });
state.SetExitMethod(delegate() { Debug.Log("Exit A " + a); });
state = mFSM.AddState("B");
state.SetEnterMethod(delegate() { Debug.Log("Enter B" + a); });
state.SetTickMethod(delegate(float dt) { });
state.SetExitMethod(delegate() { Debug.Log("Exit B " + a); });
mFSM.addTransition("A", "B", "!(A2B1 & (A2B1 | A2B2)) & !OK");
mFSM.addTransition("B", "A", "(B2A | B2A)");
mFSM.Begin();
InvokeRepeating("Test", 3.0f, 6.0f);
}
示例7: Start
void Start()
{
_health = _maxHealth;
_fsm = new FSM<UnitStates>();
// Add States for the FSM
_fsm.AddState(UnitStates.INIT);
_fsm.AddState(UnitStates.IDLE);
_fsm.AddState(UnitStates.ATTACK);
_fsm.AddState(UnitStates.HIT);
_fsm.AddState(UnitStates.DEAD);
// Add transistion for the FSM
_fsm.AddTransition(UnitStates.INIT, UnitStates.IDLE);
_fsm.AddTransition(UnitStates.IDLE, UnitStates.ATTACK);
_fsm.AddTransition(UnitStates.ATTACK, UnitStates.IDLE);
_fsm.AddTransition(UnitStates.IDLE, UnitStates.HIT);
_fsm.AddTransition(UnitStates.HIT, UnitStates.IDLE);
_fsm.AddTransition(UnitStates.HIT, UnitStates.DEAD);
_fsm.Transition(_fsm.state, UnitStates.IDLE);
}
示例8: ShouldFollowTransitionIfConditionIsMet
public void ShouldFollowTransitionIfConditionIsMet()
{
var fsm = new FSM<string>();
fsm.AddState("start");
fsm.AddState("exit");
fsm.AddTransition("start", "exit", input => true);
fsm.Step();
Assert.That(fsm.CurrentState, Is.EqualTo("exit"));
}
示例9: ShouldExecuteTransitionAction
public void ShouldExecuteTransitionAction()
{
var action = false;
var fsm = new FSM<string>();
fsm.AddState("first");
fsm.AddState("second");
fsm.AddTransition("first", "second", input => true, input => action = true);
fsm.Step();
Assert.That(action, Is.True);
}
示例10: ShouldStartAtFirstState
public void ShouldStartAtFirstState()
{
var fsm = new FSM<string>();
fsm.AddState("initial");
fsm.AddState("end");
Assert.That(fsm.CurrentState, Is.EqualTo("initial"));
}
示例11: ShouldNotExecuteOnEnterWhenInInitialState
public void ShouldNotExecuteOnEnterWhenInInitialState()
{
var fsm = new FSM<string>();
var onEnter = false;
fsm.AddState("initial", input => onEnter = true);
fsm.Step();
Assert.That(onEnter, Is.False);
}
示例12: ShouldNotBeFinishedWhenCurrentHasTransitions
public void ShouldNotBeFinishedWhenCurrentHasTransitions()
{
var fsm = new FSM<string>();
fsm.AddState("one");
fsm.AddState("two");
fsm.AddTransition("one", "two", input => true);
Assert.That(fsm.Finished, Is.False);
}
示例13: ShouldBeFinishedWhenCurrentStateHasNoTransitions
public void ShouldBeFinishedWhenCurrentStateHasNoTransitions()
{
var fsm = new FSM<string>();
fsm.AddState("a state");
Assert.That(fsm.Finished, Is.True);
}
示例14: Start
// Use this for initialization
void Start ()
{
// Console.ForegroundColor = ConsoleColor.Green;
fsm = new FSM("Jave's FSM");
Debug.Log(string.Format("Start testing :{0}", fsm));
// add event show cur state changed info
fsm.CurStateChangedEvent += (CurStateChangedEventHandler)((sender) =>
{
Debug.Log(string.Format("state changed, last : {0}, cur : {1}", fsm.LastState, fsm.CurState));
});
// add event show params changed info
fsm.ParamsChangedEvent += (ParamsChangedEventHandler)((sender, paramChangedArgs) =>
{
//Debug.Log(string.Format(
// "param:{1}, src:{2}, to: {3}",
// fsm, paramChangedArgs.CurValue.Name, paramChangedArgs.LastValue.Value, paramChangedArgs.CurValue.Value));
});
// add some states
fsm.AddState(new MyIdle(IDLE));
fsm.AddState(new MyRun(RUN));
fsm.AddState(new MyFly(FLY));
fsm.AddState(new MyDead(DEAD));
// set any state
fsm.AnyState = new MyAnyState("any state");
// set cur state
fsm.CurState = fsm.GetState(IDLE);
// add some into fsm black board, u can add anythings for every states to calcs
fsm.Blackboard.AddData("Boss", new Boss());
// add fsm some params
fsm.AddParam(new ParamFunc(P_GRAVITY_FUNC_1, (FuncParamHandler)(funcArgs => // Param can be a func, handl complex logic
{
return fsm.GetParamValue<int>(P_SPEED) > 15 && fsm.GetParamValue<int>(P_HP) > 0 && fsm.GetParamValue<int>(P_GRAVITY) <= 0;
})));
fsm.AddParam(new ParamFunc(P_GRAVITY_FUNC_2, (FuncParamHandler)(funcArgs => // Param can be a func, handl complex logic
{
return fsm.GetParamValue<int>(P_SPEED) < 15 && fsm.GetParamValue<int>(P_HP) > 0;
})));
fsm.AddParam(new ParamValue(P_GRAVITY) { Value = 10 }); // init gravity = 10;
fsm.AddParam(new ParamBoolean(P_GRAVITY_ENABLED) { Value = true }); // init gravity_enabled = true
fsm.AddParam(new ParamValue(P_SPEED) { Value = 0 }); // init speed = 0;
fsm.AddParam(new ParamValue(P_HP) { Value = 100 }); // init hp = 100
// idle state add some transition to run
FSM.TransitionTo(fsm, IDLE, RUN, new List<Condition>() { COND_GE_10_SPEED, COND_ALIVE_HP });
// run back to idle
FSM.TransitionTo(fsm, RUN, IDLE, new List<Condition>() { COND_L_10_SPEED, COND_ALIVE_HP });
// run to fly
FSM.TransitionTo(fsm, RUN, FLY, new List<Condition>() { COND_GRAVITY_FUNC_1 });
// back to run
FSM.TransitionTo(fsm, FLY, RUN, new List<Condition>() { COND_GRAVITY_FUNC_2, COND_E_TRUE_GRAVITY_ENABLE });
// every state to fly, except dead
ToFly(fsm, IDLE); ToFly(fsm, RUN);
// idle, run, fly, and so on, states add some transition to dead state's transitions.
ToDead(fsm, IDLE); ToDead(fsm, RUN); ToDead(fsm, FLY);
// dead back to alive(idle)
FSM.TransitionTo(fsm, DEAD, IDLE, new List<Condition>() { COND_ALIVE_HP });
// dummy fsm update task
// DummyFsmUpdate(fsm);
Console.ReadLine();
}