Ejemplo n.º 1
0
        public bool SetP3IkTarget(GameObject obj, ref bool weaponHasIk)
        {
            var ret = false;

            if (!ThirdPersonIncluded)
            {
                return(false);
            }
            Transform leftIKP3 = null;

            if (obj != null)
            {
                leftIKP3 = BoneMount.FindChildBoneFromCache(obj, BoneName.AttachmentLeftIKP3);
                ret      = null != leftIKP3;

                if (leftIKP3 == null)
                {
                    leftIKP3 = BoneMount.FindChildBoneFromCache(obj, BoneName.WeaponLeftIK);
                }

                weaponHasIk = null != leftIKP3;
            }

            _ikControllerP3.ClearAllIKTarget();
            _ikControllerP3.SetIKGoal(AvatarIKGoal.LeftHand);
            _ikControllerP3.SetSource(AvatarIKGoal.LeftHand, leftIKP3);

            return(ret);
        }
Ejemplo n.º 2
0
 private void GetP3Bones(GameObject obj)
 {
     if (null == obj)
     {
         return;
     }
     _spineP3        = BoneMount.FindChildBone(obj, BoneName.CharacterSpineName);     //"Bip01 Spine");
     _spine1P3       = BoneMount.FindChildBone(obj, BoneName.CharacterSpine1Name);    // "Bip01 Spine1");
     _pelvisP3       = BoneMount.FindChildBone(obj, BoneName.CharacterBipPelvisName); //"Bip01 Pelvis");
     _ikControllerP3 = obj.GetComponent <PlayerIK>();
     _ikControllerP3.SetIKGoal(AvatarIKGoal.LeftHand);
 }
Ejemplo n.º 3
0
 private void GetP1Bones(GameObject obj)
 {
     if (null == obj)
     {
         return;
     }
     _viewPointP1        = BoneMount.FindChildBone(obj, BoneName.ViewPoint);
     _baseLocatorP1      = BoneMount.FindChildBone(obj, BoneName.FirstPersonHandLocator);
     _directionLocatorP1 = BoneMount.FindChildBone(obj, BoneName.FirstPersonSubHandLocator);
     _cameraLocatorP1    = BoneMount.FindChildBone(obj, BoneName.FirstPersonCameraLocator);
     _rightHandP1        = BoneMount.FindChildBone(obj, BoneName.CharacterRightHandName);
     _leftHandP1         = BoneMount.FindChildBone(obj, BoneName.CharacterLeftHandName);
     _ikControllerP1     = obj.GetComponent <PlayerIK>();
     _ikControllerP1.SetIKGoal(AvatarIKGoal.LeftHand);
 }
Ejemplo n.º 4
0
        public bool SetIKTarget(GameObject objP1, GameObject objP3, ref bool weaponHasIk)
        {
            bool ret = false;

            if (FirstPersonIncluded)
            {
                Transform leftIKP1 = null;
                if (objP1 != null)
                {
                    leftIKP1 = BoneMount.FindChildBoneFromCache(objP1, BoneName.AttachmentLeftIKP1);
                    if (leftIKP1 == null)
                    {
                        leftIKP1 = BoneMount.FindChildBoneFromCache(objP1, BoneName.WeaponLeftIK);
                    }
                }

                _ikControllerP1.ClearAllIKTarget();
                _ikControllerP1.SetIKGoal(AvatarIKGoal.LeftHand);
                _ikControllerP1.SetSource(AvatarIKGoal.LeftHand, leftIKP1);
            }

            if (ThirdPersonIncluded)
            {
                Transform leftIKP3 = null;
                if (objP3 != null)
                {
                    leftIKP3 = BoneMount.FindChildBoneFromCache(objP3, BoneName.AttachmentLeftIKP3);
                    ret      = null != leftIKP3;

                    if (leftIKP3 == null)
                    {
                        leftIKP3 = BoneMount.FindChildBoneFromCache(objP3, BoneName.WeaponLeftIK);
                    }

                    weaponHasIk = null != leftIKP3;
                }

                _ikControllerP3.ClearAllIKTarget();
                _ikControllerP3.SetIKGoal(AvatarIKGoal.LeftHand);
                _ikControllerP3.SetSource(AvatarIKGoal.LeftHand, leftIKP3);
            }

            return(ret);
        }
Ejemplo n.º 5
0
        public void SetP1IkTarget(GameObject obj)
        {
            if (!FirstPersonIncluded)
            {
                return;
            }
            Transform leftIkP1 = null;

            if (obj != null)
            {
                leftIkP1 = BoneMount.FindChildBoneFromCache(obj, BoneName.AttachmentLeftIKP1);
                if (leftIkP1 == null)
                {
                    leftIkP1 = BoneMount.FindChildBoneFromCache(obj, BoneName.WeaponLeftIK);
                }
            }

            _ikControllerP1.ClearAllIKTarget();
            _ikControllerP1.SetIKGoal(AvatarIKGoal.LeftHand);
            _ikControllerP1.SetSource(AvatarIKGoal.LeftHand, leftIkP1);
        }
Ejemplo n.º 6
0
        // 腰射与肩射的切换,与肩射呼吸动作
        private void SetSightStatus(SightStatusParam param)
        {
            if (param.IsSight)
            {
                if (_sightLocationP1 == null)
                {
                    _sightLocationP1 = BoneMount.FindChildBoneFromCache(_characterP1, BoneName.AttachmentSight);
                    if (_sightLocationP1 == null)
                    {
                        _sightLocationP1 = BoneMount.FindChildBoneFromCache(_characterP1, BoneName.WeaponSight);
                    }
                    if (_sightLocationP1 == null)
                    {
                        _logger.ErrorFormat("characterP1:{0} contains no Bone:{1} or {2}", _characterP1.name,
                                            BoneName.AttachmentSight, BoneName.WeaponSight);
                    }
                }

                var tempPos      = _sightLocationP1.localPosition;
                var tempRot      = _sightLocationP1.localRotation;
                var tempWorldPos = _sightLocationP1.position;

                // 记录viewPoint与sightLocator的相对位移
                if (_updateBone)
                {
                    _matrix = _viewPointP1.worldToLocalMatrix * _sightLocationP1.localToWorldMatrix;
                }

                SetSightMove(param);

                _updateBone = param.SightProgress < 1;
                var finalMatrix = _viewPointP1.localToWorldMatrix * _matrix;
                _sightLocationP1.position = finalMatrix.ExtractPosition();
                _sightLocationP1.rotation = finalMatrix.ExtractRotation();

                var dir = tempWorldPos - _sightLocationP1.position;

                //camera local position
                var alignedPosition = _cameraLocatorP1.localPosition;
                alignedPosition.z += param.SightOffset;

                if (CompareUtility.IsApproximatelyEqual(param.SightProgress, 1))
                {
                    alignedPosition.x += param.SightHorizontalShift;
                    alignedPosition.y += param.SightVerticalShift;
                }

                // 一人称开镜状态下,人物偏移(枪,分辨率相关)
                alignedPosition += param.FirstPersonSightOffset;
                // 镜与人眼距离(瞄准镜相关)
                alignedPosition.z += param.ScopeOffset;

                var alignedRotation =
                    Quaternion.AngleAxis(/*param.PitchAmplitude*/ -param.SightModelOffset, Vector3.right) *
                    _cameraLocatorP1.localRotation;
                alignedPosition = alignedRotation * alignedPosition;

                var alignedMatrix = _cameraLocatorP1.parent.localToWorldMatrix *
                                    Matrix4x4.TRS(alignedPosition, alignedRotation, Vector3.one);

                AlignCoordinateSystems(_sightLocationP1,
                                       Vector3.Lerp(_sightLocationP1.position, alignedMatrix.ExtractPosition(),
                                                    Mathf.Clamp01(param.SightProgress)),
                                       Quaternion.Slerp(_sightLocationP1.rotation, alignedMatrix.ExtractRotation(),
                                                        Mathf.Clamp01(param.SightProgress)), _directionLocatorP1);

                AlignLocatorRotation(param, dir, alignedMatrix);

                // 目标:sightlocater的向前方向旋转SightPeekDegree的角度,实现瞄准QE
                // 做法,把baseLocator先转换到sightLocation关节空间,对sightLocation的局部坐标系沿着自身向前旋转SightPeekDegree的角度,转换到世界坐标系,最后把结果转换到baseLocator父关节的坐标系
                var povitMatrix = _sightLocationP1.parent.localToWorldMatrix * Matrix4x4.TRS(
                    _sightLocationP1.localPosition,
                    Quaternion.AngleAxis(
                        CharacterStateConfigManager.Instance.SightPeekDegree * param.PeekAmplitude,
                        -_sightLocationP1.localRotation.Forward()) * _sightLocationP1.localRotation,
                    Vector3.one);

                AlignCoordinateSystems(_sightLocationP1, povitMatrix.ExtractPosition(), povitMatrix.ExtractRotation(),
                                       _directionLocatorP1);



                _sightLocationP1.localPosition = tempPos;
                _sightLocationP1.localRotation = tempRot;
            }
            else
            {
                _sightLocationP1 = null;
            }
        }