Ejemplo n.º 1
0
    /// <summary>
    /// Color Enumerator Function
    /// </summary>
    /// <param name="forward">True if it's an open animation, False if its a Close Animation</param>
    /// <returns>The IEnumerator</returns>
    public IEnumerator ColorFunc(bool forward)
    {
        if (!ColorData.Enable)
        {
            yield break;
        }

        _ColorState = VCAnimationState.AnimStarted;

        VCColorComponentType ComponentType = VCColorComponentType.None;

        if (GetComponent<SpriteRenderer>())
        {
            ComponentType = VCColorComponentType.SpriteRenderer;
        }
        else if (GetComponent<Renderer>())
        {
            ComponentType = VCColorComponentType.Renderer;
        }
        else if (GetComponent<Image>())
        {
            ComponentType = VCColorComponentType.Image;
        }
        else if (GetComponent<Text>())
        {
            ComponentType = VCColorComponentType.Text;
        }
        else
        {
            yield break;
        }

        while (true)
        {
            if (forward)
            {
                onColorOpenStart.Invoke();
            }
            else
            {
                onColorCloseStart.Invoke();
            }

            float time = 0;
            bool bDelayed = false;

            float Duration = forward ? ColorData.OpenAnimation.Duration : ColorData.CloseAnimation.Duration;
            float Delay = forward ? ColorData.OpenAnimation.Delay : ColorData.CloseAnimation.Delay;
            Color Start = forward ? ColorData.OpenAnimation.Start : ColorData.CloseAnimation.Start;
            Color End = forward ? ColorData.OpenAnimation.End : ColorData.CloseAnimation.End;

            if (!bDelayed && Delay > 0)
            {
                bDelayed = true;
                yield return StartCoroutine(WaitForRealSeconds(Delay));
            }

            while (true)
            {
                time += GetDeltaTime();
                Color CurrentColor = GetAnimationValueColor(ColorData, time, forward);
                switch (ComponentType)
                {
                    case VCColorComponentType.SpriteRenderer:
                        GetComponent<SpriteRenderer>().color = CurrentColor;
                        break;
                    case VCColorComponentType.Renderer:
                        GetComponent<Renderer>().material.color = CurrentColor;
                        break;
                    case VCColorComponentType.Image:
                        GetComponent<Image>().color = CurrentColor;
                        break;
                    case VCColorComponentType.Text:
                        GetComponent<Text>().color = CurrentColor;
                        break;
                    default:
                        break;
                }
                if (time < Duration)
                {
                    yield return StartCoroutine(WaitForRealSeconds(.016f));
                }
                else
                {
                    CurrentColor = Color.Lerp(Start, End, 1); ;
                    switch (ComponentType)
                    {
                        case VCColorComponentType.SpriteRenderer:
                            GetComponent<SpriteRenderer>().color = CurrentColor;
                            break;
                        case VCColorComponentType.Renderer:
                            GetComponent<Renderer>().material.color = CurrentColor;
                            break;
                        case VCColorComponentType.Image:
                            GetComponent<Image>().color = CurrentColor;
                            break;
                        case VCColorComponentType.Text:
                            GetComponent<Text>().color = CurrentColor;
                            break;
                        default:
                            break;
                    }
                    break;
                }
            }

            if (forward)
            {
                onColorOpenEnd.Invoke();
            }
            else
            {
                onColorCloseEnd.Invoke();
            }

            if (forward)
            {
                if (ColorData.Autoclose)
                {
                    forward = false;
                    yield return StartCoroutine(WaitForRealSeconds(ColorData.AutocloseDelay));
                }
                else
                {
                    if (!ColorData.Loop)
                    {
                        break;
                    }
                }
            }
            else
            {
                if (!ColorData.Loop)
                {
                    break;
                }

                forward = true;
            }
        }

        _ColorState = VCAnimationState.AnimFinished;
        OnAnimationFinished();
    }
Ejemplo n.º 2
0
    /// <summary>
    /// Alpha Enumerator Function
    /// </summary>
    /// <param name="forward">True if it's an open animation, False if its a Close Animation</param>
    /// <returns>The IEnumerator</returns>
    public IEnumerator AlphaFunc(bool forward)
    {
        if (!Alpha.Enable || !canvasGroup)
        {
            yield break;
        }

        _AlphaState = VCAnimationState.AnimStarted;

        while (true)
        {
            if (forward)
            {
                onAlphaOpenStart.Invoke();
            }
            else
            {
                onAlphaCloseStart.Invoke();
            }

            float time = 0;
            bool bDelayed = false;

            float Duration = forward ? Alpha.OpenAnimation.Duration : Alpha.CloseAnimation.Duration;
            float Delay = forward ? Alpha.OpenAnimation.Delay : Alpha.CloseAnimation.Delay;
            float Start = forward ? Alpha.OpenAnimation.Start : Alpha.CloseAnimation.Start;
            float End = forward ? Alpha.OpenAnimation.End : Alpha.CloseAnimation.End;

            if (!bDelayed && Delay > 0)
            {
                bDelayed = true;
                yield return StartCoroutine(WaitForRealSeconds(Delay));
            }

            while (true)
            {
                time += GetDeltaTime();
                canvasGroup.alpha = Lerp(Start, End, (float)time / Duration);
                if (time < Duration)
                {
                    yield return StartCoroutine(WaitForRealSeconds(.016f));
                }
                else
                {
                    canvasGroup.alpha = Lerp(Start, End, 1);
                    break;
                }
            }

            if (forward)
            {
                onAlphaOpenEnd.Invoke();
            }
            else
            {
                onAlphaCloseEnd.Invoke();
            }

            if (forward)
            {
                if (Alpha.Autoclose)
                {
                    forward = false;
                    yield return StartCoroutine(WaitForRealSeconds(Alpha.AutocloseDelay));
                }
                else
                {
                    if (!Alpha.Loop)
                    {
                        break;
                    }
                }
            }
            else
            {
                if (!Alpha.Loop)
                {
                    break;
                }

                forward = true;
            }
        }

        _AlphaState = VCAnimationState.AnimFinished;
        OnAnimationFinished();
    }
Ejemplo n.º 3
0
    /// <summary>
    /// Stops All the Open Animations
    /// </summary>
    public void StopAnimation()
    {
        StopMovementAnimation();
        StopScaleAnimation();
        StopRotationAnimation();
        StopAlphaAnimation();
        StopColorAnimation();

        _MovementState = VCAnimationState.AnimFinished;
        _ScaleState = VCAnimationState.AnimFinished;
        _RotationState = VCAnimationState.AnimFinished;
        _AlphaState = VCAnimationState.AnimFinished;
        _ColorState = VCAnimationState.AnimFinished;

        if (CurrentAnimDirection == VCAnimationDirection.Forward)
        {
            onOpenEnd.Invoke();
        }
        else
        {
            onCloseEnd.Invoke();
        }
    }
Ejemplo n.º 4
0
    /// <summary>
    /// Scale Enumerator Function
    /// </summary>
    /// <param name="forward">True if it's an open animation, False if its a Close Animation</param>
    /// <returns>The IEnumerator</returns>
    public IEnumerator ScaleFunc(bool forward)
    {
        if (!Scale.Enable)
        {
            yield break;
        }

        _ScaleState = VCAnimationState.AnimStarted;

        while (true)
        {
            if (forward)
            {
                onScaleOpenStart.Invoke();
            }
            else
            {
                onScaleCloseStart.Invoke();
            }

            float time = 0;
            bool bDelayed = false;

            float Duration = forward ? Scale.OpenAnimation.Duration : Scale.CloseAnimation.Duration;
            float Delay = forward ? Scale.OpenAnimation.Delay : Scale.CloseAnimation.Delay;

            if (!bDelayed && Delay > 0)
            {
                bDelayed = true;
                yield return StartCoroutine(WaitForRealSeconds(Delay));
            }

            Vector3 Start = forward ? Scale.OpenAnimation.Start : Scale.CloseAnimation.Start;
            Vector3 End = forward ? Scale.OpenAnimation.End : Scale.CloseAnimation.End;

            while (true)
            {
                time += GetDeltaTime();
                if (Start != Vector3.zero && End != Vector3.zero)
                {
                    transform.localScale = GetAnimationValue(ScaleFunctions, Scale, time, forward);
                    if (time < Duration)
                    {
                        yield return StartCoroutine(WaitForRealSeconds(.016f));
                    }
                    else
                    {
                        transform.localScale = GetAnimationValue(ScaleFunctions, Scale, Duration, forward);
                        break;
                    }
                }
                else
                {
                    break;
                }
            }

            if (forward)
            {
                onScaleOpenEnd.Invoke();
            }
            else
            {
                onScaleCloseEnd.Invoke();
            }

            if (forward)
            {
                if (Scale.Autoclose)
                {
                    forward = false;
                    yield return StartCoroutine(WaitForRealSeconds(Scale.AutocloseDelay));
                }
                else
                {
                    if (!Scale.Loop)
                    {
                        break;
                    }
                }
            }
            else
            {
                if (!Scale.Loop)
                {
                    break;
                }

                forward = true;
            }
        }

        _ScaleState = VCAnimationState.AnimFinished;
        OnAnimationFinished();
    }
Ejemplo n.º 5
0
    /// <summary>
    /// Rotation Enumerator Function
    /// </summary>
    /// <param name="forward">True if it's an open animation, False if its a Close Animation</param>
    /// <returns>The IEnumerator</returns>
    public IEnumerator RotationFunc(bool forward)
    {
        if (!Rotation.Enable)
        {
            yield break;
        }

        _RotationState = VCAnimationState.AnimStarted;

        while (true)
        {
            if (forward)
            {
                onRotationOpenStart.Invoke();
            }
            else
            {
                onRotationCloseStart.Invoke();
            }

            float time = 0;
            bool bDelayed = false;

            float Duration = forward ? Rotation.OpenAnimation.Duration : Rotation.CloseAnimation.Duration;
            float Delay = forward ? Rotation.OpenAnimation.Delay : Rotation.CloseAnimation.Delay;

            if (!bDelayed && Delay > 0)
            {
                bDelayed = true;
                yield return StartCoroutine(WaitForRealSeconds(Delay));
            }

            while (true)
            {
                time += GetDeltaTime();
                transform.eulerAngles = GetAnimationValue(RotationFunctions, Rotation, time, forward);
                if (time < Duration)
                {
                    yield return StartCoroutine(WaitForRealSeconds(.016f));
                }
                else
                {
                    transform.eulerAngles = GetAnimationValue(RotationFunctions, Rotation, Duration, forward);
                    break;
                }
            }

            if (forward)
            {
                onRotationOpenEnd.Invoke();
            }
            else
            {
                onRotationCloseEnd.Invoke();
            }

            if (forward)
            {
                if (Rotation.Autoclose)
                {
                    forward = false;
                    yield return StartCoroutine(WaitForRealSeconds(Rotation.AutocloseDelay));
                }
                else
                {
                    if (!Rotation.Loop)
                    {
                        break;
                    }
                }
            }
            else
            {
                if (!Rotation.Loop)
                {
                    break;
                }

                forward = true;
            }
        }

        _RotationState = VCAnimationState.AnimFinished;
        OnAnimationFinished();
    }
Ejemplo n.º 6
0
    ////////////////////////////////////////////////////
    /// <summary>
    /// Movement Enumerator Function
    /// </summary>
    /// <param name="forward">True if it's an open animation, False if its a Close Animation</param>
    /// <returns>The IEnumerator</returns>
    public IEnumerator MoveFunc(bool forward)
    {
        if (!Movement.Enable)
        {
            yield break;
        }

        _MovementState = VCAnimationState.AnimStarted;

        while (true)
        {
            if (forward)
            {
                onMovementOpenStart.Invoke();
            }
            else
            {
                onMovementCloseStart.Invoke();
            }

            float time = 0;
            bool bDelayed = false;

            float Duration = forward ? Movement.OpenAnimation.Duration : Movement.CloseAnimation.Duration;
            float Delay = forward ? Movement.OpenAnimation.Delay : Movement.CloseAnimation.Delay;

            if (!bDelayed && Delay > 0)
            {
                bDelayed = true;
                yield return StartCoroutine(WaitForRealSeconds(Delay));
            }

            RectTransform rectTransform = transform as RectTransform;

            while (true)
            {
                time += GetDeltaTime();

                if (rectTransform)
                {
                    rectTransform.anchoredPosition = GetAnimationValue(MovementFunctions, Movement, time, forward);
                }
                else
                {
                    transform.position = GetAnimationValue(MovementFunctions, Movement, time, forward);
                }

                if (time < Duration)
                {
                    yield return StartCoroutine(WaitForRealSeconds(.016f));
                }
                else
                {
                    if (rectTransform)
                    {
                        rectTransform.anchoredPosition = GetAnimationValue(MovementFunctions, Movement, Duration, forward);
                    }
                    else
                    {
                        transform.position = GetAnimationValue(MovementFunctions, Movement, Duration, forward);
                    }
                    break;
                }
            }

            if (forward)
            {
                onMovementOpenEnd.Invoke();
            }
            else
            {
                onMovementCloseEnd.Invoke();
            }

            if (forward)
            {
                if (Movement.Autoclose)
                {
                    forward = false;
                    yield return StartCoroutine(WaitForRealSeconds(Movement.AutocloseDelay));
                }
                else
                {
                    if (!Movement.Loop)
                    {
                        break;
                    }
                }
            }
            else
            {
                if (!Movement.Loop)
                {
                    break;
                }

                forward = true;
            }
        }

        _MovementState = VCAnimationState.AnimFinished;
        OnAnimationFinished();
    }