Exemplo n.º 1
0
        public static FsmState CreateDiveMoveState()
        {
            MovementState state = new MovementState(MovementStateId.DiveMove);

            #region DiveMove to Idle
            state.AddTransition(new DiveTransition(
                                    state.AvailableTransitionId(),
                                    (command, addOutput) => FsmTransition.SimpleCommandHandler(command, FsmInput.Idle),
                                    (command, addOutput) =>
            {
                if (command.IsMatch(FsmInput.Sprint) || command.IsMatch(FsmInput.Run) || command.IsMatch(FsmInput.Walk))
                {
                    return(FsmTransitionResponseType.ForceEnd);
                }
                return(FsmTransitionResponseType.NoResponse);
            },
                                    (int)MovementStateId.Idle,
                                    (normalizedTime, addOutput) =>
            {
                FsmOutput.Cache.SetValue(AnimatorParametersHash.Instance.MotionHash,
                                         AnimatorParametersHash.Instance.MotionName,
                                         AnimatorParametersHash.Instance.MotionlessValue,
                                         CharacterView.FirstPerson | CharacterView.ThirdPerson);
                addOutput(FsmOutput.Cache);
            },
                                    SingletonManager.Get <CharacterStateConfigManager>().GetMovementTransitionTime(MovementInConfig.DiveMove, MovementInConfig.Idle), null, true), new[] { FsmInput.Idle });

            #endregion

            #region DiveMove to move
            state.AddTransition(new DiveTransition(
                                    state.AvailableTransitionId(),
                                    (command, addOutput) =>
            {
                if (command.IsMatch(FsmInput.Sprint) || command.IsMatch(FsmInput.Run) ||
                    command.IsMatch(FsmInput.Walk))
                {
                    command.Handled = true;
                    return(true);
                }

                return(false);
            },
                                    null,
                                    (int)MovementStateId.Walk,
                                    null,
                                    0), new[] { FsmInput.Sprint, FsmInput.Run, FsmInput.Walk });

            #endregion
            return(state);
        }
Exemplo n.º 2
0
        public static MovementState CreateIdleState()
        {
            MovementState state = new MovementState(MovementStateId.Idle);

            #region Idle to Walk

            state.AddTransition(
                (command, addOutput) =>
            {
                var walkRet = command.IsMatch(FsmInput.Walk);
                var runRet  = command.IsMatch(FsmInput.Run) || command.IsMatch(FsmInput.Sprint);

                if (walkRet || runRet)
                {
                    FsmOutput.Cache.SetValue(AnimatorParametersHash.Instance.IsWalkHash,
                                             AnimatorParametersHash.Instance.IsWalkName,
                                             walkRet,
                                             CharacterView.ThirdPerson, false);
                    addOutput(FsmOutput.Cache);

                    FsmOutput.Cache.SetValue(AnimatorParametersHash.Instance.MotionHash,
                                             AnimatorParametersHash.Instance.MotionName,
                                             AnimatorParametersHash.Instance.MotionValue,
                                             CharacterView.FirstPerson | CharacterView.ThirdPerson);
                    addOutput(FsmOutput.Cache);

                    FsmOutput.Cache.SetValue(AnimatorParametersHash.Instance.MovementHash,
                                             AnimatorParametersHash.Instance.MovementName,
                                             AnimatorParametersHash.Instance.WalkValue,
                                             CharacterView.FirstPerson | CharacterView.ThirdPerson);
                    addOutput(FsmOutput.Cache);

                    command.Handled = true;
                }
                return(walkRet || runRet);
            },
                (command, addOutput) =>
            {
                if (command.IsMatch(FsmInput.Idle))
                {
                    return(FsmTransitionResponseType.ForceEnd);
                }
                return(FsmTransitionResponseType.NoResponse);
            },
                (int)MovementStateId.Walk,
                null,
                SingletonManager.Get <CharacterStateConfigManager>().GetMovementTransitionTime(MovementInConfig.Idle, MovementInConfig.Walk),
                new[] { FsmInput.Walk, FsmInput.Run, FsmInput.Sprint });
            #endregion

            #region idle to divemove
            state.AddTransition(new DiveTransition(state.AvailableTransitionId(),
                                                   (command, addOutput) =>
            {
                bool ret = command.IsMatch(FsmInput.DiveMove);
                if (ret)
                {
                    FsmOutput.Cache.SetValue(AnimatorParametersHash.Instance.MotionHash,
                                             AnimatorParametersHash.Instance.MotionName,
                                             AnimatorParametersHash.Instance.MotionValue,
                                             CharacterView.FirstPerson | CharacterView.ThirdPerson);
                    addOutput(FsmOutput.Cache);
                    command.Handled = true;
                }

                return(ret);
            },
                                                   (command, addOutput) =>
            {
                if (command.IsMatch(FsmInput.Idle))
                {
                    return(FsmTransitionResponseType.ForceEnd);
                }
                return(FsmTransitionResponseType.NoResponse);
            },
                                                   (int)MovementStateId.DiveMove,
                                                   null,
                                                   SingletonManager.Get <CharacterStateConfigManager>().GetMovementTransitionTime(MovementInConfig.Idle, MovementInConfig.DiveMove)
                                                   ), new[] { FsmInput.DiveMove });

            #endregion

            return(state);
        }