123456789101112131415161718192021222324252627282930313233343536373839 |
- using UnityEngine;
- using System.Collections;
- /// <summary>
- /// This component should be placed on a UIScrollbar and is responsible for scrolling it to the top.
- /// This is useful for dynamic content inside a scrollable panel
- /// </summary>
- public class ScrollToTop : MonoBehaviour
- {
- UIScrollBar scrollBar;
- void Awake()
- {
- scrollBar = GetComponent<UIScrollBar>();
- }
- void OnEnable()
- {
- StartCoroutine(ResetScrollCoroutine());
- }
- IEnumerator ResetScrollCoroutine()
- {
- yield return new WaitForSeconds(0.5f); //wait for transition
- iTween.ValueTo(gameObject, iTween.Hash(
- "from", scrollBar.scrollValue,
- "to", 0,
- "time", 0.5f,
- "easetype", iTween.EaseType.easeOutCubic,
- "onupdate", "UpdateScrollValue",
- "onupdatetarget", gameObject));
- }
- void UpdateScrollValue(float newScrollValue)
- {
- scrollBar.scrollValue = newScrollValue;
- }
- }
|