Beispiel #1
0
    // Use this for initialization
    void Start()
    {
        if (Application.isPlaying && uiAnimation != null)
        {
            return;
        }

        rect = GetComponent <RectTransform>();
        if (rect == null)
        {
            Debug.Log("Please add a RectTransform to this object:" + gameObject.name);
            return;
        }

        List <UIAnimation> animations = new List <UIAnimation>();

        if (moveAnimation)
        {
            UpdateBehaviour     mod = EasyUIAnimatorUtils.GetModifier(moveModifier);
            Effect.EffectUpdate eff = EasyUIAnimatorUtils.GetEffect(moveEffect, max[0], bounce[0]);
            effectRotation = (randomDirection) ? Vector3.forward * Random.Range(0, 360) : effectRotation;
            Vector2 startValue = (useScreenValues) ? Vector3.Scale(start[0], (Vector3)UIAnimator.InvertedScreenDimension) : start[0];
            Vector2 finalValue = (useScreenValues) ? Vector3.Scale(final[0], (Vector3)UIAnimator.InvertedScreenDimension) : final[0];
            if (isBezier)
            {
                if (isCubicBezier)
                {
                    animations.Add(UIAnimator.MoveBezier(rect, startValue, finalValue, bezierP1, bezierP2, duration).SetModifier(mod));
                }
                else
                {
                    animations.Add(UIAnimator.MoveBezier(rect, startValue, finalValue, bezierP1, duration).SetModifier(mod));
                }
            }
            else
            {
                animations.Add(UIAnimator.Move(rect, startValue, finalValue, duration).SetModifier(mod).SetEffect(eff, Quaternion.Euler(effectRotation)));
            }
        }
        if (scaleAnimation)
        {
            UpdateBehaviour     mod = EasyUIAnimatorUtils.GetModifier(scaleModifier);
            Effect.EffectUpdate eff = EasyUIAnimatorUtils.GetEffect(scaleEffect, max[1], bounce[1]);
            animations.Add(UIAnimator.Scale(rect, start[1], final[1], duration).SetModifier(mod).SetEffect(eff));
        }
        if (rotationAnimation)
        {
            UpdateBehaviour     mod = EasyUIAnimatorUtils.GetModifier(rotationModifier);
            Effect.EffectUpdate eff = EasyUIAnimatorUtils.GetEffect(rotationEffect, max[2], bounce[2]);
            if (start[2].x != 0 || start[2].y != 0 || final[2].x != 0 || final[2].y != 0)
            {
                animations.Add(UIAnimator.Rotate(rect, Quaternion.Euler(start[2]), Quaternion.Euler(final[2]), duration).SetModifier(mod).SetEffect(eff));
            }
            else
            {
                animations.Add(UIAnimator.Rotate(rect, start[2].z, final[2].z, duration).SetModifier(mod).SetEffect(eff));
            }
        }
        if (graphicAnimation)
        {
            UpdateBehaviour mod = EasyUIAnimatorUtils.GetModifier(graphicModifier);
            image = GetComponent <Graphic>();
            if (!image)
            {
                Debug.LogError("Please attach an Image/Text component to the gameObject");
            }
            else
            {
                animations.Add(UIAnimator.ChangeColor(image, startColor, finalColor, duration).SetDelay(delay).SetModifier(mod));
            }
        }

        if (animations.Count == 0)
        {
            Debug.Log("No animation");
            return;
        }
        else
        {
            uiAnimation = new UIGroupAnimation(animations.ToArray()).SetDelay(delay);
        }

        switch (loop)
        {
        case Loop.LOOP:
            uiAnimation.SetLoop();
            break;

        case Loop.PING_PONG:
            uiAnimation.SetLoop(true);
            break;
        }

        if (playAudioOnPlay)
        {
            audioSource = GetComponent <AudioSource>();
            if (audioSource == null)
            {
                Debug.LogError("No audio source found!");
            }
        }

        if (disableAfter)
        {
            uiAnimation.SetCallback(() => { gameObject.SetActive(false); });
        }
        if (Application.isPlaying)
        {
            if (playOnStart)
            {
                Play();
            }
        }
    }
    void Start()
    {
        if (Application.isPlaying && uiAnimation != null)
        {
            return;
        }

        rect = GetComponent <RectTransform>();
        UpdateBehaviour mMod = EasyUIAnimatorUtils.GetModifier(mod);

        Effect.EffectUpdate mEff = EasyUIAnimatorUtils.GetEffect(effect, max, bounce);
        effectRotation = (randomDirection) ? Vector3.forward * Random.Range(0, 360) : effectRotation;
        switch (animType)
        {
        case AnimationType.MOVE:
            if (useScreenValues)
            {
                uiAnimation = UIAnimator.Move(rect, Vector3.Scale(startV3, (Vector3)UIAnimator.InvertedScreenDimension), Vector3.Scale(finalV3, (Vector3)UIAnimator.InvertedScreenDimension), duration).SetDelay(delay).SetModifier(mMod).SetEffect(mEff, Quaternion.Euler(effectRotation));
            }
            else
            {
                uiAnimation = UIAnimator.Move(rect, startV3, finalV3, duration).SetDelay(delay).SetModifier(mMod).SetEffect(mEff, Quaternion.Euler(effectRotation));
            }
            break;

        case AnimationType.SCALE:
            uiAnimation = UIAnimator.Scale(rect, startV3, finalV3, duration).SetDelay(delay).SetModifier(mMod).SetEffect(mEff, Quaternion.Euler(effectRotation));
            break;

        case AnimationType.ROTATION:
            if (startV3.x != 0 || startV3.y != 0 || finalV3.x != 0 || finalV3.y != 0)
            {
                uiAnimation = UIAnimator.Rotate(rect, Quaternion.Euler(startV3), Quaternion.Euler(finalV3), duration).SetDelay(delay).SetModifier(mMod).SetEffect(mEff, Quaternion.Euler(effectRotation));
            }
            else
            {
                uiAnimation = UIAnimator.Rotate(rect, startV3.z, finalV3.z, duration).SetDelay(delay).SetModifier(mMod).SetEffect(mEff, Quaternion.Euler(effectRotation));
            }
            break;

        case AnimationType.IMAGE:
            image = GetComponent <Graphic>();
            if (!image)
            {
                Debug.LogError("Please attach an Image component to the gameObject");
                uiAnimation = null;
                return;
            }
            uiAnimation = UIAnimator.ChangeColor(image, startColor, finalColor, duration).SetDelay(delay).SetModifier(mMod);
            break;

        case AnimationType.GROUP:
            UIAnimation[] uiAnimations = new UIAnimation[fixedAnimations.Length];
            for (int i = 0; i < uiAnimations.Length; i++)
            {
                uiAnimations[i] = fixedAnimations[i].uiAnimation;
            }
            uiAnimation = new UIGroupAnimation(uiAnimations);
            break;

        default:
            break;
        }
        switch (loop)
        {
        case Loop.LOOP:
            uiAnimation.SetLoop();
            break;

        case Loop.PING_PONG:
            uiAnimation.SetLoop(true);
            break;
        }

        if (disableAfter)
        {
            uiAnimation.SetCallback(() => { gameObject.SetActive(false); });
        }
        if (Application.isPlaying)
        {
            if (playOnStart)
            {
                Play();
            }
        }
    }