Beispiel #1
0
    private void Awake()
    {
        stateMachine = new StateMachineBuilder()
                       .State(STATE_Idle)
                       .Enter(state => {
            animator.Play(hand.equipped ? getEquippedAnimation(stateMachine.CurrentStateStr) : "idle");
        })
                       .Condition(() => statCollection.GetStatValue(GlobalSymbol.INPUTVAR_MOVE_HORIZONTAL) != 0, state => stateMachine.ChangeState(STATE_Run))
                       .Condition(() => playerInput.GetButtonDown(GlobalSymbol.INPUTACTION_Jump), state => stateMachine.ChangeState(STATE_Jump))
                       .Condition(() => !movement.isGrounded, state => stateMachine.ChangeState(STATE_Fall))
                       .Update((state, dt) => {
        })
                       .End()
                       .State(STATE_Run)
                       .Enter(state => {
            animator.Play(hand.equipped ? getEquippedAnimation(stateMachine.CurrentStateStr) : "run");
        })
                       .Condition(() => statCollection.GetStatValue(GlobalSymbol.INPUTVAR_MOVE_HORIZONTAL) == 0, state => stateMachine.ChangeState(STATE_Idle))
                       .Condition(() => playerInput.GetButtonDown(GlobalSymbol.INPUTACTION_Jump), state => stateMachine.ChangeState(STATE_Jump))
                       .Update((state, dt) => {
            movement.Move(new Vector2(statCollection.GetStatValue(GlobalSymbol.INPUTVAR_MOVE_HORIZONTAL), 0));
            faceDirectionComponent.SetFaceDirection(statCollection.GetStatValue(GlobalSymbol.INPUTVAR_MOVE_HORIZONTAL));
        })
                       .End()
                       .State(STATE_Jump)
                       .Enter(state => {
            animator.Play(hand.equipped ? getEquippedAnimation(stateMachine.CurrentStateStr) : "jump");
            movement.Jump(statCollection.GetStatValue(GlobalSymbol.JUMP_HEIGHT));
        })
                       .Exit(state => {
        })
                       .Condition(() => movement.isGrounded, state => stateMachine.ChangeState(STATE_Idle))
                       .Update((state, dt) => {
            movement.Move(new Vector2(statCollection.GetStatValue(GlobalSymbol.INPUTVAR_MOVE_HORIZONTAL), 0));
        })
                       .End()
                       .State(STATE_Fall)
                       .Enter(state => {
            animator.Play(hand.equipped ? getEquippedAnimation(stateMachine.CurrentStateStr) : "jump");
        })
                       .Condition(() => movement.isGrounded, state => stateMachine.ChangeState(STATE_Idle))
                       .Update((state, dt) => {
            movement.Move(new Vector2(statCollection.GetStatValue(GlobalSymbol.INPUTVAR_MOVE_HORIZONTAL), 0));
            faceDirectionComponent.SetFaceDirection(statCollection.GetStatValue(GlobalSymbol.INPUTVAR_MOVE_HORIZONTAL));
        })
                       .End()
                       .Build() as RSG.AbstractState;

        // movement.onMoved += onMovementMove;
        hand.onEquipped   += onHandGearEquipped;
        hand.onUnequipped += onHandGearUnequipped;

        stateMachine.PushState(STATE_Idle);
    }
Beispiel #2
0
    private void initStateMachine()
    {
        m_stateMachine = new StateMachineBuilder().
                         State(CSTATE_Idle)
                         .Enter(state =>
        {
        })
                         .Condition(() => InputManager.GetAxis("Horizontal") > 0f, state => m_stateMachine.ChangeState(CSTATE_MoveRight))
                         .Condition(() => InputManager.GetAxis("Horizontal") < 0f, state => m_stateMachine.ChangeState(CSTATE_MoveLeft))
                         .Condition(() => InputManager.GetAxis("Vertical") > 0f, state => m_stateMachine.ChangeState(CSTATE_MoveUp))
                         .Condition(() => InputManager.GetAxis("Vertical") < 0f, state => m_stateMachine.ChangeState(CSTATE_MoveDown))
                         .End().
                         State(CSTATE_MoveLeft)
                         .Enter(state =>
        {
            m_actionAnimator.Play(CSTATE_MoveLeft);
        })
                         .Update((state, dt) =>
        {
            m_moveController.Move(InputManager.GetAxis("Horizontal"), InputManager.GetAxis("Vertical"));
        })
                         .Condition(() => InputManager.GetAxis("Horizontal") == 0f, state => m_stateMachine.ChangeState(CSTATE_Idle))
                         .Condition(() => InputManager.GetAxis("Horizontal") > 0f, state => m_stateMachine.ChangeState(CSTATE_MoveRight))
                         .End().
                         State(CSTATE_MoveRight)
                         .Enter(state =>
        {
            m_actionAnimator.Play(CSTATE_MoveRight);
        })
                         .Update((state, dt) =>
        {
            m_moveController.Move(InputManager.GetAxis("Horizontal"), InputManager.GetAxis("Vertical"));
        })
                         .Condition(() => InputManager.GetAxis("Horizontal") == 0f, state => m_stateMachine.ChangeState(CSTATE_Idle))
                         .Condition(() => InputManager.GetAxis("Horizontal") < 0f, state => m_stateMachine.ChangeState(CSTATE_MoveLeft))
                         .End().
                         State(CSTATE_MoveUp)
                         .Enter(state =>
        {
            m_actionAnimator.Play(CSTATE_MoveUp);
        })
                         .Update((state, dt) =>
        {
            m_moveController.Move(0f, InputManager.GetAxis("Vertical"));
        })
                         .Condition(() => InputManager.GetAxis("Vertical") == 0f, state => m_stateMachine.ChangeState(CSTATE_Idle))
                         .End().
                         State(CSTATE_MoveDown)
                         .Enter(state =>
        {
            m_actionAnimator.Play(CSTATE_MoveDown);
        })
                         .Update((state, dt) =>
        {
            m_moveController.Move(0f, InputManager.GetAxis("Vertical"));
        })
                         .Condition(() => InputManager.GetAxis("Vertical") == 0f, state => m_stateMachine.ChangeState(CSTATE_Idle))
                         .End()
                         .Build() as AbstractState;

        m_stateMachine.PushState(CSTATE_MoveRight);
    }