protected override void AfterOnPlayback()
        {
            base.AfterOnPlayback();

            Animator.BatchUpdate();
            Animator.ClearAnimatorJobContainer();
        }
        /// <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;
        }
Beispiel #3
0
        public static void UpdateTransform(PlayerEntity player, NetworkAnimatorComponent networkAnimator,
                                           PredictedAppearanceComponent appearance, OrientationComponent orientation)
        {
            if (!player.hasAppearanceInterface)
            {
                return;
            }

            //Logger.InfoFormat("replay pose, networkAnimatior:BaseClientTime{0}, server Time:{1}", networkAnimator.BaseClientTime, networkAnimator.BaseServerTime);

            // Animation
            Animator.ClearAnimatorJobContainer();

            PoseReplayer.ReplayPose(networkAnimator.AnimatorLayers, networkAnimator.AnimatorParameters,
                                    player.thirdPersonAnimator.UnityAnimator);

            Animator.BatchUpdate();
            Animator.ClearAnimatorJobContainer();

            // 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,
                HandPitch      = characterBone.PitchHandAngle,
                HeadRotProcess = characterBone.HeadRotProcess,
                WeaponRot      = characterBone.WeaponRot,
                IsProne        = thirdPersonAppearance.Posture == ThirdPersonPosture.Prone,
                IsHeadRotCW    = characterBone.IsHeadRotCW,

                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);
            }
        }
        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);
            }
        }