示例#1
0
    void Update()
    {
        if (Input.touchCount == 2)
        {
            Touch t1 = Input.GetTouch(0);
            Touch t2 = Input.GetTouch(1);

            var touchCenter = (t1.position + t2.position) * 0.5f;

            inputHandler.GetWorldPoint(touchCenter, out Vector3 touchCenterWorld);

            if (t1.phase == TouchPhase.Began || t2.phase == TouchPhase.Began)
            {
                initialTouchVector = t2.position - t1.position;
                initialCameraYaw   = currentPivot.rotation.eulerAngles.y;

                initialZoom      = map.zoom;
                invTouchDistance = 1f / (t1.position - t2.position).magnitude;
            }
            else
            {
                float distance = (t1.position - t2.position).magnitude;
                float newZoom  = initialZoom + Mathf.Log10(distance * invTouchDistance) / Log2;

                var yawDiff = Angle(t2.position - t1.position, initialTouchVector) - currentPivot.rotation.eulerAngles.y + initialCameraYaw;

                map.ChangeZoom(newZoom - map.zoom, touchCenterWorld.x, touchCenterWorld.z);
                PanMap(prevTouchCenterWorld);
                Orbit(0, yawDiff);
                PanMap(-touchCenterWorld);
            }

            prevTouchCenterWorld = touchCenterWorld;
        }

#if UNITY_EDITOR
        if (needToUpdateBounds || !Application.isPlaying)
#else
        if (needToUpdateBounds)
#endif
        {
            needToUpdateBounds = false;

            if (needToUpdateViewport)
            {
                needToUpdateViewport = false;
                UpdateCameraOffset();
            }

            UpdateMapBounds(needToAdjustZoom);
            needToAdjustZoom = false;
        }
    }
示例#2
0
 private void Update()
 {
     if (updateTime < Time.time)
     {
         updateTime += 0.05f;
         if (minusButton.Pressed)
         {
             map.ChangeZoom(-0.1f);
         }
         if (plusButton.Pressed)
         {
             map.ChangeZoom(0.1f);
         }
     }
 }
示例#3
0
    private void Zoom(float change)
    {
        switch (movementType)
        {
        case MovementType.MoveCamera:
            SetDistanceToTarget(Mathf.Max(MinDistanceToTarget, distanceToTarget - change * ZoomScale * distanceToTarget));
            break;

        case MovementType.MoveMap:
            Vector3 zoomPoint;
            inputHandler.GetWorldPoint(Input.mousePosition, out zoomPoint);
            map.ChangeZoom(change, zoomPoint.x, zoomPoint.z);
            break;
        }
    }
示例#4
0
    //
    // Event Methods
    //

    private void OnZoomInClick()
    {
        zoomingChange = 0.1f;
        nextUpdate    = Time.time + 0.25f;
        map.ChangeZoom(zoomingChange);
    }