Exemplo n.º 1
0
        /// <summary>
        /// 这个函数没有应用PeekDegree等boneRigging.Update
        /// </summary>
        /// <param name="player"></param>
        public static void UpdateAnimatorTransform(PlayerEntity player)
        {
            if (!player.hasNetworkAnimator && !player.hasThirdPersonAnimator)
            {
                return;
            }

            var networkAnimator = player.networkAnimator;
            var animatorP3      = player.thirdPersonAnimator.UnityAnimator;
            var previousMode    = animatorP3.cullingMode;

            animatorP3.cullingMode = AnimatorCullingMode.AlwaysAnimate;
            // Animation
            Animator.ClearAnimatorJobContainer();

//            流量优化用
//            if (networkAnimator.AnimatorParameters == null)
//            {
//                networkAnimator.SetAnimatorParamsWithoutChangeData(
//                    NetworkAnimatorUtil.GetAnimatorParams(player.thirdPersonAnimator.UnityAnimator));
//                networkAnimator.ConvertCompressDataToStructureData();
//            }
            AnimatorPoseReplayer.ReplayPose(networkAnimator.AnimatorLayers, networkAnimator.AnimatorParameters,
                                            animatorP3);

            Animator.BatchUpdate();

            animatorP3.cullingMode = previousMode;
        }
        protected override void OnPlayBack(PlayerEntity player)
        {
            try
            {
                _info.BeginProfileOnlyEnableProfile();

                CheckPlayerLifeState(player);

                var networkAnimator = player.networkAnimator;
                if (null == networkAnimator)
                {
                    return;
                }
                if (!player.gamePlay.IsLifeState(EPlayerLifeState.Dead))
                {
                    OverridePlayBackNetworkAnimator(player, networkAnimator.AnimatorLayers);

//                    流量优化用
//                    if (networkAnimator.AnimatorParameters == null)
//                    {
//                        networkAnimator.SetAnimatorParamsWithoutChangeData(
//                            NetworkAnimatorUtil.GetAnimatorParams(player.thirdPersonAnimator.UnityAnimator));
//                        networkAnimator.ConvertCompressDataToStructureData();
//                    }
                    AnimatorPoseReplayer.ReplayPose(networkAnimator.AnimatorLayers, networkAnimator.AnimatorParameters,
                                                    player.thirdPersonAnimator.UnityAnimator);
                }
            }
            finally
            {
                _info.EndProfileOnlyEnableProfile();
            }
        }
Exemplo n.º 3
0
 public ClientPlayerHitBoxContext(PlayerContext playerContext)
 {
     _playerContext = playerContext;
     _poseReplayer  = new AnimatorPoseReplayer();
 }
Exemplo n.º 4
0
        public static void UpdateTransform(PlayerEntity player, NetworkAnimatorComponent networkAnimator,
                                           PredictedAppearanceComponent appearance, OrientationComponent orientation)
        {
            if (!player.hasAppearanceInterface)
            {
                return;
            }

            // Animation
            Animator.ClearAnimatorJobContainer();

//            流量优化用
//            if (networkAnimator.AnimatorParameters == null)
//            {
//                networkAnimator.SetAnimatorParamsWithoutChangeData(
//                    NetworkAnimatorUtil.GetAnimatorParams(player.thirdPersonAnimator.UnityAnimator));
//                networkAnimator.ConvertCompressDataToStructureData();
//            }
            AnimatorPoseReplayer.ReplayPose(networkAnimator.AnimatorLayers, networkAnimator.AnimatorParameters,
                                            player.thirdPersonAnimator.UnityAnimator);

            Animator.BatchUpdate();

            // equipment(pan)
            var appearanceInterface = player.appearanceInterface;

            appearanceInterface.Appearance.SyncLatestFrom(player.latestAppearance);
            appearanceInterface.Appearance.SyncPredictedFrom(appearance);
            appearanceInterface.Appearance.TryRewind();

            var characterBoneInterface       = player.characterBoneInterface;
            var thirdPersonAppearance        = player.thirdPersonAppearance;
            var characterBone                = player.characterBone;
            var characterControllerInterface = player.characterControllerInterface;

            characterBoneInterface.CharacterBone.Peek(thirdPersonAppearance.PeekDegree);
            var param = new CodeRigBoneParam
            {
                PitchAmplitude         = orientation.Pitch,
                OverlayAnimationWeight =
                    networkAnimator.AnimatorLayers[NetworkAnimatorLayer.PlayerUpperBodyOverlayLayer].Weight,
                PostureWhenOverlay = thirdPersonAppearance.Posture,
                // 预测时,IK不生效
                IKActive = ActiveIK(thirdPersonAppearance.Action, thirdPersonAppearance.Posture,
                                    thirdPersonAppearance.NextPosture, thirdPersonAppearance.Movement),
                HeadPitch        = characterBone.PitchHeadAngle,
                HeadYaw          = characterBone.RotHeadAngle,
                CurrentHandPitch = characterBone.CurrentPitchHandAngle,
                WeaponRot        = characterBone.WeaponRot,

                FirstPersonPositionOffset = characterBone.FirstPersonPositionOffset,
                FirstPersonRotationOffset = characterBone.FirstPersonRotationOffset,
                FirstPersonSightOffset    = characterBone.FirstPersonSightOffset
            };

            // code controlled pose
            characterBoneInterface.CharacterBone.WeaponRotPlayback(param);
            characterBoneInterface.CharacterBone.Update(param);

            player.characterContoller.Value.SetCurrentControllerType(
                ThirdPersonPostureTool.ConvertToPostureInConfig(thirdPersonAppearance.Posture));

            // 更新包围盒

            if (thirdPersonAppearance.NeedUpdateController)
            {
                characterControllerInterface.CharacterController.SetCharacterControllerHeight(thirdPersonAppearance
                                                                                              .CharacterHeight, player.characterContoller.Value.GetCurrentControllerType() == CharacterControllerType.UnityCharacterController, thirdPersonAppearance.CharacterStandHeight);
                characterControllerInterface.CharacterController.SetCharacterControllerCenter(thirdPersonAppearance
                                                                                              .CharacterCenter, player.characterContoller.Value.GetCurrentControllerType() == CharacterControllerType.UnityCharacterController);
                characterControllerInterface.CharacterController.SetCharacterControllerRadius(thirdPersonAppearance
                                                                                              .CharacterRadius, player.characterContoller.Value.GetCurrentControllerType() == CharacterControllerType.UnityCharacterController);
            }
        }