本文整理汇总了C#中FiniteStateMachine.AddTransition方法的典型用法代码示例。如果您正苦于以下问题:C# FiniteStateMachine.AddTransition方法的具体用法?C# FiniteStateMachine.AddTransition怎么用?C# FiniteStateMachine.AddTransition使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FiniteStateMachine
的用法示例。
在下文中一共展示了FiniteStateMachine.AddTransition方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Awake
void Awake()
{
mainFSM = new FiniteStateMachine<State>();
mainFSM.AddTransition(State.Initialize, State.SetupNewGame, null, InitializeNewGame, OnSettingUpNewGame);
mainFSM.AddTransition(State.SetupNewGame, State.Game, null, () => StartCoroutine(InitializeGameLogicStuff()), null);
mainFSM.AddTransition(State.Game, State.GameOver, OnGameIsOver);
mainFSM.AddTransition(State.GameOver, State.Restart, null);
mainFSM.AddTransition(State.Restart, State.SetupNewGame, null, InitializeNewGame, null);
mainFSM.AddTransition(State.Restart, State.Quit, null);
mainFSM.StateChanged += (object s, EventArgs e) => {
Debug.Log("state: " + mainFSM.CurrentState.ToString() + " | game state: " + gameFSM.CurrentState.ToString());
};
gameFSM = new FiniteStateMachine<GameState>();
gameFSM.AddTransition(GameState.Idle, GameState.InGameMenu, OnInGameMenuOpened);
gameFSM.AddTransition(GameState.InGameMenu, GameState.Idle, OnInGameMenuClosed);
gameFSM.StateChanged += (object s, EventArgs e) => {
Debug.Log("state: " + mainFSM.CurrentState.ToString() + " | game state: " + gameFSM.CurrentState.ToString());
};
GameIsOver += (object s, EventArgs e) => { Debug.Log("oh no!"); };
InGameMenuOpened += (object s, EventArgs e) => { Time.timeScale = 0f; Debug.Log("PAUSED"); };
InGameMenuClosed += (object s, EventArgs e) => { Time.timeScale = 1f; Debug.Log("UNPAUSED"); };
igm = GetComponent<InGameMenu>();
mainFSM.ChangeState(State.SetupNewGame);
}
示例2: AIProperty
public AIProperty()
{
IsActive = true;
StateMachine = new FiniteStateMachine();
// basic behaviors!
StateMachine.AddState("idle", 2, 3);
StateMachine.AddState("move", 2, 2);
StateMachine.AddTransition("idle", "move", .5);
StateMachine.AddTransition("move", "idle", .5);
// Pick our first state.
StateMachine.SetState("idle");
}
示例3: DebugClickTimedToggle
static void DebugClickTimedToggle(FiniteStateMachine fsm)
{
FiniteState start_state = new FiniteState();//ScriptableObject.CreateInstance<FiniteState>();
FiniteState red_state = new FiniteState();//ScriptableObject.CreateInstance<FiniteState>();
FiniteState green_state = new FiniteState();//ScriptableObject.CreateInstance<FiniteState>();
start_state.StateName = "Start";
red_state.StateName = "Red";
green_state.StateName = "Green";
{
red_state.EnterAction = fsm.gameObject.AddComponent<StateActions.SA_ChangeColor>() as IStateAction;
StateActions.SA_ChangeColor sa = red_state.EnterAction as StateActions.SA_ChangeColor;
sa.NewColor = Color.red;
}
{
green_state.EnterAction = fsm.gameObject.AddComponent<StateActions.SA_ChangeColor>() as IStateAction;
StateActions.SA_ChangeColor sa = green_state.EnterAction as StateActions.SA_ChangeColor;
sa.NewColor = Color.green;
}
{
Transitions.OnMouseClick t = fsm.AddTransition(start_state,typeof(Transitions.OnMouseClick),red_state) as Transitions.OnMouseClick;
t.Name = "click_start";
}
{
Transitions.OnMouseClick t = fsm.AddTransition(red_state,typeof(Transitions.OnMouseClick),green_state) as Transitions.OnMouseClick;
t.Name = "click_red";
}
{
Transitions.OnMouseClick t = fsm.AddTransition(green_state,typeof(Transitions.OnMouseClick),red_state) as Transitions.OnMouseClick;
t.Name = "click_green";
}
{
Transitions.OnTimer2 t = fsm.AddTransition(green_state,typeof(Transitions.OnTimer2),red_state) as Transitions.OnTimer2;
t.Name = "click_green";
t.Delay = 2;
}
fsm.ChangeState(start_state);
}
示例4: Main
public static void Main(String[] Args)
{
var FSM1 = new FiniteStateMachine<State, Signal>("FSM1");
FSM1.AddTransition(State.Start, Signal.Hello, () => Console.WriteLine("Hello received!"), State.Middle);
FSM1.AddTransition(State.Middle, Signal.World, () => Console.WriteLine("World received!"), State.End);
Console.WriteLine(FSM1.CurrentState);
FSM1.ProcessSignal(Signal.Hello);
Console.WriteLine(FSM1.CurrentState);
FSM1.ProcessSignal(Signal.GoToHell);
Console.WriteLine(FSM1.CurrentState);
FSM1.ProcessSignal(Signal.Hello);
Console.WriteLine(FSM1.CurrentState);
}
示例5: DebugToggleMultiColor
static void DebugToggleMultiColor(FiniteStateMachine fsm)
{
FiniteState start_state = new FiniteState();//ScriptableObject.CreateInstance<FiniteState>();
FiniteState red_state = new FiniteState();//ScriptableObject.CreateInstance<FiniteState>();
FiniteState green_state = new FiniteState();//ScriptableObject.CreateInstance<FiniteState>();
FiniteState blue_state = new FiniteState();//ScriptableObject.CreateInstance<FiniteState>();
FiniteState yellow_state = new FiniteState();//ScriptableObject.CreateInstance<FiniteState>();
FiniteState magenta_state = new FiniteState();//ScriptableObject.CreateInstance<FiniteState>();
start_state.StateName = "Start";
red_state.StateName = "Red";
green_state.StateName = "Green";
blue_state.StateName = "blue";
yellow_state.StateName = "yellow";
magenta_state.StateName = "magenta";
{
red_state.EnterAction = fsm.gameObject.AddComponent<StateActions.SA_ChangeColor>() as IStateAction;
StateActions.SA_ChangeColor sa = red_state.EnterAction as StateActions.SA_ChangeColor;
sa.NewColor = Color.red;
}
{
green_state.EnterAction = fsm.gameObject.AddComponent<StateActions.SA_ChangeColor>() as IStateAction;
StateActions.SA_ChangeColor sa = green_state.EnterAction as StateActions.SA_ChangeColor;
sa.NewColor = Color.green;
}
{
blue_state.EnterAction = fsm.gameObject.AddComponent<StateActions.SA_ChangeColor>() as IStateAction;
StateActions.SA_ChangeColor sa = blue_state.EnterAction as StateActions.SA_ChangeColor;
sa.NewColor = Color.blue;
}
{
yellow_state.EnterAction = fsm.gameObject.AddComponent<StateActions.SA_ChangeColor>() as IStateAction;
StateActions.SA_ChangeColor sa = yellow_state.EnterAction as StateActions.SA_ChangeColor;
sa.NewColor = Color.yellow;
}
{
magenta_state.EnterAction = fsm.gameObject.AddComponent<StateActions.SA_ChangeColor>() as IStateAction;
StateActions.SA_ChangeColor sa = magenta_state.EnterAction as StateActions.SA_ChangeColor;
sa.NewColor = Color.magenta;
}
{
Transitions.OnTimer2 t = fsm.AddTransition(start_state,typeof(Transitions.OnTimer2),red_state) as Transitions.OnTimer2;
t.Name = "timer_start";
t.Delay = 1.0f;
}
{
Transitions.OnTimer2 t = fsm.AddTransition(red_state,typeof(Transitions.OnTimer2),green_state) as Transitions.OnTimer2;
t.Name = "timer_red";
t.Delay = Random.value * 10.0f;
}
{
Transitions.OnTimer2 t = fsm.AddTransition(green_state,typeof(Transitions.OnTimer2),blue_state) as Transitions.OnTimer2;
t.Name = "timer_green";
t.Delay = Random.value * 10.0f;
}
{
Transitions.OnTimer2 t = fsm.AddTransition(blue_state,typeof(Transitions.OnTimer2),yellow_state) as Transitions.OnTimer2;
t.Name = "timer_blue";
t.Delay = Random.value * 10.0f;
}
{
Transitions.OnTimer2 t = fsm.AddTransition(yellow_state,typeof(Transitions.OnTimer2),magenta_state) as Transitions.OnTimer2;
t.Name = "timer_yellow";
t.Delay = Random.value * 10.0f;
}
{
Transitions.OnTimer2 t = fsm.AddTransition(magenta_state,typeof(Transitions.OnTimer2),red_state) as Transitions.OnTimer2;
t.Name = "timer_magenta";
t.Delay = Random.value * 10.0f;
}
fsm.ChangeState(start_state);
}
示例6: DebugTest
static void DebugTest(FiniteStateMachine fsm)
{
FiniteState start_state = new FiniteState();//ScriptableObject.CreateInstance<FiniteState>();
FiniteState red_state = new FiniteState();//ScriptableObject.CreateInstance<FiniteState>();
FiniteState green_state = new FiniteState();//ScriptableObject.CreateInstance<FiniteState>();
start_state.StateName = "Start";
red_state.StateName = "Red";
green_state.StateName = "Green";
{
red_state.EnterAction = fsm.gameObject.AddComponent<StateActions.SA_ChangeColor>() as IStateAction;
StateActions.SA_ChangeColor sa = red_state.EnterAction as StateActions.SA_ChangeColor;
sa.NewColor = Color.red;
}
{
red_state.ExitAction = fsm.gameObject.AddComponent<StateActions.SA_SetVariable>() as IStateAction;
StateActions.SA_SetVariable sa = red_state.ExitAction as StateActions.SA_SetVariable;
sa.Value = new Vector3(1,2,3);
}
{
green_state.EnterAction = fsm.gameObject.AddComponent<StateActions.SA_ChangeColor>() as IStateAction;
StateActions.SA_ChangeColor sa = green_state.EnterAction as StateActions.SA_ChangeColor;
sa.NewColor = Color.green;
}
{
green_state.ExitAction = fsm.gameObject.AddComponent<StateActions.SA_SetScriptVariable>() as IStateAction;
StateActions.SA_SetScriptVariable sa = green_state.ExitAction as StateActions.SA_SetScriptVariable;
sa.ScriptName = "SimpleScript";
sa.ValueName = "Position";
sa.Value = new Vector3(42,43,44);
}
{
Transitions.OnMouseClick t = fsm.AddTransition(start_state,typeof(Transitions.OnMouseClick),red_state) as Transitions.OnMouseClick;
t.Name = "click_start";
}
{
Transitions.OnMouseClick t = fsm.AddTransition(red_state,typeof(Transitions.OnMouseClick),green_state) as Transitions.OnMouseClick;
t.Name = "click_red";
}
{
Transitions.OnMouseClick t = fsm.AddTransition(green_state,typeof(Transitions.OnMouseClick),red_state) as Transitions.OnMouseClick;
t.Name = "click_green";
}
fsm.ChangeState(start_state);
}
示例7: DebugPressurePlateLight
static void DebugPressurePlateLight(FiniteStateMachine fsm)
{
FiniteState unpressed_state = new FiniteState();//ScriptableObject.CreateInstance<FiniteState>();
FiniteState pressed_state = new FiniteState();//ScriptableObject.CreateInstance<FiniteState>();
{
//unpressed_state.EnterAction = fsm.gameObject.AddComponent<StateActions.SA_PressurePlateLight>() as IStateAction;
//StateActions.SA_PressurePlateLight sa = unpressed_state.EnterAction as StateActions.SA_PressurePlateLight;
//sa.State = false;
}
{
pressed_state.EnterAction = fsm.gameObject.AddComponent<StateActions.SA_PressurePlateLight>() as IStateAction;
StateActions.SA_PressurePlateLight sa = pressed_state.EnterAction as StateActions.SA_PressurePlateLight;
sa.State = true;
}
{
Transitions.OnTriggerEnterTransition t = fsm.AddTransition(unpressed_state,typeof(Transitions.OnTriggerEnterTransition),pressed_state) as Transitions.OnTriggerEnterTransition;
t.Name = "trigger_enter";
}
{
Transitions.OnTriggerExitTransition t = fsm.AddTransition(pressed_state,typeof(Transitions.OnTriggerExitTransition),unpressed_state) as Transitions.OnTriggerExitTransition;
t.Name = "trigger_exit";
}
fsm.ChangeState(unpressed_state);
}
示例8: DebugPressurePlate
static void DebugPressurePlate(FiniteStateMachine fsm)
{
FiniteState unpressed_state = new FiniteState();//ScriptableObject.CreateInstance<FiniteState>();
FiniteState pressed_state = new FiniteState();//ScriptableObject.CreateInstance<FiniteState>();
{
unpressed_state.EnterAction = fsm.gameObject.AddComponent<StateActions.SA_PressurePlateColor>() as IStateAction;
StateActions.SA_PressurePlateColor sa = unpressed_state.EnterAction as StateActions.SA_PressurePlateColor;
sa.NewColor = Color.red;
}
{
pressed_state.EnterAction = fsm.gameObject.AddComponent<StateActions.SA_PressurePlateColor>() as IStateAction;
StateActions.SA_PressurePlateColor sa = pressed_state.EnterAction as StateActions.SA_PressurePlateColor;
sa.NewColor = Color.green;
}
{
Transitions.OnTriggerEnterTransition t = fsm.AddTransition(unpressed_state,typeof(Transitions.OnTriggerEnterTransition),pressed_state) as Transitions.OnTriggerEnterTransition;
t.Name = "trigger_enter";
}
{
Transitions.OnTriggerExitTransition t = fsm.AddTransition(pressed_state,typeof(Transitions.OnTriggerExitTransition),unpressed_state) as Transitions.OnTriggerExitTransition;
t.Name = "trigger_exit";
}
fsm.ChangeState(unpressed_state);
}
示例9: Start
void Start()
{
_myTransform = transform;
Text.renderer.enabled = false;
_fsm = new FiniteStateMachine("start state", StartState);
_fsm.AddState("say hello", SayHello);
_fsm.AddEvent("go and say hello", "start state", "say hello");
_fsm.AddEvent("say goodbye and go away", "say hello", "start state");
_fsm.AddTransition("start state", "say hello", ()=> MoveTo(Target));
_fsm.AddTransition("say hello", "start state", ()=> MoveTo(End));
}