Example #1
0
        public static PostureState CreateStandState()
        {
            PostureState state = new CustomPostureState(PostureStateId.Stand,
                                                        AnimatorParametersHash.FirstPersonStandCameraHeight,
                                                        AnimatorParametersHash.FirstPersonStandCameraForwardOffset,
                                                        SingletonManager.Get <CharacterStateConfigManager>().GetCharacterControllerCapsule(PostureInConfig.Stand).Height,
                                                        SingletonManager.Get <CharacterStateConfigManager>().GetCharacterControllerCapsule(PostureInConfig.Stand).Radius);

            #region stand to crouch

            state.AddTransition(new PostureTransition(
                                    state.AvailableTransitionId(),
                                    (command, addOutput) => FsmTransition.SimpleCommandHandler(command, FsmInput.Crouch),
                                    (command, addOutput) => FsmTransitionResponseType.NoResponse,
                                    PostureStateId.Crouch,
                                    SingletonManager.Get <CharacterStateConfigManager>().GetPostureTransitionTime(PostureInConfig.Stand,
                                                                                                                  PostureInConfig.Crouch),
                                    AnimatorParametersHash.FirstPersonStandCameraHeight,
                                    AnimatorParametersHash.FirstPersonCrouchCameraHeight,
                                    AnimatorParametersHash.FirstPersonStandCameraForwardOffset,
                                    AnimatorParametersHash.FirstPersonCrouchCameraForwardOffset,
                                    AnimatorParametersHash.Instance.StandValue,
                                    AnimatorParametersHash.Instance.CrouchValue,
                                    SingletonManager.Get <CharacterStateConfigManager>().GetCharacterControllerCapsule(PostureInConfig.Stand),
                                    SingletonManager.Get <CharacterStateConfigManager>().GetCharacterControllerCapsule(PostureInConfig.Crouch)),
                                new[] { FsmInput.Crouch });

            #endregion

            #region stand to prone

            state.AddTransition(new PostureTransition(
                                    state.AvailableTransitionId(),
                                    (command, addOutput) =>
            {
                var ret = command.IsMatch(FsmInput.Prone);

                if (ret)
                {
                    FsmOutput.Cache.SetValue(AnimatorParametersHash.Instance.ProneHash,
                                             AnimatorParametersHash.Instance.ProneName,
                                             AnimatorParametersHash.Instance.ProneEnable,
                                             CharacterView.FirstPerson | CharacterView.ThirdPerson, false);
                    addOutput(FsmOutput.Cache);

                    FsmOutput.Cache.SetValue(AnimatorParametersHash.Instance.PostureHash,
                                             AnimatorParametersHash.Instance.PostureName,
                                             AnimatorParametersHash.Instance.ProneValue,
                                             CharacterView.ThirdPerson);
                    addOutput(FsmOutput.Cache);

                    command.Handled = true;
                }

                return(ret);
            },
                                    (command, addOutput) => FsmTransitionResponseType.NoResponse,
                                    PostureStateId.ProneTransit,
                                    SingletonManager.Get <CharacterStateConfigManager>().GetPostureTransitionTime(PostureInConfig.Stand,
                                                                                                                  PostureInConfig.Prone) /*0*/,
                                    AnimatorParametersHash.FirstPersonStandCameraHeight,
                                    AnimatorParametersHash.FirstPersonProneCameraHeight,
                                    AnimatorParametersHash.FirstPersonStandCameraForwardOffset,
                                    AnimatorParametersHash.FirstPersonProneCameraForwardOffset,
                                    AnimatorParametersHash.Instance.StandValue,
                                    AnimatorParametersHash.Instance.ProneValue,
                                    SingletonManager.Get <CharacterStateConfigManager>().GetCharacterControllerCapsule(PostureInConfig.Stand),
                                    SingletonManager.Get <CharacterStateConfigManager>().GetCharacterControllerCapsule(PostureInConfig.Prone), false),
                                new[] { FsmInput.Prone });

            #endregion

            #region stand to jumpstart

            state.AddTransition(
                (command, addOutput) =>
            {
                var ret = command.IsMatch(FsmInput.Jump);

                if (ret)
                {
                    FsmOutput.Cache.SetValue(AnimatorParametersHash.Instance.JumpStartHash,
                                             AnimatorParametersHash.Instance.JumpStartName,
                                             AnimatorParametersHash.Instance.JumpStartEnable,
                                             CharacterView.FirstPerson | CharacterView.ThirdPerson, false);
                    addOutput(FsmOutput.Cache);

                    command.Handled = true;
                }

                return(ret);
            },
                (command, addOutput) => FsmTransitionResponseType.NoResponse,
                (int)PostureStateId.JumpStart, null, 0, new[] { FsmInput.Jump });

            #endregion

            #region stand to freefall

            state.AddTransition(
                (command, addOutput) =>
            {
                var ret = command.IsMatch(FsmInput.Freefall);

                if (ret)
                {
                    FsmOutput.Cache.SetValue(AnimatorParametersHash.Instance.FreeFallHash,
                                             AnimatorParametersHash.Instance.FreeFallName,
                                             AnimatorParametersHash.Instance.FreeFallEnable,
                                             CharacterView.FirstPerson | CharacterView.ThirdPerson, false);
                    addOutput(FsmOutput.Cache);
                    Logger.InfoFormat("stand to freefall transition, set jumploop to true!");
                    command.Handled = true;
                }

                return(ret);
            },
                null, (int)PostureStateId.Freefall, null, 0, new[] { FsmInput.Freefall });

            #endregion

            #region stand to swim

            state.AddTransition(
                (command, addOutput) =>
            {
                var ret = command.IsMatch(FsmInput.Swim);

                if (ret)
                {
                    FsmOutput.Cache.SetLayerWeight(AnimatorParametersHash.Instance.SwimLayer,
                                                   AnimatorParametersHash.Instance.SwimEnableValue,
                                                   CharacterView.ThirdPerson);
                    addOutput(FsmOutput.Cache);

                    FsmOutput.Cache.SetValue(AnimatorParametersHash.Instance.SwimStateHash,
                                             AnimatorParametersHash.Instance.SwimStateName,
                                             AnimatorParametersHash.Instance.SwimStateSwimValue,
                                             CharacterView.ThirdPerson);
                    addOutput(FsmOutput.Cache);

                    command.Handled = true;
                }

                return(ret);
            },
                (command, addOutput) => FsmTransitionResponseType.NoResponse,
                (int)PostureStateId.Swim, null, 0, new[] { FsmInput.Swim });

            #endregion

            #region stand to dying

            AddTransitionToDying(state);

            #endregion

            #region stand to climb

            state.AddTransition(
                (command, addOutput) =>
            {
                if (command.IsMatch(FsmInput.Climb))
                {
                    FsmOutput.Cache.SetValue(AnimatorParametersHash.Instance.ClimbHash,
                                             AnimatorParametersHash.Instance.ClimbName,
                                             AnimatorParametersHash.Instance.ClimbEnableValue,
                                             CharacterView.ThirdPerson, false);
                    addOutput(FsmOutput.Cache);

                    FsmOutput.Cache.SetValue(AnimatorParametersHash.Instance.ClimbStateHash,
                                             AnimatorParametersHash.Instance.ClimbStateName,
                                             command.AdditioanlValue,
                                             CharacterView.ThirdPerson);
                    addOutput(FsmOutput.Cache);
                    command.Handled = true;
                    return(true);
                }

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

            #endregion

            return(state);
        }
Example #2
0
        public static PostureState CreateProneState()
        {
            PostureState state = new CustomPostureState(PostureStateId.Prone,
                                                        AnimatorParametersHash.FirstPersonProneCameraHeight,
                                                        AnimatorParametersHash.FirstPersonProneCameraForwardOffset,
                                                        SingletonManager.Get <CharacterStateConfigManager>().GetCharacterControllerCapsule(PostureInConfig.Prone).Height,
                                                        SingletonManager.Get <CharacterStateConfigManager>().GetCharacterControllerCapsule(PostureInConfig.Prone).Radius);

            #region prone to crouch

            state.AddTransition(new PostureTransition(
                                    state.AvailableTransitionId(),
                                    (command, addOutput) =>
            {
                var ret = command.IsMatch(FsmInput.Crouch);

                if (ret)
                {
                    FsmOutput.Cache.SetValue(AnimatorParametersHash.Instance.ProneHash,
                                             AnimatorParametersHash.Instance.ProneName,
                                             AnimatorParametersHash.Instance.ProneDisable,
                                             CharacterView.FirstPerson | CharacterView.ThirdPerson, false);
                    addOutput(FsmOutput.Cache);

                    FsmOutput.Cache.SetValue(AnimatorParametersHash.Instance.PostureHash,
                                             AnimatorParametersHash.Instance.PostureName,
                                             AnimatorParametersHash.Instance.CrouchValue,
                                             CharacterView.ThirdPerson);
                    addOutput(FsmOutput.Cache);

                    command.Handled = true;
                }

                return(ret);
            },
                                    (command, addOutput) => FsmTransitionResponseType.NoResponse,
                                    PostureStateId.ProneToCrouch,
                                    SingletonManager.Get <CharacterStateConfigManager>().GetPostureTransitionTime(PostureInConfig.Prone,
                                                                                                                  PostureInConfig.Crouch) /*0*/,
                                    AnimatorParametersHash.FirstPersonProneCameraHeight,
                                    AnimatorParametersHash.FirstPersonCrouchCameraHeight,
                                    AnimatorParametersHash.FirstPersonProneCameraForwardOffset,
                                    AnimatorParametersHash.FirstPersonCrouchCameraForwardOffset,
                                    AnimatorParametersHash.Instance.ProneValue,
                                    AnimatorParametersHash.Instance.CrouchValue,
                                    SingletonManager.Get <CharacterStateConfigManager>().GetCharacterControllerCapsule(PostureInConfig.Prone),
                                    SingletonManager.Get <CharacterStateConfigManager>().GetCharacterControllerCapsule(PostureInConfig.Crouch), false),
                                new[] { FsmInput.Crouch });

            #endregion

            #region prone to stand

            state.AddTransition(new PostureTransition(
                                    state.AvailableTransitionId(),
                                    (command, addOutput) =>
            {
                var ret = command.IsMatch(FsmInput.Jump) || command.IsMatch(FsmInput.Prone);

                if (ret)
                {
                    FsmOutput.Cache.SetValue(AnimatorParametersHash.Instance.ProneHash,
                                             AnimatorParametersHash.Instance.ProneName,
                                             AnimatorParametersHash.Instance.ProneDisable,
                                             CharacterView.FirstPerson | CharacterView.ThirdPerson, false);
                    addOutput(FsmOutput.Cache);

                    FsmOutput.Cache.SetValue(AnimatorParametersHash.Instance.PostureHash,
                                             AnimatorParametersHash.Instance.PostureName,
                                             AnimatorParametersHash.Instance.StandValue,
                                             CharacterView.ThirdPerson);
                    addOutput(FsmOutput.Cache);

                    command.Handled = true;

                    Logger.InfoFormat("prone to stand!!!! handle");
                }

                return(ret);
            },
                                    (command, addOutput) => FsmTransitionResponseType.NoResponse,
                                    PostureStateId.ProneToStand,
                                    SingletonManager.Get <CharacterStateConfigManager>().GetPostureTransitionTime(PostureInConfig.Prone,
                                                                                                                  PostureInConfig.Stand) /*0*/,
                                    AnimatorParametersHash.FirstPersonProneCameraHeight,
                                    AnimatorParametersHash.FirstPersonStandCameraHeight,
                                    AnimatorParametersHash.FirstPersonProneCameraForwardOffset,
                                    AnimatorParametersHash.FirstPersonStandCameraForwardOffset,
                                    AnimatorParametersHash.Instance.ProneValue,
                                    AnimatorParametersHash.Instance.StandValue,
                                    SingletonManager.Get <CharacterStateConfigManager>().GetCharacterControllerCapsule(PostureInConfig.Prone),
                                    SingletonManager.Get <CharacterStateConfigManager>().GetCharacterControllerCapsule(PostureInConfig.Stand), false),
                                new[] { FsmInput.Jump, FsmInput.Prone });

            #endregion

            #region prone to freefall

            state.AddTransition(
                (command, addOutput) =>
            {
                var ret = command.IsMatch(FsmInput.Freefall);

                if (ret)
                {
                    FsmOutput.Cache.SetValue(AnimatorParametersHash.Instance.FreeFallHash,
                                             AnimatorParametersHash.Instance.FreeFallName,
                                             AnimatorParametersHash.Instance.FreeFallEnable,
                                             CharacterView.FirstPerson | CharacterView.ThirdPerson, false);
                    addOutput(FsmOutput.Cache);

                    FsmOutput.Cache.SetValue(AnimatorParametersHash.Instance.ProneHash,
                                             AnimatorParametersHash.Instance.ProneName,
                                             AnimatorParametersHash.Instance.ProneDisable,
                                             CharacterView.FirstPerson | CharacterView.ThirdPerson, false);
                    addOutput(FsmOutput.Cache);

                    command.Handled = true;
                }

                return(ret);
            },
                null, (int)PostureStateId.Freefall, null, 0, new[] { FsmInput.Freefall });

            #endregion

            #region prone to dying

            AddTransitionToDying(state);

            #endregion

            return(state);
        }
Example #3
0
        public static PostureState CreateCrouchState()
        {
            PostureState state = new CustomPostureState(PostureStateId.Crouch,
                                                        AnimatorParametersHash.FirstPersonCrouchCameraHeight,
                                                        AnimatorParametersHash.FirstPersonCrouchCameraForwardOffset);

            #region crouch to stand

            state.AddTransition(new PostureTransition(
                                    state.AvailableTransitionId(),
                                    (command, addOutput) => FsmTransition.SimpleCommandHandler(command, FsmInput.Crouch) ||
                                    FsmTransition.SimpleCommandHandler(command, FsmInput.Jump) ||
                                    FsmTransition.SimpleCommandHandler(command, FsmInput.PostureStand),
                                    (command, addOutput) => FsmTransitionResponseType.NoResponse,
                                    PostureStateId.Stand,
                                    SingletonManager.Get <CharacterStateConfigManager>()
                                    .GetPostureTransitionTime(PostureInConfig.Crouch, PostureInConfig.Stand),
                                    AnimatorParametersHash.FirstPersonCrouchCameraHeight,
                                    AnimatorParametersHash.FirstPersonStandCameraHeight,
                                    AnimatorParametersHash.FirstPersonCrouchCameraForwardOffset,
                                    AnimatorParametersHash.FirstPersonStandCameraForwardOffset,
                                    AnimatorParametersHash.Instance.CrouchValue,
                                    AnimatorParametersHash.Instance.StandValue,
                                    PostureInConfig.Crouch,
                                    PostureInConfig.Stand),
                                new[] { FsmInput.Crouch, FsmInput.Jump, FsmInput.PostureStand });

            #endregion

            #region crouch to prone

            state.AddTransition(
                (command, addOutput) =>
            {
                if (command.IsMatch(FsmInput.PostureProne))
                {
                    FsmOutput.Cache.SetValue(AnimatorParametersHash.Instance.ProneHash,
                                             AnimatorParametersHash.Instance.ProneName,
                                             AnimatorParametersHash.Instance.ProneEnable,
                                             CharacterView.FirstPerson | CharacterView.ThirdPerson, false);
                    addOutput(FsmOutput.Cache);

                    FsmOutput.Cache.SetValue(AnimatorParametersHash.Instance.PostureHash,
                                             AnimatorParametersHash.Instance.PostureName,
                                             AnimatorParametersHash.Instance.ProneValue,
                                             CharacterView.FirstPerson | CharacterView.ThirdPerson);
                    addOutput(FsmOutput.Cache);

                    FsmOutput.Cache.SetValue(AnimatorParametersHash.Instance.ForceToProneHash,
                                             AnimatorParametersHash.Instance.ForceToProneName,
                                             AnimatorParametersHash.Instance.ForceToProneEnable,
                                             CharacterView.FirstPerson | CharacterView.ThirdPerson, false);
                    addOutput(FsmOutput.Cache);

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

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

            state.AddTransition(new PostureTransition(
                                    state.AvailableTransitionId(),
                                    (command, addOutput) =>
            {
                var ret = command.IsMatch(FsmInput.Prone);

                if (ret)
                {
                    FsmOutput.Cache.SetValue(AnimatorParametersHash.Instance.ProneHash,
                                             AnimatorParametersHash.Instance.ProneName,
                                             AnimatorParametersHash.Instance.ProneEnable,
                                             CharacterView.FirstPerson | CharacterView.ThirdPerson, false);
                    addOutput(FsmOutput.Cache);

                    FsmOutput.Cache.SetValue(AnimatorParametersHash.Instance.PostureHash,
                                             AnimatorParametersHash.Instance.PostureName,
                                             AnimatorParametersHash.Instance.ProneValue,
                                             CharacterView.FirstPerson | CharacterView.ThirdPerson);
                    addOutput(FsmOutput.Cache);

                    FsmOutput.Cache.SetValue(AnimatorParametersHash.Instance.FrontPostureHash,
                                             AnimatorParametersHash.Instance.FrontPostureName,
                                             AnimatorParametersHash.Instance.FrontCrouch,
                                             CharacterView.FirstPerson | CharacterView.ThirdPerson);
                    addOutput(FsmOutput.Cache);

                    command.Handled = true;
                }

                return(ret);
            },
                                    (command, addOutput) => FsmTransitionResponseType.NoResponse,
                                    PostureStateId.ProneTransit,
                                    SingletonManager.Get <CharacterStateConfigManager>().GetPostureTransitionTime(PostureInConfig.Crouch,
                                                                                                                  PostureInConfig.Prone) /*0*/,
                                    AnimatorParametersHash.FirstPersonCrouchCameraHeight,
                                    AnimatorParametersHash.FirstPersonProneCameraHeight,
                                    AnimatorParametersHash.FirstPersonCrouchCameraForwardOffset,
                                    AnimatorParametersHash.FirstPersonProneCameraForwardOffset,
                                    AnimatorParametersHash.Instance.CrouchValue,
                                    AnimatorParametersHash.Instance.ProneValue,
                                    PostureInConfig.Crouch,
                                    PostureInConfig.Prone, false),
                                new[] { FsmInput.Prone });

            #endregion

            #region crouch to freefall

            state.AddTransition(
                (command, addOutput) =>
            {
                var ret = command.IsMatch(FsmInput.Freefall);

                if (ret)
                {
                    FsmOutput.Cache.SetValue(AnimatorParametersHash.Instance.FreeFallHash,
                                             AnimatorParametersHash.Instance.FreeFallName,
                                             AnimatorParametersHash.Instance.FreeFallEnable,
                                             CharacterView.FirstPerson | CharacterView.ThirdPerson, false);
                    addOutput(FsmOutput.Cache);

                    command.Handled = true;
                }

                return(ret);
            },
                null, (int)PostureStateId.Freefall, null, 0, new[] { FsmInput.Freefall });

            #endregion

            #region crouch to slide

            state.AddTransition(
                (command, addOutput) =>
            {
                var ret = command.IsMatch(FsmInput.Slide);

                if (ret)
                {
                    FsmOutput.Cache.SetValue(AnimatorParametersHash.Instance.SlideHash,
                                             AnimatorParametersHash.Instance.SlideName,
                                             AnimatorParametersHash.Instance.SlideEnable,
                                             CharacterView.ThirdPerson, false);
                    addOutput(FsmOutput.Cache);

                    command.Handled = true;
                }

                return(ret);
            },
                null, (int)PostureStateId.Slide, null, 0, new[] { FsmInput.Slide });

            #endregion

            #region crouch to dying

            AddTransitionToDying(state);

            #endregion

            return(state);
        }