/// <summary> /// Get scroll. /// </summary> /// <param name="type">Type.</param> /// <param name="position">Position.</param> /// <param name="value">Scroll value.</param> protected virtual Vector3 ScrollOnClick(ScrollButtonType type, Vector3 position, float value) { switch (type) { case ScrollButtonType.Top: position.y -= value; break; case ScrollButtonType.Bottom: position.y += value; break; case ScrollButtonType.Left: position.x += value; break; case ScrollButtonType.Right: position.x -= value; break; default: throw new NotSupportedException("Unknown ScrollButtonType: " + type); } return(position); }
/// <summary> /// Scroll on click. /// </summary> /// <param name="type">Type.</param> public void ScrollOnClick(ScrollButtonType type) { if (!Interactable) { return; } AnimationStop(); if ((AnimationStartTime + AnimationLength) < GetTime()) { 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(); } }
/// <summary> /// Animation on hold. /// </summary> /// <returns>Nothing.</returns> /// <param name="type">Type.</param> protected virtual IEnumerator AnimationHold(ScrollButtonType type) { do { var delta = UnscaledTime ? Time.unscaledDeltaTime : Time.deltaTime; var step = scrollRect.scrollSensitivity * ScrollSensitivityRateHold * delta; ScrollRect.content.localPosition = ScrollOnClick(type, ScrollRect.content.localPosition, step); ForceUpdateBounds(); yield return(null); }while (gameObject.activeSelf); }
/// <summary> /// Scroll on hold. /// </summary> /// <param name="type">Type.</param> public void ScrolOnHold(ScrollButtonType type) { if (!Interactable) { return; } AnimationStop(); AnimationStartTime = GetTime(); StartPosition = ScrollRect.content.localPosition; ScrollRect.StopMovement(); CurrentCoroutine = AnimationHold(type); StartCoroutine(CurrentCoroutine); }