Exemplo n.º 1
0
        internal static IEnumerator CoAnimateToast(RectTransform toast, float target, System.Action cb = null)
        {
            var parent = toast.parent as RectTransform;
            var group  = toast.GetComponent <CanvasGroup>();
            var scale  = toast.localScale;

            float start   = scale.y;
            float delta   = Mathf.Abs(target - start);
            float elapsed = 0;

            while (elapsed <= delta)
            {
                elapsed += Time.deltaTime / AnimationTime;
                float t = Mathf.Lerp(start, target, elapsed);

                scale.y     = t;
                group.alpha = t;

                toast.localScale = scale;
                toast.ForceUpdateRectTransforms();

                LayoutRebuilder.MarkLayoutForRebuild(toast);

                yield return(null);

                if (!group)
                {
                    break;
                }
            }

            if (start != target)
            {
                singleton.UpdateVisibility(parent, target == 1 ? 1 : 0);
            }

            if (cb != null)
            {
                cb.Invoke();
            }
        }