12345678910111213141516171819202122232425262728293031323334353637383940 |
- using UnityEngine;
- using System.Collections;
- using UnityEngine.UI;
- /// <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
- {
- Scrollbar scrollBar;
- void Awake()
- {
- scrollBar = GetComponent<Scrollbar>();
- }
- void OnEnable()
- {
- StartCoroutine(ResetScrollCoroutine());
- }
- IEnumerator ResetScrollCoroutine()
- {
- yield return new WaitForSeconds(0.5f); //wait for transition
- iTween.ValueTo(gameObject, iTween.Hash(
- "from", scrollBar.value,
- "to", 0,
- "time", 0.5f,
- "easetype", iTween.EaseType.easeOutCubic,
- "onupdate", "UpdateScrollValue",
- "onupdatetarget", gameObject));
- }
- void UpdateScrollValue(float newScrollValue)
- {
- scrollBar.value = newScrollValue;
- }
- }
|