Example #1
0
    private void FollowFocus(float deltaTime)
    {
        Vector3 position = this.transform.position;
        float   t        = Mathf.Min(deltaTime * this.Damping, 0.75f);
        //Debug.Log("TargetFocusPos:" + this.focusTargetPos);
        Vector3 vector = Vector3.Lerp(position, this.focusTargetPos, t);

        if (UnityToolBase.IsVaildPos(vector))
        {
            return;
        }
        //Debug.LogError("Follow");
        this.transform.position = vector;
        float      sqrMagnitude = (vector - this.focusTargetPos).sqrMagnitude;
        bool       bArray       = sqrMagnitude <= 1f;
        Quaternion rotation     = this.transform.rotation;
        Quaternion quaternion   = Quaternion.Slerp(rotation, Quaternion.Euler(this.focusTargetRot), t);

        if (UnityToolBase.IsVaildPos(quaternion))
        {
            return;
        }
        this.transform.rotation = quaternion;
        bool bArrayQuanternion = this.TestEulerAnglesInRange(quaternion.eulerAngles, this.focusTargetRot, 0.1f);

        //Debug.Log("Array:" + bArray);
        //D//ebug.Log("ArrayQuanternion:" + bArrayQuanternion);
        //Debug.Log("FollowOver:" + this.followFocusOver);
        if (bArrayQuanternion && bArray && this.followFocusOver)
        {
            //Debug.LogError("FocursOver");
            this.followFocusActive = false;
            this.followFocusOver   = true;
        }
    }
Example #2
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;
    }