示例#1
0
    public void Zoom()
    {
        if (IsZoomed || cardMovementLerpInformations.Count > 0 || !IsZoomOutInPlace)
        {
            return;
        }

        IsZoomed         = true;
        IsZoomOutInPlace = false;
        GameController.Instance.Pause();

        zoomMovementLerpInformations.Clear();
        zoomRotationLerpInformations.Clear();
        positionsBeforeZoom.Clear();
        rotationsBeforeZoom.Clear();

        const float gapBetweenEachCard = 1.0f;
        float       offset             = (cardGameObjects.Count - 1) * gapBetweenEachCard / 2f;

        const float totalCardCurve = 50f;
        const float turnOffset     = -1f * (totalCardCurve / 2f);
        float       turnPerCard    = totalCardCurve / cardGameObjects.Count;
        float       rotationOffset = turnOffset + (cardGameObjects.Count - 1) * turnPerCard / 2f;

        float yOffsetScale = cardGameObjects.Count / 500f;

        for (int i = 0; i < cardGameObjects.Count; i++)
        {
            float zRotation = -(turnOffset + i * turnPerCard - rotationOffset);

            Quaternion destinationRotation = Quaternion.Euler(0, 0, zRotation);
            LerpInformation <Quaternion> rotationLerpInformation = new LerpInformation <Quaternion>(cardGameObjects[i].transform.rotation, destinationRotation, ZoomLerpDuration, Quaternion.Lerp);

            Vector3 destination = new Vector3(i * gapBetweenEachCard - offset, -(Mathf.Abs(zRotation) * yOffsetScale));
            LerpInformation <Vector3> positionLerpInformation = new LerpInformation <Vector3>(cardGameObjects[i].transform.position, destination, ZoomLerpDuration, Vector3.Lerp);

            zoomMovementLerpInformations.Add(cardGameObjects[i], positionLerpInformation);
            zoomRotationLerpInformations.Add(cardGameObjects[i], rotationLerpInformation);

            positionsBeforeZoom.Add(cardGameObjects[i], cardGameObjects[i].transform.position);
            rotationsBeforeZoom.Add(cardGameObjects[i], cardGameObjects[i].transform.rotation);

            cardGameObjects[i].GetComponent <SpriteRenderer>().sortingLayerName = "Display Card";
        }

        zoomScaleLperInformation =
            new LerpInformation <Vector3>(transform.localScale, Vector3.one, ZoomLerpDuration, Vector3.Lerp);

        ZoomedIn?.Invoke(this, new CardStackEventArgs(this));
    }
    void FinishTransitioning()
    {
        transitioning = false;
        focused       = !focused;
        lerpPct       = 0;

        if (focused)
        {
            ZoomedIn?.Invoke();
        }
        else
        {
            ZoomedOut?.Invoke();
        }
    }