Beispiel #1
0
    void Update()
    {
        if (!mAnimating)
        {
            return;
        }

        bool done = false;

        mCurrentTime += UnityEngine.Time.unscaledDeltaTime;
        if (mCurrentTime >= Time)
        {
            mCurrentTime = Time;
            done         = true;
        }

        float t = 1.0f - mCurrentTime / Time;

        mTransform.anchoredPosition = mStartPosition * Easing.EaseInOutCubic(t);

        if (done)
        {
            mAnimating = false;
            mTargetTransform.SetParent(mTargetTransformParent);
            mTargetTransform = null;
        }
    }
Beispiel #2
0
    public IEnumerator MoveTo(Vector2 target, float duration, int type)
    {
        float   t                = 0;
        Vector2 start            = rectTransform.anchoredPosition;
        float   distancePosition = Vector2.Distance(start, target);
        Vector2 unit             = Vector3.Normalize(target - start);

        while (t < duration)
        {
            t += Time.deltaTime;
            if (t > duration)
            {
                t = duration;
            }
            float traveled = 0;
            if (type == 0) //In
            {
                traveled = Easing.EaseInCubic(t, 0, distancePosition, duration);
            }
            else if (type == 1) //Out
            {
                traveled = Easing.EaseOutCubic(t, 0, distancePosition, duration);
            }
            else if (type == 2) //InOut
            {
                traveled = Easing.EaseInOutCubic(t, 0, distancePosition, duration);
            }
            rectTransform.anchoredPosition = start + unit * traveled;

            yield return(null);
        }
    }
    void SetTime(float time)
    {
        float scale = Easing.EaseInOutCubic(time / Time);
        mTransform.localScale = new Vector3(1.0f, scale, 1.0f);

        var color = DarkOverlay.color;
        color.a = mOverlayAlpha * Mathf.Clamp(scale, 0.0f, 1.0f);
        DarkOverlay.color = color;
    }
Beispiel #4
0
    IEnumerator MoveToPointCoroutine(Vector3 endPoint, Quaternion endRot, float moveTime)
    {
        // Indicate we're moving
        Moving = true;

        // Store the initial conditions for interpolation
        Vector3    startPoint = transform.position;
        Quaternion startRot   = transform.rotation;

        // Apply the height offset
        endPoint += homeTransform.up * heightOffset;

        // We want to pass through the center point
        Vector3 centerPoint = (startPoint + endPoint) / 2;

        // But also lift off, so we move it up arbitrarily by half the step distance
        centerPoint += homeTransform.up * Vector3.Distance(startPoint, endPoint) / 2f;

        // Time since step started
        float timeElapsed = 0;

        // Here we use a do-while loop so normalized time goes past 1.0 on the last iteration,
        // placing us at the end position before exiting.
        do
        {
            timeElapsed += Time.deltaTime;

            // Get the normalized time
            float normalizedTime = timeElapsed / moveTime;

            // Apply easing
            normalizedTime = Easing.EaseInOutCubic(normalizedTime);

            // Note: Unity's Lerp and Slerp functions are clamped at 0.0 and 1.0,
            // so even if our normalizedTime goes past 1.0, we won't overshoot the end

            // Quadratic bezier curve
            // See https://en.wikipedia.org/wiki/B%C3%A9zier_curve#Constructing_B.C3.A9zier_curves
            transform.position =
                Vector3.Lerp(
                    Vector3.Lerp(startPoint, centerPoint, normalizedTime),
                    Vector3.Lerp(centerPoint, endPoint, normalizedTime),
                    normalizedTime
                    );

            transform.rotation = Quaternion.Slerp(startRot, endRot, normalizedTime);

            // Wait for one frame
            yield return(null);
        }while (timeElapsed < moveTime);

        Moving = false;
    }
Beispiel #5
0
    IEnumerator Move()
    {
        Moving = true;

        Vector3    startPoint = transform.position;
        Quaternion startRot   = transform.rotation;

        Quaternion endRot = homeTransform.rotation;

        // Directional vector from the foot to the home position
        Vector3 towardHome = (homeTransform.position - transform.position);
        // Total distnace to overshoot by
        float   overshootDistance = wantStepAtDistance * stepOvershootFraction;
        Vector3 overshootVector   = towardHome * overshootDistance;

        // Since we don't ground the point in this simplified implementation,
        // we restrict the overshoot vector to be level with the ground by projecting it
        overshootVector = Vector3.ProjectOnPlane(overshootVector, Vector3.up);

        // Apply the overshoot
        Vector3 endPoint = homeTransform.position + overshootVector;

        // We want to pass through the center point
        Vector3 centerPoint = (startPoint + endPoint) / 2;

        // But also lift off, so we move it up by half the step distance (arbitrarily)
        centerPoint += homeTransform.up * Vector3.Distance(startPoint, endPoint) / 2f;

        float timeElapsed = 0;

        do
        {
            timeElapsed += Time.deltaTime;
            float normalizedTime = timeElapsed / moveDuration;

            normalizedTime = Easing.EaseInOutCubic(normalizedTime);

            // Quadratic bezier curve
            transform.position =
                Vector3.Lerp(
                    Vector3.Lerp(startPoint, centerPoint, normalizedTime),
                    Vector3.Lerp(centerPoint, endPoint, normalizedTime),
                    normalizedTime
                    );

            transform.rotation = Quaternion.Slerp(startRot, endRot, normalizedTime);

            yield return(null);
        }while (timeElapsed < moveDuration);

        Moving = false;
    }
Beispiel #6
0
    public IEnumerator ShowScore(float duration)
    {
        float t = 0;

        while (t < duration)
        {
            t += Time.deltaTime;
            if (t > duration)
            {
                t = duration;
            }
            float alpha = Easing.EaseInOutCubic(t, 0, 1, duration);
            scoreText.color = new Color(1f, 1f, 1f, alpha);
            yield return(null);
        }
    }
Beispiel #7
0
    protected void Update()
    {
        if (_animationActive == true)
        {
            Vector3 tmp = Vector3.Lerp(_prevPosition, _nextPosition, Easing.EaseInOutCubic(_lerpPosition));
            tmp.y = Mathf.Sin(_lerpPosition * Mathf.PI) * AnimationJumpHeight;

            transform.position   = tmp;
            transform.localScale = Vector3.one * (0.5f + Mathf.Sin(Easing.EaseInOut(_lerpPosition) * Mathf.PI) * AnimationScaleFactor * 0.5f);

            _lerpPosition += Time.deltaTime * kAnimationsInvMaxLength;
            if (_lerpPosition > 1.0f)
            {
                _lerpPosition = 1.0f;
            }
        }
    }
Beispiel #8
0
    public IEnumerator BackgroudFade(float alpha, float duration)
    {
        float start = uiBackground.color.a;
        Color c     = uiBackground.color;
        float t     = 0;

        while (t < duration)
        {
            t += Time.deltaTime;
            if (t > duration)
            {
                t = duration;
            }
            float val = Easing.EaseInOutCubic(t, start, alpha - start, duration);
            uiBackground.color = new Color(c.r, c.g, c.b, val);

            yield return(null);
        }
    }