Ejemplo n.º 1
0
        public void Show()
        {
            Debug.Log("Ripple on " + name);

            if (rect == null) //Use rect to get the size.
            {
                rect = GetComponent <RectTransform>();
            }

            if (parent == null)
            {
                parent = transform;
            }

            //make the ripple
            GameObject g = (GameObject)Instantiate(Resources.Load("Ripple"), Input.mousePosition, Quaternion.identity, parent);

            rippleRect = g.GetComponent <RectTransform>();
            g.GetComponent <Image>().color = color;



            //Find the smallest size
            float size = (rect.sizeDelta.x < rect.sizeDelta.y) ? rect.sizeDelta.x : rect.sizeDelta.y;

            //Set the size
            rippleRect.sizeDelta = new Vector2(size, size) * 0.5f;

            //Aaaaaand animate
            if (animationFramework == null)
            {
                animationFramework = FindObjectOfType <UIAnimationFramework>();
            }

            if (moveToMiddle)
            {
                animationFramework.Move(rippleRect, rect.anchoredPosition, duration, 0);
            }

            animationFramework.Scale(rippleRect, Vector3.one * scaleFactor, duration);
            animationFramework.Fade(g.GetComponent <Image>(), Color.clear, duration * 0.75f, duration * 0.25f);

            Destroy(g, duration + 0.1f);
        }
Ejemplo n.º 2
0
        public void Invoke(UIAnimationFramework effects)
        {
            foreach (RectMoveAnimationSingle m in move)
            {
                effects.Move(m.rect, m.point, m.time);
            }

            foreach (RectScaleAnimationSingle s in scale)
            {
                effects.Scale(s.rect, s.point, s.time);
            }

            foreach (RectRotateAnimationSingle a in rotate)
            {
                effects.Rotate(a.rect, Quaternion.Euler(a.rotation), a.time, a.delay);
            }

            foreach (TextFadeAnimationSingle a in textFade)
            {
                effects.Fade(a.text, a.color, a.time, a.delay);
            }

            foreach (ImageFadeAnimationSingle a in imageFade)
            {
                effects.Fade(a.image, a.color, a.time, a.delay);
            }

            foreach (ImageFillAnimationSingle a in imageFill)
            {
                effects.Fill(a.image, a.value, a.time, a.delay);
            }

            foreach (CanvasGroupFadeAnimationSingle a in cg)
            {
                effects.Fade(a.cg, a.value, a.time, a.delay);
            }
        }
Ejemplo n.º 3
0
        private void Animate()
        {
            if (effect == null)
            {
                effect = GameObject.FindObjectOfType <UIAnimationFramework>();
            }

            OnStart.Invoke(new UIAnimation.UIAnimationEvent(name, isOpen, id));

            if ((moveAnimations.Count + scaleAnimations.Count + rotateAnimation.Count + textFadeAnimations.Count + imageFadeAnimations.Count + imageFillAnimations.Count + canvasGroupFadeAnimation.Count) == 0)
            {
                OnEnd.Invoke(new UIAnimation.UIAnimationEvent(name, isOpen, id));
                return;
            }

            bool first = true;

            foreach (UIAnimation.RectMoveAnimation move in moveAnimations)
            {
                Vector3 point     = (isOpen) ? move.open : move.close;
                float   animDelay = (isOpen) ? move.openDelay : move.closeDelay;

                if (first)
                {
                    //Only fire OnOver event one time.
                    effect.Move(move.rect, point, time, delay + animDelay, OnOver, curve);
                    first = false;
                }
                else
                {
                    effect.Move(move.rect, point, time, delay + animDelay, null, curve);
                }
            }

            foreach (UIAnimation.RectScaleAnimation scale in scaleAnimations)
            {
                Vector3 point     = (isOpen) ? scale.open : scale.close;
                float   animDelay = (isOpen) ? scale.openDelay : scale.closeDelay;

                if (first)
                {
                    //Only fire OnOver event one time.
                    effect.Scale(scale.rect, point, time, delay + animDelay, OnOver, curve);
                    first = false;
                }
                else
                {
                    effect.Scale(scale.rect, point, time, delay + animDelay, null, curve);
                }
            }

            foreach (UIAnimation.RectRotateAnimation rotate in rotateAnimation)
            {
                Vector3 point     = (isOpen) ? rotate.open : rotate.close;
                float   animDelay = (isOpen) ? rotate.openDelay : rotate.closeDelay;

                if (first)
                {
                    //Only fire OnOver event one time.
                    effect.Rotate(rotate.rect, Quaternion.Euler(point), time, delay + animDelay, OnOver, curve);
                    first = false;
                }
                else
                {
                    effect.Rotate(rotate.rect, Quaternion.Euler(point), time, delay + animDelay, null, curve);
                }
            }

            foreach (UIAnimation.TextFadeAnimation fade in textFadeAnimations)
            {
                Color color     = (isOpen) ? fade.open : fade.close;
                float animDelay = (isOpen) ? fade.openDelay : fade.closeDelay;

                if (first)
                {
                    //Only fire OnOver event one time.
                    effect.Fade(fade.text, color, time, delay + animDelay, OnOver, curve);
                    first = false;
                }
                else
                {
                    effect.Fade(fade.text, color, time, delay + animDelay, null, curve);
                }
            }

            foreach (UIAnimation.ImageFadeAnimation image in imageFadeAnimations)
            {
                Color color     = (isOpen) ? image.open : image.close;
                float animDelay = (isOpen) ? image.openDelay : image.closeDelay;

                if (first)
                {
                    //Only fire OnOver event one time.
                    effect.Fade(image.image, color, time, delay + animDelay, OnOver, curve);
                    first = false;
                }
                else
                {
                    effect.Fade(image.image, color, time, delay + animDelay, null, curve);
                }
            }

            foreach (UIAnimation.ImageFillAnimation img in imageFillAnimations)
            {
                float value     = (isOpen) ? img.open : img.close;
                float animDelay = (isOpen) ? img.openDelay : img.closeDelay;

                if (first)
                {
                    //Only fire OnOver event one time.
                    effect.Fill(img.image, value, time, delay + animDelay, OnOver, curve);
                    first = false;
                }
                else
                {
                    effect.Fill(img.image, value, time, delay + animDelay, null, curve);
                }
            }

            foreach (UIAnimation.CanvasGroupFadeAnimation cg in canvasGroupFadeAnimation)
            {
                float visible   = (isOpen) ? cg.open : cg.close;
                float animDelay = (isOpen) ? cg.openDelay : cg.closeDelay;

                if (first)
                {
                    //Only fire OnOver event one time.
                    effect.Fade(cg.cg, visible, time, delay + animDelay, OnOver, curve);
                    first = false;
                }
                else
                {
                    effect.Fade(cg.cg, visible, time, delay + animDelay, null, curve);
                }
            }
        }
Ejemplo n.º 4
0
        public void Init(string text, int textSize, TextAlignmentOptions alignment = TextAlignmentOptions.MidlineJustified)
        {
            if (animations == null)
            {
                animations = FindObjectOfType <UIAnimationFramework>();
            }

            if (animations == null)
            {
                Debug.LogError("Couldn't find UI Animations");
            }

            textComponent = new GameObject("text").AddComponent <TextMeshProUGUI>();
            start         = new GameObject("Start").AddComponent <Image>();
            fill          = new GameObject("Fill").AddComponent <Image>();

            textComponent.color = Color.clear;
            start.color         = Color.clear;
            fill.color          = Color.clear;

            //Load start sprite
            Sprite toolTipStart = Resources.Load <Sprite>("tooltip_start");

            if (toolTipStart == null)
            {
                Debug.LogError("Couldn't find tool tip start sprite!");
            }

            startRect = start.GetComponent <RectTransform>();
            fillRect  = fill.GetComponent <RectTransform>();
            textRect  = textComponent.GetComponent <RectTransform>();



            start.transform.SetParent(transform);
            fill.transform.SetParent(transform);
            textComponent.transform.SetParent(fill.transform);

            //set everything to 0.
            startRect.anchoredPosition = Vector3.zero;

            start.sprite = toolTipStart; //assign the start sprite

            //Fix sizing with the
            textComponent.text     = text;
            textComponent.fontSize = textSize;


            float width  = textComponent.preferredWidth * 1.1f;
            float height = textComponent.preferredHeight * 1.1f;

            startRect.sizeDelta       = new Vector2(height, height); //set height and width. (height in both vars, because the ratio is 1/1.)
            fillRect.sizeDelta        = new Vector2(width, height);
            fillRect.anchoredPosition = new Vector2((height - width + (textComponent.preferredWidth * 0.1f)) * 0.9f, 0);


            textComponent.alignment = alignment; //assign the text aligment
            textComponent.GetComponent <RectTransform>().anchorMin = new Vector2(0, 0);
            textComponent.GetComponent <RectTransform>().anchorMax = new Vector2(1, 1);
            textRect.offsetMin = textRect.offsetMax = Vector2.zero;



            //Animations!
            animations.Fade(start, Color.white, FADETIME);
            animations.Fade(fill, Color.white, FADETIME);
            animations.Scale(startRect, Vector3.one, SCALETIME);
            animations.Scale(fillRect, Vector3.one, SCALETIME);
            animations.Fade(textComponent, Color.black, FADETIME);
            animations.Scale(textRect, Vector3.one, SCALETIME);
        }