Ejemplo n.º 1
0
    // Use this for initialization
    void Start()
    {
        cameraScript = GetComponentInChildren <CameraFollowPlayer>();
        Debug.Log("CameraPan>>" + cameraScript);
        camHeight = cameraScript.cameraHeight;
        Debug.Log("CameraPan>> camHeight instantiated " + camHeight);
        Bounds b = cameraScript.OrthographicBounds();

        bgDim = cameraScript.GetBackroundDim();
    }
Ejemplo n.º 2
0
    void Update()
    {
        Bounds b = cameraScript.OrthographicBounds();

        if (Input.GetKeyUp(KeyCode.RightShift))
        {
            ZoomIn(new Vector3(30.5f, 25, 0), .1f, 3, 100.0f);
        }
        if (Input.GetKeyUp(KeyCode.RightCommand))
        {
            ZoomOut(bgDim.GetPivot(), .1f);
        }

        bool arrivedAtPosition = Vector3.Distance(transform.position, pos) < 1.0f;

        if (active)
        {
            if (pos != null && !arrivedAtPosition)
            {
                transform.position = Vector3.SmoothDamp(transform.position, pos, ref moveVelocity, dampTime, maxSpeed);
                // Debug.Log("Zoomout? height=" + camHeight + " Max=" + camMax);
                if (zoomIn && camHeight < camMax && camHeight <= maxZoomOutHeight)
                {
                    // Smooth the zoom out process using an exponential function.
                    // Goal was to start with a fast zooming and reduce the speed rapidly over time.
                    float zoomOutParameter = 1.0f / Mathf.Pow(1.7f, zoomOutModifier);
                    zoomOutParameter = zoomOutParameter * camHeighSpeed;
                    zoomOutModifier  = zoomOutModifier + 0.10f;
                    camHeight       += zoomOutParameter;
                }
            }

            if (arrivedAtPosition && zoomOut)
            {
                camHeight += camHeighSpeed;
//                Debug.Log("CameraPan>>" + cameraScript + " -> " + camHeight);
            }
            if (arrivedAtPosition && zoomIn)
            {
                camHeight -= camHeighSpeed;
//                Debug.Log("CameraPan>>" + cameraScript + " -> " + camHeight);
            }
            Camera.main.orthographicSize = camHeight;
            Camera.main.orthographicSize = Mathf.Clamp(camHeight, cameraScript.cameraHeightMin, camMax);
            // b.extends<---(bg) ------- b.center
            if (arrivedAtPosition && zoomOut && bgDim.GetBackgroundStart().x > b.center.x - b.extents.x &&
                bgDim.GetBackgroundStart().y > b.center.y - b.extents.y)
            {
                Debug.Log("Finished zooming out!");
                active = false;
            }
            if (zoomIn && arrivedAtPosition && camHeight <= camMin)
            {
                Debug.Log("Finished zooming in!");
                active = false;
            }
        }
        else if (resetOnce)
        {
            Invoke("StopZoom", 3);
            resetOnce = false;
        }
    }