Пример #1
0
    private void UpdateFocusTarget()
    {
        Vector3 cameraZoomDir = this.focusCameraStartPos - this.focusWorldPos;
        float   magnitude     = cameraZoomDir.magnitude;

        cameraZoomDir.Normalize();
        Quaternion rotation = Quaternion.AngleAxis(this.focusRotY, Vector3.up);

        cameraZoomDir = rotation * cameraZoomDir;
        if (this.focusAdjustXRotWithZoom)
        {
            float height = magnitude * (1f / this.focusZoomAmount);
            //Debug.Log(height);
            int   num2            = 60;
            float targetTheta     = this.GetTargetTheta((float)num2, height);
            float targetRotationX = targetTheta - this.cam2ZoomAngle;
            bool  flag            = false;
            if (targetRotationX < this.focusStartRot.x && this.focusZoomAmount > 1f)
            {
                flag = true;
            }
            if (targetRotationX > this.focusStartRot.x && this.focusZoomAmount < 1f)
            {
                flag = true;
            }
            if (flag)
            {
                //Debug.LogError("Over");
                float leapTime = (this.focusZoomAmount >= 1f) ? (this.focusZoomAmount - 1f) : ((1f - this.focusZoomAmount) * 2f);
                UnityToolBase.ClampMax(ref leapTime, 1f);
                if (this.focusRotX == 0f)
                {
                    leapTime = 1f;
                }
                else
                {
                    float num5 = 1f - leapTime;
                    leapTime = 1f - num5 * num5;
                }
                float target = Mathf.Lerp(this.focusStartRot.x, targetRotationX, leapTime);
                this.focusRotX = Mathf.DeltaAngle(this.focusStartRot.x, target);
                float   num6    = targetRotationX + this.cam2ZoomAngle;
                Vector3 vector2 = new Vector3(cameraZoomDir.x, 0f, cameraZoomDir.z);
                vector2.Normalize();
                vector2  *= height * Mathf.Cos(num6 * 0.0174532924f);
                vector2.y = height * Mathf.Sin(num6 * 0.0174532924f);
                Vector3 vector3 = vector2;
                vector3.Normalize();
                cameraZoomDir = vector3;
            }
        }
        else
        {
            if (this.RestrictCamera)
            {
                float height = cameraZoomDir.y * magnitude * (1f / this.focusZoomAmount);
                //if (num7 > 3000f)
                //{
                //    num7 = 3000f;
                //}
                if (height > this.MaxHeight)
                {
                    height = this.MaxHeight;
                }
                if (height < this.MinCameraHeight)
                {
                    height = this.MinCameraHeight;
                }
                this.focusRotX = this.GetLimitedXRotAdjustment(height, this.focusRotX, this.focusStartRot.x);
            }
            Vector3    axis      = Vector3.Cross(cameraZoomDir, Vector3.up);
            Quaternion rotation2 = Quaternion.AngleAxis(this.focusRotX, axis);
            cameraZoomDir = rotation2 * cameraZoomDir;
        }
        Vector3 vector4 = cameraZoomDir * magnitude;

        vector4 *= 1f / this.focusZoomAmount;
        Vector3 vector5   = this.focusWorldPos;
        Vector3 vector6   = vector5 + vector4;
        float   maxHeight = this.MaxHeight;

        if (vector6.y > maxHeight)
        {
            float distance = maxHeight - this.focusWorldPos.y;
            float d        = distance / cameraZoomDir.y;
            vector4 = cameraZoomDir * d;
            vector6 = vector5 + vector4;
        }
        if (this.focusDoDrag)
        {
            Ray     limitedScreenPointToRay = this.GetLimitedScreenPointToRay(this.focusCurrentTouchPos);
            Vector3 b;
            if (limitedScreenPointToRay.direction.y < 0f)
            {
                float num11 = limitedScreenPointToRay.origin.y - this.focusWorldPos.y;
                b = limitedScreenPointToRay.origin + limitedScreenPointToRay.direction * -num11 / limitedScreenPointToRay.direction.y;
                this.focusLastValidDragPoint = b;
            }
            else
            {
                b = this.focusLastValidDragPoint;
            }
            Ray limitedScreenPointToRay2 = this.GetLimitedScreenPointToRay(this.focusDragStart);
            if (limitedScreenPointToRay2.direction.y < 0f)
            {
                float   num12 = limitedScreenPointToRay2.origin.y - this.focusWorldPos.y;
                Vector3 a     = limitedScreenPointToRay2.origin + limitedScreenPointToRay2.direction * -num12 / limitedScreenPointToRay2.direction.y;
                Vector3 b2    = a - b;
                vector5 = this.focusWorldPos + b2;
                vector5 = this.GetLimitedPosition(vector5);
                vector6 = vector5 + vector4;
            }
        }
        if (UnityToolBase.IsVaildPos(vector6))
        {
            return;
        }
        if (this.RestrictCamera)
        {
            //float apparentLimitedHeightAtPoint = HeightMapManager.GetApparentLimitedHeightAtPoint(vector6.x, vector6.z);
            //float minCameraHeight = this.MinCameraHeight;
            //if (vector6.y < apparentLimitedHeightAtPoint + minCameraHeight)
            //{
            //    vector6.y = apparentLimitedHeightAtPoint + minCameraHeight;
            //}
            if (vector6.y < vector5.y + this.MinCameraHeight)
            {
                vector6.y = vector5.y + this.MinCameraHeight;
            }
            this.focusRotX = this.GetLimitedXRotAdjustment(this.focusTargetPos.y, this.focusRotX, this.focusStartRot.x);
        }
        this.focusTargetPos = vector6;
        Vector3 vector7 = this.focusStartRot;

        vector7.y          += this.focusRotY;
        vector7.x          += this.focusRotX;
        vector7.z           = 0f;
        this.focusTargetRot = vector7;
    }
Пример #2
0
    private void UpdateKeyPanAmount(float timeDelta)
    {
        float num  = Mathf.Sign(this.keyPanX) * Mathf.Sqrt(Mathf.Abs(this.keyPanX));
        float num2 = Mathf.Sign(this.keyPanZ) * Mathf.Sqrt(Mathf.Abs(this.keyPanZ));

        if (num != 0f || num2 != 0f)
        {
            float num3 = this.TargetCamera.transform.position.y;
            if (num3 < 3f)
            {
                num3 = 3f;
            }
            float num4 = 1f + 5f * 0.5f;
            num  *= num4 * timeDelta * num3;
            num2 *= num4 * timeDelta * num3;
            this.keyPanAmount = this.GetPannedPosition(Vector3.zero, num, num2);
            if (!this.panXActive)
            {
                float num5 = timeDelta * 10f;
                if (this.keyPanX > 0f)
                {
                    this.keyPanX -= num5;
                    UnityToolBase.ClampMin(ref this.keyPanX, 0f);
                }
                else if (this.keyPanX < 0f)
                {
                    this.keyPanX += num5;
                    UnityToolBase.ClampMax(ref this.keyPanX, 0f);
                }
            }
            else
            {
                float num6 = timeDelta * 5f;
                if (this.keyPanX > 0f)
                {
                    this.keyPanX += num6;
                    UnityToolBase.ClampMax(ref this.keyPanX, 1f);
                }
                else if (this.keyPanX < 0f)
                {
                    this.keyPanX -= num6;
                    UnityToolBase.ClampMin(ref this.keyPanX, -1f);
                }
            }
            if (!this.panZActive)
            {
                float num7 = timeDelta * 10f;
                if (this.keyPanZ > 0f)
                {
                    this.keyPanZ -= num7;
                    UnityToolBase.ClampMin(ref this.keyPanZ, 0f);
                }
                else if (this.keyPanZ < 0f)
                {
                    this.keyPanZ += num7;
                    UnityToolBase.ClampMax(ref this.keyPanZ, 0f);
                }
            }
            else
            {
                float num8 = timeDelta * 5f;
                if (this.keyPanZ > 0f)
                {
                    this.keyPanZ += num8;
                    UnityToolBase.ClampMax(ref this.keyPanZ, 1f);
                }
                else if (this.keyPanZ < 0f)
                {
                    this.keyPanZ -= num8;
                    UnityToolBase.ClampMin(ref this.keyPanZ, -1f);
                }
            }
        }
        else
        {
            this.keyPanAmount = Vector3.zero;
        }
    }