Ejemplo n.º 1
0
 protected override void PostPipelineStageCallback(CinemachineVirtualCameraBase vcam, CinemachineCore.Stage stage, ref CameraState state, float deltaTime)
 {
     CinemachineCollider.VcamExtraState vcamExtraState = null;
     if (stage == CinemachineCore.Stage.Body)
     {
         vcamExtraState = base.GetExtraState <CinemachineCollider.VcamExtraState>(vcam);
         vcamExtraState.targetObscured       = false;
         vcamExtraState.colliderDisplacement = 0f;
         vcamExtraState.debugResolutionPath  = null;
     }
     if (stage == CinemachineCore.Stage.Body && this.m_AvoidObstacles)
     {
         Vector3 vector = this.PreserveLignOfSight(ref state, ref vcamExtraState);
         if (this.m_Damping > 0f && deltaTime >= 0f)
         {
             Vector3 vector2 = vector - vcamExtraState.m_previousDisplacement;
             vector2 = Damper.Damp(vector2, this.m_Damping, deltaTime);
             vector  = vcamExtraState.m_previousDisplacement + vector2;
         }
         vcamExtraState.m_previousDisplacement = vector;
         state.PositionCorrection            += vector;
         vcamExtraState.colliderDisplacement += vector.magnitude;
     }
     if (stage == CinemachineCore.Stage.Aim)
     {
         vcamExtraState = base.GetExtraState <CinemachineCollider.VcamExtraState>(vcam);
         vcamExtraState.targetObscured = this.CheckForTargetObstructions(state);
         if (vcamExtraState.targetObscured)
         {
             state.ShotQuality *= 0.2f;
         }
         if (vcamExtraState.colliderDisplacement > 0f)
         {
             state.ShotQuality *= 0.8f;
         }
         float num = 0f;
         if (this.m_OptimalTargetDistance > 0f && state.HasLookAt)
         {
             float num2 = Vector3.Magnitude(state.ReferenceLookAt - state.FinalPosition);
             if (num2 <= this.m_OptimalTargetDistance)
             {
                 float num3 = this.m_OptimalTargetDistance / 2f;
                 if (num2 >= num3)
                 {
                     num = 0.2f * (num2 - num3) / (this.m_OptimalTargetDistance - num3);
                 }
             }
             else
             {
                 num2 -= this.m_OptimalTargetDistance;
                 float num4 = this.m_OptimalTargetDistance * 3f;
                 if (num2 < num4)
                 {
                     num = 0.2f * (1f - num2 / num4);
                 }
             }
             state.ShotQuality *= 1f + num;
         }
     }
 }
Ejemplo n.º 2
0
        private Vector3 PreserveLignOfSight(ref CameraState state, ref CinemachineCollider.VcamExtraState extra)
        {
            Vector3 result = Vector3.zero;

            if (state.HasLookAt)
            {
                Vector3 correctedPosition = state.CorrectedPosition;
                Vector3 referenceLookAt   = state.ReferenceLookAt;
                Vector3 vector            = correctedPosition;
                Vector3 vector2           = vector - referenceLookAt;
                float   magnitude         = vector2.magnitude;
                float   num = Mathf.Max(this.m_MinimumDistanceFromTarget, 0.0001f);
                if (magnitude > num)
                {
                    vector2.Normalize();
                    float num2 = magnitude - num;
                    if (this.m_DistanceLimit > 0.0001f)
                    {
                        num2 = Mathf.Min(this.m_DistanceLimit, num2);
                    }
                    Ray ray = new Ray(vector - num2 * vector2, vector2);
                    num2 += 0.001f;
                    RaycastHit obstacle;
                    if (num2 > 0.0001f && this.RaycastIgnoreTag(ray, out obstacle, num2))
                    {
                        float distance = Mathf.Max(0f, obstacle.distance - 0.001f);
                        vector = ray.GetPoint(distance);
                        extra.AddPointToDebugPath(vector);
                        if (this.m_Strategy != CinemachineCollider.ResolutionStrategy.PullCameraForward)
                        {
                            vector = this.PushCameraBack(vector, vector2, obstacle, referenceLookAt, new Plane(state.ReferenceUp, correctedPosition), magnitude, this.m_MaximumEffort, ref extra);
                        }
                    }
                }
                if (this.m_CameraRadius > 0.0001f)
                {
                    vector += this.RespectCameraRadius(vector, state.ReferenceLookAt);
                }
                else if (this.mCameraColliderGameObject != null)
                {
                    this.CleanupCameraCollider();
                }
                result = vector - correctedPosition;
            }
            return(result);
        }
Ejemplo n.º 3
0
        private Vector3 PushCameraBack(Vector3 currentPos, Vector3 pushDir, RaycastHit obstacle, Vector3 lookAtPos, Plane startPlane, float targetDistance, int iterations, ref CinemachineCollider.VcamExtraState extra)
        {
            Vector3 vector = Vector3.zero;

            if (!this.GetWalkingDirection(currentPos, pushDir, obstacle, ref vector))
            {
                return(currentPos);
            }
            Ray   ray = new Ray(currentPos, vector);
            float num = this.GetPushBackDistance(ray, startPlane, targetDistance, lookAtPos);

            if (num <= 0.0001f)
            {
                return(currentPos);
            }
            float num2 = this.ClampRayToBounds(ray, num, obstacle.collider.bounds);

            num = Mathf.Min(num, num2 + 0.001f);
            RaycastHit obstacle2;
            Vector3    vector2;

            if (this.RaycastIgnoreTag(ray, out obstacle2, num))
            {
                float distance = obstacle2.distance - 0.001f;
                vector2 = ray.GetPoint(distance);
                extra.AddPointToDebugPath(vector2);
                if (iterations > 1)
                {
                    vector2 = this.PushCameraBack(vector2, vector, obstacle2, lookAtPos, startPlane, targetDistance, iterations - 1, ref extra);
                }
                return(vector2);
            }
            vector2 = ray.GetPoint(num);
            vector  = vector2 - lookAtPos;
            float      magnitude = vector.magnitude;
            RaycastHit raycastHit;

            if (magnitude < 0.0001f || this.RaycastIgnoreTag(new Ray(lookAtPos, vector), out raycastHit, magnitude - 0.001f))
            {
                return(currentPos);
            }
            ray = new Ray(vector2, vector);
            extra.AddPointToDebugPath(vector2);
            num = this.GetPushBackDistance(ray, startPlane, targetDistance, lookAtPos);
            if (num > 0.0001f)
            {
                if (!this.RaycastIgnoreTag(ray, out obstacle2, num))
                {
                    vector2 = ray.GetPoint(num);
                    extra.AddPointToDebugPath(vector2);
                }
                else
                {
                    float distance2 = obstacle2.distance - 0.001f;
                    vector2 = ray.GetPoint(distance2);
                    extra.AddPointToDebugPath(vector2);
                    if (iterations > 1)
                    {
                        vector2 = this.PushCameraBack(vector2, vector, obstacle2, lookAtPos, startPlane, targetDistance, iterations - 1, ref extra);
                    }
                }
            }
            return(vector2);
        }