예제 #1
0
        /// <summary>
        /// Runs the animation.
        /// </summary>
        /// <returns>The animation.</returns>
        /// <param name="isHorizontal">If set to <c>true</c> is horizontal.</param>
        /// <param name="startPosition">Start position.</param>
        /// <param name="endPosition">End position.</param>
        /// <param name="unscaledTime">If set to <c>true</c> use unscaled time.</param>
        protected virtual IEnumerator RunAnimation(bool isHorizontal, float startPosition, float endPosition, bool unscaledTime)
        {
            float delta;

            var animation_length = Movement.keys[Movement.keys.Length - 1].time;
            var start_time       = Utilites.GetTime(unscaledTime);

            do
            {
                delta = Utilites.GetTime(unscaledTime) - start_time;
                var value = Movement.Evaluate(delta);

                var position = startPosition + ((endPosition - startPosition) * value);

                SetPosition(position, isHorizontal);

                yield return(null);
            }while (delta < animation_length);

            SetPosition(endPosition, isHorizontal);

            ScrollRectRestore();

            isAnimationRunning = false;
            currentAnimation   = null;
        }
예제 #2
0
        /// <summary>
        /// Base collapse animation.
        /// </summary>
        /// <param name="notify">Notify.</param>
        /// <param name="isHorizontal">Is horizontal?</param>
        /// <param name="speed">Animation speed in points per second.</param>
        /// <returns>Returns animations.</returns>
        public static IEnumerator AnimationCollapseBase(Notify notify, bool isHorizontal, float speed)
        {
            var rect      = notify.transform as RectTransform;
            var layout    = notify.GetComponentInParent <EasyLayout>();
            var axis      = isHorizontal ? RectTransform.Axis.Horizontal : RectTransform.Axis.Vertical;
            var base_size = isHorizontal ? rect.rect.width : rect.rect.height;

            var time     = base_size / speed;
            var end_time = Utilites.GetTime(notify.unscaledTime) + time;

            while (Utilites.GetTime(notify.unscaledTime) <= end_time)
            {
                var t    = 1f - ((end_time - Utilites.GetTime(notify.unscaledTime)) / time);
                var size = Mathf.Lerp(base_size, 0f, t);
                rect.SetSizeWithCurrentAnchors(axis, size);
                if (layout != null)
                {
                    layout.NeedUpdateLayout();
                }

                yield return(null);
            }

            // return height back for future use
            rect.SetSizeWithCurrentAnchors(axis, base_size);
        }
예제 #3
0
        /// <summary>
        /// Collapse animation.
        /// </summary>
        /// <param name="notify">Notify.</param>
        /// <returns>Returns animations.</returns>
        public static IEnumerator AnimationCollapse(Notify notify)
        {
            var rect       = notify.transform as RectTransform;
            var layout     = notify.GetComponentInParent <EasyLayout>();
            var max_height = rect.rect.height;

            var speed    = 200f;
            var time     = max_height / speed;
            var end_time = Utilites.GetTime(notify.unscaledTime) + time;

            while (Utilites.GetTime(notify.unscaledTime) <= end_time)
            {
                var t      = 1 - ((end_time - Utilites.GetTime(notify.unscaledTime)) / time);
                var height = Mathf.Lerp(max_height, 0, t);
                rect.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, height);
                if (layout != null)
                {
                    layout.UpdateLayout();
                }

                yield return(null);
            }

            // return height back for future use
            rect.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, max_height);
        }
        IEnumerator AnimationConstantTime(int targetValue)
        {
            if (targetValue > Max)
            {
                targetValue = Max;
            }

            var start = Value;
            var delta = targetValue - start;

            if (delta != 0)
            {
                var total_time = Speed;

                var start_time = Utilites.GetTime(UnscaledTime);
                var end_time   = start_time + total_time;

                do
                {
                    var progress = Mathf.Min(1, (Utilites.GetTime(UnscaledTime) - start_time) / total_time);

                    progressValue = start + Mathf.RoundToInt(progress * delta);

                    UpdateProgressbar();

                    yield return(null);
                }while (end_time > Utilites.GetTime(UnscaledTime));

                progressValue = targetValue;
                UpdateProgressbar();
            }

            IsAnimationRunning = false;
        }
예제 #5
0
        /// <summary>
        /// Scroll on click.
        /// </summary>
        /// <param name="type">Type.</param>
        public void ScrollOnClick(ScrollButtonType type)
        {
            if (!Interactable)
            {
                return;
            }

            AnimationStop();

            if ((AnimationStartTime + AnimationLength) < Utilites.GetTime(UnscaledTime))
            {
                return;
            }

            ScrollRect.StopMovement();
            var start = ScrollRect.content.localPosition;
            var end   = ScrollOnClick(type, start, ScrollRect.scrollSensitivity * ScrollSensitivityRateOnClick);

            if (Animate)
            {
                CurrentCoroutine = AnimationClick(start, end);
                StartCoroutine(CurrentCoroutine);
            }
            else
            {
                ScrollRect.content.localPosition = end;
                ForceUpdateBounds();
            }
        }
예제 #6
0
        /// <summary>
        /// Handle scroll changes.
        /// </summary>
        protected virtual void ScrollChanged()
        {
            if (!gameObject.activeInHierarchy)
            {
                return;
            }

            var distance = Mathf.Abs(IsHorizontal() ? DragDelta.x : DragDelta.y);
            var time     = Utilites.GetTime(UnscaledTime) - DragStarted;

            var is_fast = (distance >= FastDragDistance) && (time <= FastDragTime);

            if (!is_fast)
            {
                var pos  = IsHorizontal() ? -ScrollRect.content.anchoredPosition.x : ScrollRect.content.anchoredPosition.y;
                var page = Mathf.RoundToInt(pos / GetPageSize());
                GoToPage(page, true);

                DragDelta   = Vector2.zero;
                DragStarted = 0f;
            }
            else
            {
                var direction = IsHorizontal() ? DragDelta.x : -DragDelta.y;
                DragDelta = Vector2.zero;
                if (direction == 0f)
                {
                    return;
                }

                var page = direction < 0 ? CurrentPage + 1 : CurrentPage - 1;
                GoToPage(page, false);
            }
        }
예제 #7
0
        /// <summary>
        /// Base slide animation.
        /// </summary>
        /// <param name="notify">Notify.</param>
        /// <param name="isHorizontal">Is horizontal slide?</param>
        /// <param name="direction">Slide direction.</param>
        /// <param name="speed">Speed.</param>
        /// <param name="animateOthers">Animate other notifications.</param>
        /// <returns>Animation.</returns>
        public static IEnumerator AnimationSlideBase(Notify notify, bool isHorizontal, float direction, float speed, bool animateOthers = true)
        {
            var replacement = GetReplacement(notify);

            var layout_element = Utilites.GetOrAddComponent <LayoutElement>(notify);

            layout_element.ignoreLayout = true;

            var layout    = notify.GetComponentInParent <EasyLayout>();
            var rect      = notify.transform as RectTransform;
            var base_size = isHorizontal ? rect.rect.width : rect.rect.height;
            var base_pos  = rect.anchoredPosition;

            var time     = base_size / speed;
            var end_time = Utilites.GetTime(notify.unscaledTime) + time;
            var axis     = isHorizontal ? RectTransform.Axis.Horizontal : RectTransform.Axis.Vertical;

            while (Utilites.GetTime(notify.unscaledTime) <= end_time)
            {
                if (!animateOthers)
                {
                    base_pos = replacement.anchoredPosition;
                }

                var t    = 1 - ((end_time - Utilites.GetTime(notify.unscaledTime)) / time);
                var size = Mathf.Lerp(0, base_size, t);
                rect.anchoredPosition = isHorizontal
                                        ? new Vector2(base_pos.x + (size * direction), base_pos.y)
                                        : new Vector2(base_pos.x, base_pos.y + (size * direction));

                if (animateOthers)
                {
                    replacement.SetSizeWithCurrentAnchors(axis, base_size - size);
                    if (layout != null)
                    {
                        layout.NeedUpdateLayout();
                    }
                }

                yield return(null);
            }

            layout_element.ignoreLayout = false;

            Replacements.Push(replacement);
            replacement.gameObject.SetActive(false);
            replacement.SetSizeWithCurrentAnchors(axis, base_size);

            if (layout != null)
            {
                layout.NeedUpdateLayout();
            }
        }
예제 #8
0
        /// <summary>
        /// Scroll on hold.
        /// </summary>
        /// <param name="type">Type.</param>
        public void ScrolOnHold(ScrollButtonType type)
        {
            if (!Interactable)
            {
                return;
            }

            AnimationStop();

            AnimationStartTime = Utilites.GetTime(UnscaledTime);
            StartPosition      = ScrollRect.content.localPosition;

            ScrollRect.StopMovement();

            CurrentCoroutine = AnimationHold(type);
            StartCoroutine(CurrentCoroutine);
        }
예제 #9
0
        /// <summary>
        /// Open animation.
        /// </summary>
        /// <returns>Animation.</returns>
        /// <param name="rectTransform">RectTransform.</param>
        /// <param name="time">Time.</param>
        /// <param name="isHorizontal">Is Horizontal animated width changes; otherwise height.</param>
        /// <param name="unscaledTime">Use unscaled time.</param>
        /// <param name="actionAfter">Action to run after animation.</param>
        public static IEnumerator OpenFlexible(RectTransform rectTransform, float time = 0.5f, bool isHorizontal = false, bool unscaledTime = false, Action actionAfter = null)
        {
            var layoutElement = Utilites.GetOrAddComponent <LayoutElement>(rectTransform);

            if (isHorizontal)
            {
                layoutElement.preferredWidth = -1f;
            }
            else
            {
                layoutElement.preferredHeight = -1f;
            }

            var end_time = Utilites.GetTime(unscaledTime) + time;

            while (Utilites.GetTime(unscaledTime) <= end_time)
            {
                var t    = 1 - ((end_time - Utilites.GetTime(unscaledTime)) / time);
                var size = Mathf.Lerp(0f, 1f, t);
                if (isHorizontal)
                {
                    layoutElement.flexibleWidth = size;
                }
                else
                {
                    layoutElement.flexibleHeight = size;
                }

                yield return(null);
            }

            // return size back for future use
            if (isHorizontal)
            {
                layoutElement.flexibleWidth = 1f;
            }
            else
            {
                layoutElement.flexibleHeight = 1f;
            }

            if (actionAfter != null)
            {
                actionAfter();
            }
        }
예제 #10
0
        /// <summary>
        /// Animation on click.
        /// </summary>
        /// <returns>Nothing.</returns>
        /// <param name="start">Start scroll position.</param>
        /// <param name="end">End scroll position.</param>
        protected virtual IEnumerator AnimationClick(Vector3 start, Vector3 end)
        {
            var animation_position = 0f;

            do
            {
                animation_position = Utilites.GetTime(UnscaledTime) - AnimationStartTime;
                var pos = Vector3.Lerp(start, end, Curve.Evaluate(animation_position));

                ScrollRect.content.localPosition = pos;
                ForceUpdateBounds();

                yield return(null);
            }while (animation_position < AnimationLength);

            ScrollRect.content.localPosition = end;
            ForceUpdateBounds();
        }
예제 #11
0
        IEnumerator IndeterminateAnimation()
        {
            while (true)
            {
                var r = Bar.uvRect;
                if (Direction == ProgressbarDirection.Horizontal)
                {
                    r.x = (Utilites.GetTime(UnscaledTime) * (-Speed)) % 1;
                }
                else
                {
                    r.y = (Utilites.GetTime(UnscaledTime) * (-Speed)) % 1;
                }

                Bar.uvRect = r;
                yield return(null);
            }
        }
예제 #12
0
        /// <summary>
        /// Happens when ScrollRect OnDragStart event occurs.
        /// </summary>
        /// <param name="eventData">Event data.</param>
        protected virtual void OnScrollRectDragStart(PointerEventData eventData)
        {
            if (!IsValidDrag(eventData))
            {
                return;
            }

            DragDelta = Vector2.zero;

            isDragging = true;

            CursorStartPosition = Vector2.zero;
            RectTransformUtility.ScreenPointToLocalPointInRectangle(ScrollRect.transform as RectTransform, eventData.position, eventData.pressEventCamera, out CursorStartPosition);

            DragStarted = Utilites.GetTime(UnscaledTime);

            StopAnimation();
        }
예제 #13
0
        /// <summary>
        /// Collapse animation.
        /// </summary>
        /// <returns>Animation.</returns>
        /// <param name="rectTransform">RectTransform.</param>
        /// <param name="time">Time.</param>
        /// <param name="isHorizontal">Is Horizontal animated width changes; otherwise height.</param>
        /// <param name="unscaledTime">Use unscaled time.</param>
        /// <param name="actionAfter">Action to run after animation.</param>
        public static IEnumerator Collapse(RectTransform rectTransform, float time = 0.5f, bool isHorizontal = false, bool unscaledTime = false, Action actionAfter = null)
        {
            var layoutElement = Utilites.GetOrAddComponent <LayoutElement>(rectTransform);
            var size          = isHorizontal
                                ? (LayoutUtilites.IsWidthControlled(rectTransform) ? LayoutUtility.GetPreferredWidth(rectTransform) : rectTransform.rect.width)
                                : (LayoutUtilites.IsHeightControlled(rectTransform) ? LayoutUtility.GetPreferredHeight(rectTransform) : rectTransform.rect.height);

            var end_time = Utilites.GetTime(unscaledTime) + time;

            while (Utilites.GetTime(unscaledTime) <= end_time)
            {
                var t        = 1 - ((end_time - Utilites.GetTime(unscaledTime)) / time);
                var new_size = Mathf.Lerp(size, 0, t);
                if (isHorizontal)
                {
                    rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, new_size);
                    layoutElement.preferredWidth = new_size;
                }
                else
                {
                    rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, new_size);
                    layoutElement.preferredHeight = new_size;
                }

                yield return(null);
            }

            // return size back for future use
            if (isHorizontal)
            {
                rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, size);
                layoutElement.preferredWidth = size;
            }
            else
            {
                rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, size);
                layoutElement.preferredHeight = size;
            }

            if (actionAfter != null)
            {
                actionAfter();
            }
        }
예제 #14
0
        /// <summary>
        /// Rotate animation.
        /// </summary>
        /// <param name="notify">Notify.</param>
        /// <returns>Returns animations.</returns>
        public static IEnumerator AnimationRotate(Notify notify)
        {
            var rect           = notify.transform as RectTransform;
            var start_rotarion = rect.localRotation.eulerAngles;
            var length         = 0.5f;

            var end_time = Utilites.GetTime(notify.unscaledTime) + length;

            while (Utilites.GetTime(notify.unscaledTime) <= end_time)
            {
                var t          = 1 - ((end_time - Utilites.GetTime(notify.unscaledTime)) / length);
                var rotation_x = Mathf.Lerp(0, 90, t);

                rect.localRotation = Quaternion.Euler(rotation_x, start_rotarion.y, start_rotarion.z);
                yield return(null);
            }

            // return rotation back for future use
            rect.localRotation = Quaternion.Euler(start_rotarion);
        }
예제 #15
0
        /// <summary>
        /// Animates the switch.
        /// </summary>
        /// <returns>The switch.</returns>
        /// <param name="state">IsOn.</param>
        /// <param name="time">Time.</param>
        protected virtual IEnumerator AnimateSwitch(bool state, float time)
        {
            SetMarkPosition(GetPosition(!IsOn));

            var prev_position = GetPosition(!IsOn);
            var next_position = GetPosition(IsOn);
            var end_time      = Utilites.GetTime(UnscaledTime) + time;

            while (Utilites.GetTime(UnscaledTime) <= end_time)
            {
                var distance = 1 - ((end_time - Utilites.GetTime(UnscaledTime)) / time);
                var pos      = Mathf.Lerp(prev_position, next_position, distance);

                SetMarkPosition(pos);

                yield return(null);
            }

            SetMarkPosition(GetPosition(IsOn));
        }
예제 #16
0
        /// <summary>
        /// Collapse animation.
        /// </summary>
        /// <returns>Animation coroutine.</returns>
        protected virtual IEnumerator AnimationCollapse()
        {
            var max_height = rect.rect.height;
            var speed      = 200f;        // pixels per second

            var time     = max_height / speed;
            var end_time = Utilites.GetTime(UnscaledTime) + time;

            while (Utilites.GetTime(UnscaledTime) <= end_time)
            {
                var t      = 1 - ((end_time - Utilites.GetTime(UnscaledTime)) / time);
                var height = Mathf.Lerp(max_height, 0, t);

                rect.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, height);
                yield return(null);
            }

            // return height back for future use
            rect.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, max_height);
        }
예제 #17
0
        /// <summary>
        /// Base rotate animation.
        /// </summary>
        /// <param name="notify">Notify.</param>
        /// <param name="isHorizontal">Is horizontal></param>
        /// <param name="timeLength">Animation length in seconds.</param>
        /// <returns>Returns animations.</returns>
        public static IEnumerator AnimationRotateBase(Notify notify, bool isHorizontal, float timeLength)
        {
            var rect          = notify.transform as RectTransform;
            var base_rotation = rect.localRotation.eulerAngles;

            var end_time = Utilites.GetTime(notify.unscaledTime) + timeLength;

            while (Utilites.GetTime(notify.unscaledTime) <= end_time)
            {
                var t        = 1f - ((end_time - Utilites.GetTime(notify.unscaledTime)) / timeLength);
                var rotation = Mathf.Lerp(0f, 90f, t);

                rect.localRotation = isHorizontal
                                        ? Quaternion.Euler(base_rotation.x, rotation, base_rotation.z)
                                        : Quaternion.Euler(rotation, base_rotation.y, base_rotation.z);
                yield return(null);
            }

            // return rotation back for future use
            rect.localRotation = Quaternion.Euler(base_rotation);
        }
예제 #18
0
        /// <summary>
        /// Rotate animation.
        /// </summary>
        /// <returns>Animation.</returns>
        /// <param name="rectTransform">RectTransform.</param>
        /// <param name="time">Time.</param>
        /// <param name="startAngle">Start rotation angle.</param>
        /// <param name="endAngle">End rotation angle.</param>
        /// <param name="unscaledTime">Use unscaled time.</param>
        /// <param name="actionAfter">Action to run after animation.</param>
        public static IEnumerator RotateZ(RectTransform rectTransform, float time = 0.5f, float startAngle = 0, float endAngle = 90, bool unscaledTime = false, Action actionAfter = null)
        {
            var start_rotarion = rectTransform.localRotation.eulerAngles;
            var end_time       = Utilites.GetTime(unscaledTime) + time;

            while (Utilites.GetTime(unscaledTime) <= end_time)
            {
                var t          = 1 - ((end_time - Utilites.GetTime(unscaledTime)) / time);
                var rotation_z = Mathf.Lerp(startAngle, endAngle, t);

                rectTransform.localRotation = Quaternion.Euler(start_rotarion.x, start_rotarion.y, rotation_z);
                yield return(null);
            }

            // return rotation back for future use
            rectTransform.localRotation = Quaternion.Euler(start_rotarion);

            if (actionAfter != null)
            {
                actionAfter();
            }
        }
예제 #19
0
        /// <summary>
        /// Animation coroutine.
        /// </summary>
        /// <returns>Coroutine.</returns>
        protected IEnumerator AnimationCoroutine()
        {
            var start_pos = DragRect.localPosition;
            var end_pos   = RestrictPosition(DragRect.localPosition);

            if (start_pos != end_pos)
            {
                var animation_length   = Draggable.Curve.keys[Draggable.Curve.keys.Length - 1].time;
                var startTime          = Utilites.GetTime(Draggable.UnscaledTime);
                var animation_position = 0f;

                do
                {
                    animation_position = Utilites.GetTime(Draggable.UnscaledTime) - startTime;
                    var value = Draggable.Curve.Evaluate(animation_position);
                    DragRect.localPosition = Vector3.Lerp(start_pos, end_pos, value);

                    yield return(null);
                }while (animation_position < animation_length);

                DragRect.localPosition = end_pos;
            }
        }
예제 #20
0
        /// <summary>
        /// Runs the animation.
        /// </summary>
        /// <returns>The animation.</returns>
        /// <param name="isHorizontal">If set to <c>true</c> is horizontal.</param>
        /// <param name="startPosition">Start position.</param>
        /// <param name="endPosition">End position.</param>
        /// <param name="unscaledTime">If set to <c>true</c> use unscaled time.</param>
        protected virtual IEnumerator RunAnimation(bool isHorizontal, float startPosition, float endPosition, bool unscaledTime)
        {
            float delta;

            var animation_length = Movement.keys[Movement.keys.Length - 1].time;
            var start_time       = Utilites.GetTime(unscaledTime);

            do
            {
                delta = Utilites.GetTime(unscaledTime) - start_time;
                var value = Movement.Evaluate(delta);

                var position = startPosition + ((endPosition - startPosition) * value);
                if (isHorizontal)
                {
                    RectTransform.anchoredPosition = new Vector2(position, RectTransform.anchoredPosition.y);
                }
                else
                {
                    RectTransform.anchoredPosition = new Vector2(RectTransform.anchoredPosition.x, position);
                }

                yield return(null);
            }while (delta < animation_length);

            if (isHorizontal)
            {
                RectTransform.anchoredPosition = new Vector2(endPosition, RectTransform.anchoredPosition.y);
            }
            else
            {
                RectTransform.anchoredPosition = new Vector2(RectTransform.anchoredPosition.x, endPosition);
            }

            IsAnimationRunning = false;
        }
예제 #21
0
 protected float GetTime()
 {
     return(Utilites.GetTime(UnscaledTime));
 }
예제 #22
0
 protected float GetTime()
 {
     return(Utilites.GetTime(Draggable.UnscaledTime));
 }