Пример #1
0
        public void run(CamFilterResultInfo resultInfo)
        {
            if (_targetGhostPlayer == null || _triggerPoint == null)
            {
                return;
            }

            //  rotation
            Quaternion quaternionTo = Quaternion.LookRotation(resultInfo.resultMixedForward, resultInfo.resultMixedUp);

            _targetGhostRig.rotation = Quaternion.Lerp(_targetGhostRig.rotation, quaternionTo, Time.deltaTime * rotationSpeed);

            //  position
            Vector3 positionTo = Vector3.zero;

            if (resultInfo.hitTriggerPointLst.Count == 1)
            {
                positionTo = _targetGhostPlayer.position + _offsetVec3 * distanceOffset;
            }

            else
            {
                switch (positionBlendMode)
                {
                case PositionBlendMode.NONE:
                {
                    positionTo = resultInfo.resultMixedPosition;
                    break;
                }

                case PositionBlendMode.BLEND:
                {
                    positionTo = (resultInfo.resultMixedPosition + (_targetGhostPlayer.position + _offsetVec3 * distanceOffset)) * .5f;
                    break;
                }

                case PositionBlendMode.RAY:
                {
                    RaycastHit raycastInfo;
                    if (Physics.Raycast(resultInfo.resultMixedPosition, _targetGhostRig.forward, out raycastInfo, 200, LayerMask.GetMask("gameLayer_clickInput")))
                    {
                        Debug.DrawLine(resultInfo.resultMixedPosition, raycastInfo.point, Color.blue, 1f);
                        _offsetVec3Ray = resultInfo.resultMixedPosition - raycastInfo.point;
                        positionTo     = _targetGhostPlayer.position + _offsetVec3Ray * distanceOffset;
                    }

                    break;
                }

                case PositionBlendMode.CUSTOM:
                {
                    _offsetVec3Ray = resultInfo.resultMixedPosition - customBlendModeOffsetVec;
                    positionTo     = _targetGhostPlayer.position + _offsetVec3Ray * distanceOffset;
                    break;
                }
                }
            }

            _targetGhostRig.position = Vector3.Lerp(_targetGhostRig.position, positionTo, Time.deltaTime * moveSpeed);
        }
Пример #2
0
        public bool filter(CamFilterIntent camFilterIntent, out CamFilterResultInfo info)
        {
            this._camFilterIntent = camFilterIntent;

            List <CamInfluenceTriggerPoint> tempLst = createInfluenceQuery();

            //  过滤碰撞的 collider 存放入 _camInfiuencePointLst 中
            bool hasHit = tempLst.Count > 0;


            if (tempLst.Count == 2)
            {
                int a = 1;
            }

            if (hasHit)
            {
                Vector3[] positions = tempLst.Select <CamInfluenceTriggerPoint, Vector3>(tp => tp.getCamRigPosition()).ToArray();
                Vector3[] facings   = tempLst.Select <CamInfluenceTriggerPoint, Vector3>(tp => tp.getCamRigfacing()).ToArray();
                Vector3[] ups       = tempLst.Select <CamInfluenceTriggerPoint, Vector3>(tp => tp.getCamRigUp()).ToArray();
                float[][] weights   = tempLst.Select <CamInfluenceTriggerPoint, float[]>(tp => tp.getPositionAndQuaternionInfluenceWeight(camFilterIntent.followTargetGhost)).ToArray();


                Vector3 mixedPositionVec3 = Vector3.zero;
                Vector3 mixedUpVec3       = Vector3.zero;
                Vector3 mixedForwardVec3  = Vector3.zero;
                float   posWeightSum      = 0f;
                float   qWeightSum        = 0f;

                for (int i = 0; i < weights.Length; i++)
                {
                    float posW = weights[i][0];
                    float qW   = weights[i][1];

                    posWeightSum += posW;
                    qWeightSum   += qW;

                    mixedPositionVec3 += positions[i] * posW;
                    mixedForwardVec3  += facings[i] * qW;
                    mixedUpVec3       += ups[i] * qW;
                }

                _resultInfo.resultMixedPosition = mixedPositionVec3 / posWeightSum;
                _resultInfo.resultMixedForward  = mixedForwardVec3 / qWeightSum;
                _resultInfo.resultMixedUp       = mixedUpVec3 / qWeightSum;
                _resultInfo.hitTriggerPointLst  = tempLst;

                _debugTriggerPointLst = tempLst;
            }

            info = _resultInfo;

            return(hasHit);
        }
Пример #3
0
 void Awake()
 {
     _resultInfo = new CamFilterResultInfo();
 }