Пример #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);
        }
Пример #2
0
        protected static void AddTransitionToMovement(MovementState state)
        {
            state.AddTransition(
                (command, addOutput) =>
            {
                var 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);
            },
                null, (int)MovementStateId.DiveMove, null, 0, new[] { FsmInput.DiveMove });
        }
Пример #3
0
        public static MovementState CreateSprintState()
        {
            MovementState state = new MovementState(MovementStateId.Sprint);

            #region Sprint to Idle

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

            #endregion

            #region Sprint to Walk

            state.AddTransition(
                (command, addOutput) => FsmTransition.SimpleCommandHandler(command, FsmInput.Walk),
                (command, addOutput) =>
            {
                if (command.IsMatch(FsmInput.Sprint))
                {
                    return(FsmTransitionResponseType.ForceEnd);
                }
                if (command.IsMatch(FsmInput.Idle) || command.IsMatch(FsmInput.Run))
                {
                    return(FsmTransitionResponseType.ChangeRoad);
                }
                return(FsmTransitionResponseType.NoResponse);
            },
                (int)MovementStateId.Walk,
                FsmTransition.GetLerpFunc(AnimatorParametersHash.Instance.MovementHash,
                                          AnimatorParametersHash.Instance.MovementName,
                                          AnimatorParametersHash.Instance.SprintValue,
                                          AnimatorParametersHash.Instance.WalkValue,
                                          CharacterView.FirstPerson | CharacterView.ThirdPerson),
                SingletonManager.Get <CharacterStateConfigManager>().GetMovementTransitionTime(MovementInConfig.Sprint, MovementInConfig.Walk),
                new[] { FsmInput.Walk });

            #endregion

            #region Sprint to Run

            state.AddTransition(
                (command, addOutput) => FsmTransition.SimpleCommandHandler(command, FsmInput.Run),
                (command, addOutput) =>
            {
                if (command.IsMatch(FsmInput.Sprint))
                {
                    return(FsmTransitionResponseType.ForceEnd);
                }
                if (command.IsMatch(FsmInput.Idle) || command.IsMatch(FsmInput.Walk))
                {
                    return(FsmTransitionResponseType.ChangeRoad);
                }
                return(FsmTransitionResponseType.NoResponse);
            },
                (int)MovementStateId.Run,
                FsmTransition.GetLerpFunc(AnimatorParametersHash.Instance.MovementHash,
                                          AnimatorParametersHash.Instance.MovementName,
                                          AnimatorParametersHash.Instance.SprintValue,
                                          AnimatorParametersHash.Instance.RunValue,
                                          CharacterView.FirstPerson | CharacterView.ThirdPerson),
                SingletonManager.Get <CharacterStateConfigManager>().GetMovementTransitionTime(MovementInConfig.Sprint, MovementInConfig.Run),
                new[] { FsmInput.Run });

            #endregion

            #region to divemovement
            AddTransitionToMovement(state);
            #endregion

            return(state);
        }
Пример #4
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);
        }
Пример #5
0
        private static void ToLadderMovement(MovementState state)
        {
            state.AddTransition(
                (command, addOutput) =>
            {
                if (command.IsMatch(FsmInput.EnterLadder))
                {
                    FsmOutput.Cache.SetValue(AnimatorParametersHash.Instance.LadderHash,
                                             AnimatorParametersHash.Instance.LadderName,
                                             AnimatorParametersHash.Instance.LadderEnableValue,
                                             CharacterView.ThirdPerson, false);
                    addOutput(FsmOutput.Cache);

                    FsmOutput.Cache.SetValue(AnimatorParametersHash.Instance.LadderEnterStateHash,
                                             AnimatorParametersHash.Instance.LadderEnterStateName,
                                             (int)command.AdditioanlValue,
                                             CharacterView.ThirdPerson);
                    addOutput(FsmOutput.Cache);

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

                    command.Handled = true;
                    return(true);
                }

                return(false);
            },
                (command, addOutput) => FsmTransitionResponseType.NoResponse,
                (int)MovementStateId.EnterLadder, null, 0, new[] { FsmInput.EnterLadder });

            state.AddTransition(
                (command, addOutput) =>
            {
                if (command.IsMatch(FsmInput.MiddleEnterLadder))
                {
                    FsmOutput.Cache.SetValue(AnimatorParametersHash.Instance.LadderHash,
                                             AnimatorParametersHash.Instance.LadderName,
                                             AnimatorParametersHash.Instance.LadderEnableValue,
                                             CharacterView.ThirdPerson, false);
                    addOutput(FsmOutput.Cache);

                    FsmOutput.Cache.SetValue(AnimatorParametersHash.Instance.LadderEnterStateHash,
                                             AnimatorParametersHash.Instance.LadderEnterStateName,
                                             AnimatorParametersHash.Instance.LadderEnterStateMiddle,
                                             CharacterView.ThirdPerson);
                    addOutput(FsmOutput.Cache);

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

                    command.Handled = true;
                    return(true);
                }

                return(false);
            },
                (command, addOutput) => FsmTransitionResponseType.NoResponse,
                (int)MovementStateId.Ladder, null, 0, new[] { FsmInput.MiddleEnterLadder });
        }