Esempio n. 1
0
        private void UpdateBones(PlayerEntity player)
        {
            var orientation                  = player.orientation;
            var networkAnimator              = player.networkAnimator;
            var characterBoneInterface       = player.characterBoneInterface;
            var thirdPersonAppearance        = player.thirdPersonAppearance;
            var characterBone                = player.characterBone;
            var characterControllerInterface = player.characterControllerInterface;

            characterBoneInterface.CharacterBone.Peek(thirdPersonAppearance.PeekDegree);
            try
            {
                _subCharacterBoneUpdateInfo.BeginProfileOnlyEnableProfile();
                var param = new CodeRigBoneParam
                {
                    PitchAmplitude         = orientation.Pitch,
                    OverlayAnimationWeight = networkAnimator.AnimatorLayers[NetworkAnimatorLayer.PlayerUpperBodyOverlayLayer].Weight,
                    PostureWhenOverlay     = thirdPersonAppearance.Posture,
                    // 预测时,IK不生效
                    IKActive = PlayerEntityUtility.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);
            }
            finally
            {
                _subCharacterBoneUpdateInfo.EndProfileOnlyEnableProfile();
            }

            try
            {
                _subCharacterControllerUpdateInfo.BeginProfileOnlyEnableProfile();
                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);
                }
            }
            finally
            {
                _subCharacterControllerUpdateInfo.EndProfileOnlyEnableProfile();
            }
        }