Ejemplo n.º 1
0
        public override void Update()
        {
            if (this.needLPF)
            {
                for (int i = this._lastFollowCenters.Length - 1; i > 0; i--)
                {
                    this._lastFollowCenters[i] = this._lastFollowCenters[i - 1];
                }
                this._lastFollowCenters[0] = this.followCenterXZPosition;
            }
            Vector3 followCenterXZPosition = this.followCenterXZPosition;

            this.followCenterXZPosition = this.avatar.XZPosition;
            Vector3 vector2 = followCenterXZPosition - this.followCenterXZPosition;

            this.needLerpPositionThisFrame       = true;
            this.needLerpForwardThisFrame        = true;
            this.needSmoothFollowCenterThisFrame = false;
            this.SubStateTransitionUpdate();
            if (this.recoverState.active)
            {
                this.recoverState.Update();
            }
            if (this._nextBaseState != null)
            {
                this._baseState.Exit();
                this._baseState.SetActive(false);
                this.lastBaseState = this._baseState;
                this._baseState    = this._nextBaseState;
                this._baseState.Enter();
                this._baseState.SetActive(true);
                this._nextBaseState = null;
                if ((this._shortState != null) && this._baseState.maskedShortStates.Contains(this._shortState))
                {
                    this.RemoveShortState();
                }
            }
            if (this._shortState != null)
            {
                this._shortState.Update();
                bool isSkippingBaseState = false;
                if (this._shortState != null)
                {
                    isSkippingBaseState = this._shortState.isSkippingBaseState;
                }
                if (!isSkippingBaseState || this._baseState.cannotBeSkipped)
                {
                    this._baseState.Update();
                }
                if (this._shortState != null)
                {
                    this._shortState.PostUpdate();
                }
            }
            else
            {
                this._baseState.Update();
            }
            if (this.needLPF && this.needSmoothFollowCenterThisFrame)
            {
                Vector3 vector3 = this.followCenterXZPosition;
                for (int j = 0; j < this._lastFollowCenters.Length; j++)
                {
                    vector3 += this._lastFollowCenters[j];
                }
                this.followCenterXZPosition = (Vector3)(vector3 / ((float)(this._lastFollowCenters.Length + 1)));
                UnityEngine.Debug.DrawLine(this.followCenterXZPosition, this.followCenterXZPosition + Vector3.up);
            }
            this.ConvertToFollowData();
            Vector3 cameraPosition = this.followData.cameraPosition;
            Vector3 cameraForward  = this.followData.cameraForward;
            Vector3 vector6        = cameraPosition - this.followData.followCenterPosition;
            float   magnitude      = vector6.magnitude;

            if (Physics.Raycast(this.followData.followCenterPosition, -this.followData.cameraForwardNoForwardDelta, out this._wallHit, magnitude, ((int)1) << InLevelData.CAMERA_COLLIDER_LAYER))
            {
                float num4 = magnitude - this._wallHit.distance;
                cameraPosition    = Vector3.Lerp(this._wallHit.point, cameraPosition, 0.1f);
                cameraPosition.y += num4 * 0.1f;
                base._owner.cameraComponent.nearClipPlane = Mathf.Lerp(base._owner.originalNearClip, 0.01f, num4 / magnitude);
                Vector3 axis = Vector3.Cross(Vector3.up, base.cameraForward);
                cameraForward = (Vector3)(Quaternion.AngleAxis((0.05f * num4) * 57.29578f, axis) * cameraForward);
                cameraForward.Normalize();
                base.cameraShakeRatio = 1f - (num4 / magnitude);
            }
            else
            {
                base._owner.cameraComponent.nearClipPlane = base._owner.originalNearClip;
            }
            float num5 = Time.deltaTime * base._owner.TimeScale;
            float num6 = (num5 != 0f) ? (vector2.magnitude / Time.deltaTime) : 0f;
            float num7 = Miscs.NormalizedClamp(num6, 5f, 12f);

            if (this.needLerpPositionThisFrame)
            {
                float   num8     = ((Time.deltaTime * 7.9f) * (1f + num7)) * this.posLerpRatio;
                Vector3 a        = base.cameraPosition - this.followData.followCenterPosition;
                Vector3 b        = cameraPosition - this.followData.followCenterPosition;
                Vector3 vector10 = Vector3.Slerp(a, b, Mathf.Clamp01(num8));
                base.cameraPosition = vector10 + this.followData.followCenterPosition;
                this.lerpPositionOvershootLastFrame = num8 >= 1f;
            }
            else
            {
                base.cameraPosition = cameraPosition;
            }
            if (this.needLerpForwardThisFrame)
            {
                float num9 = ((Time.deltaTime * 5f) * (1f + num7)) * this.forwardLerpRatio;
                this.cameraForward.Normalize();
                cameraForward.Normalize();
                base.cameraForward = MonoMainCamera.CameraForwardLerp(base.cameraForward, cameraForward, Mathf.Clamp01(num9));
                this.lerpForwardOvershootLastFrame = num9 >= 1f;
            }
            else if (this.focusOnAvatar)
            {
                Vector3 vector11 = this.followData.followCenterPosition - base.cameraPosition;
                base.cameraForward = vector11;
                this.cameraForward.Normalize();
            }
            else
            {
                base.cameraForward = cameraForward;
            }
            if (base.cameraFOV > 0f)
            {
                base._owner.cameraComponent.fieldOfView = base.cameraFOV;
            }
        }