Пример #1
0
    // Update is called once per frame
    void Update()
    {
        float scrollUpdate = Input.GetAxis("Mouse ScrollWheel") * Time.deltaTime * scrollSpeed.y;
        float xUpdate = Input.GetAxis("Horizontal") * Time.deltaTime * scrollSpeed.x;
        float zUpdate = Input.GetAxis("Vertical") * Time.deltaTime * scrollSpeed.z;

        xPercent += xUpdate;
        zPercent += zUpdate;

        if (scrollUpdate != 0)
        {
            /*xPercent = xPercent + (scrollUpdate * scrollSpeed.x) * (tentativePercent.x - xPercent);
            zPercent = zPercent + (scrollUpdate * scrollSpeed.z) * (tentativePercent.z - zPercent);*/

            if (zoomPercent != 1 )
            {
                Vector3 tentativePercent = WorldToPercent(MouseToWorld());

                xPercent = tentativePercent.x;
                zPercent = tentativePercent.z;

            }
            zoomPercent = zoomPercent + scrollUpdate;

            zoomPercent = Mathf.Min(zoomPercent, 1);
            zoomPercent = Mathf.Max(0, zoomPercent);

        }

        xPercent = Mathf.Min(xPercent, 1);
        xPercent = Mathf.Max(0, xPercent);

        zPercent = Mathf.Min(zPercent, 1);
        zPercent = Mathf.Max(0, zPercent);

         float zoomX = zoomPercent * (xPercent - 0.5f) *2 * xRange;
        float zoomY = YfromZoomPercent();
        float zoomZ = zoomPercent  *(zPercent - 0.5f) * 2 * zRange;

        float zoomAngleX = fartherstZoomXAngle;

        if (zoomPercent >= angleChangeZoomPercent)
        {
            float partialPercent = (zoomPercent - angleChangeZoomPercent) / (1 - angleChangeZoomPercent);
            zoomAngleX = fartherstZoomXAngle - partialPercent * (fartherstZoomXAngle - closestZoomXAngle);
            zoomZ += partialPercent * closestAdjustZ;
        }

        translateAnimation = new GameAnimation(transform, AnimationTypes.Simple, adjust+ new Vector3(zoomX, zoomY, zoomZ), Quaternion.Euler(zoomAngleX, 0, 0), 0.25f);
        translateAnimation.Continue();
    }