Example #1
0
    public void AnimateToPosition(GameObject uiObj, Vector2 targetPos, float time)
    {
        RectToAnimate newRect = new RectToAnimate();

        newRect.Rect        = uiObj.GetComponent <RectTransform>();
        newRect.Time        = time;
        newRect.Type        = AnimationType.AnimateTo;
        newRect.TargetPos   = targetPos;
        newRect.OriginalPos = newRect.Rect.offsetMax;
        newRect.AnimTimer   = 0;
        m_UiAnimationList.Add(newRect);
    }
Example #2
0
    public void AnimateFlyAway(GameObject uiObj, Vector3 direction, float speed, float time)
    {
        RectToAnimate newRect = new RectToAnimate();

        newRect.Rect      = uiObj.GetComponent <RectTransform>();
        newRect.Direction = direction;
        newRect.Speed     = speed * 100;
        newRect.Time      = time;
        newRect.Type      = AnimationType.FlyAway;
        newRect.AnimTimer = 0;
        newRect.Distance  = time * newRect.Speed;
        m_UiAnimationList.Add(newRect);
    }
Example #3
0
    //-----------------------------------------------------------------

    #region Animation Functions

    public void UpdateUIAnimations()
    {
        if (m_UiAnimationList.Count <= 0)
        {
            return;
        }
        for (int i = 0; i < m_UiAnimationList.Count; i++)
        {
            RectToAnimate r = m_UiAnimationList[i];
            switch (r.Type)
            {
            case AnimationType.FlyAway:
            {
                r.AnimTimer += Time.deltaTime;
                if (r.AnimTimer < r.Time)
                {
                    r.Rect.offsetMax = Vector2.SmoothDamp(r.Rect.offsetMax, new Vector2(r.Direction.x * r.Distance, r.Direction.y * r.Distance), ref r.SmoothVel, r.Time, 100, Time.deltaTime);
                    r.Rect.offsetMin = Vector2.SmoothDamp(r.Rect.offsetMin, new Vector2(r.Direction.x * r.Distance, r.Direction.y * r.Distance), ref r.SmoothVel, r.Time, 100, Time.deltaTime);
                }
                else
                {
                    m_UiAnimationList.RemoveAt(i);
                }
                break;
            }

            case AnimationType.AnimateTo:
            {
                r.AnimTimer += Time.deltaTime;
                if (r.AnimTimer <= r.Time * 2)
                {
                    r.Rect.offsetMax = Vector2.SmoothDamp(r.Rect.offsetMax, r.TargetPos, ref r.SmoothVel, r.Time * 0.5f, 100, Time.deltaTime);
                    r.Rect.offsetMin = Vector2.SmoothDamp(r.Rect.offsetMax, r.TargetPos, ref r.SmoothVel, r.Time * 0.5f, 100, Time.deltaTime);
                }
                else
                {
                    m_UiAnimationList.RemoveAt(i);
                }
                break;
            }

            case AnimationType.FlyInAndAway:
            {
                switch (r.AnimStateCounter)
                {
                case 0:             // Fly in
                    r.AnimTimer += Time.deltaTime;
                    if (r.AnimTimer <= r.Time)
                    {
                        r.Rect.offsetMax = Vector2.SmoothDamp(r.Rect.offsetMax, r.TargetPos, ref r.SmoothVel, r.Time * 0.25f, 100, Time.deltaTime);
                        r.Rect.offsetMin = Vector2.SmoothDamp(r.Rect.offsetMax, r.TargetPos, ref r.SmoothVel, r.Time * 0.25f, 100, Time.deltaTime);
                    }
                    else
                    {
                        r.AnimStateCounter++;
                        r.AnimTimer = 0;
                    }
                    break;

                case 1:             // Small Sway
                    r.AnimTimer += Time.deltaTime;
                    if (r.AnimTimer < r.Time * 0.2f)
                    {
                        r.Rect.offsetMax = Vector2.SmoothDamp(r.Rect.offsetMax, new Vector2(r.Direction.x * r.Distance, r.Direction.y * r.Distance), ref r.SmoothVel, r.Time, 100, Time.deltaTime);
                        r.Rect.offsetMin = Vector2.SmoothDamp(r.Rect.offsetMin, new Vector2(r.Direction.x * r.Distance, r.Direction.y * r.Distance), ref r.SmoothVel, r.Time, 100, Time.deltaTime);
                    }
                    else
                    {
                        r.AnimStateCounter++;
                        r.AnimTimer = 0;
                    }
                    break;

                case 2:             // Fly Away
                    r.AnimTimer += Time.deltaTime;
                    if (r.AnimTimer < r.Time)
                    {
                        r.Rect.offsetMax = Vector2.SmoothDamp(r.Rect.offsetMax, new Vector2(r.Direction.x * r.Distance, r.Direction.y * r.Distance), ref r.SmoothVel, r.Time * 0.5f, 100, Time.deltaTime);
                        r.Rect.offsetMin = Vector2.SmoothDamp(r.Rect.offsetMin, new Vector2(r.Direction.x * r.Distance, r.Direction.y * r.Distance), ref r.SmoothVel, r.Time * 0.5f, 100, Time.deltaTime);
                    }
                    else
                    {
                        m_UiAnimationList.RemoveAt(i);
                    }
                    break;
                }
                break;
            }
            }
        }
    }