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


C# FiniteStateMachine.ChangeState方法代码示例

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


在下文中一共展示了FiniteStateMachine.ChangeState方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
    }
开发者ID:rafedb,项目名称:fsm_framework,代码行数:27,代码来源:GameManager.cs

示例2: Awake

    protected void Awake()
    {
        _fsm = new FiniteStateMachine();

        _fsm.AddState(new MonsterWanderState(gameObject));

        _fsm.ChangeState(new FSMTransition(MonsterState.Wander));
    }
开发者ID:jtuttle,项目名称:umbra-client,代码行数:8,代码来源:MonsterAI.cs

示例3: Awake

	protected void Awake() {
		_fsm = new FiniteStateMachine();

		_fsm.AddState(new GameCreateState());
		_fsm.AddState(new GameResetState());
		_fsm.AddState(new GamePlayState());
		_fsm.AddState(new GameWinState());
		_fsm.AddState(new GameLoseState());

		_fsm.ChangeState(new FSMTransition(GameState.GameCreate));
	}
开发者ID:jtuttle,项目名称:ritual,代码行数:11,代码来源:GameController.cs

示例4: 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);
    }
开发者ID:mmvlad,项目名称:FiniteStateMachine,代码行数:46,代码来源:FiniteStateExamples.cs

示例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);
    }
开发者ID:mmvlad,项目名称:FiniteStateMachine,代码行数:84,代码来源:FiniteStateExamples.cs

示例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);
    }
开发者ID:mmvlad,项目名称:FiniteStateMachine,代码行数:55,代码来源:FiniteStateExamples.cs

示例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);
    }
开发者ID:mmvlad,项目名称:FiniteStateMachine,代码行数:30,代码来源:FiniteStateExamples.cs

示例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);
    }
开发者ID:mmvlad,项目名称:FiniteStateMachine,代码行数:30,代码来源:FiniteStateExamples.cs


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