Skip to content

Instantly share code, notes, and snippets.

@nkjzm
Created April 19, 2017 18:16
Show Gist options
  • Save nkjzm/d237af5da28c3471d1d05fa28b28cc7e to your computer and use it in GitHub Desktop.
Save nkjzm/d237af5da28c3471d1d05fa28b28cc7e to your computer and use it in GitHub Desktop.
自動的にスクロールバーが隠れるScrollRect
using UnityEngine.UI;
using UnityEngine.EventSystems;
using System.Collections.Generic;
using DG.Tweening;
public class AutoHideScrollRect : ScrollRect
{
public List<Image> bars = new List<Image>();
float beginDuration = 0.5f;
float endDuration = 1.0f;
new void Start()
{
base.Start();
if (vertical)
{
bars.AddRange(verticalScrollbar.GetComponentsInChildren<Image>());
}
if (horizontal)
{
bars.AddRange(horizontalScrollbar.GetComponentsInChildren<Image>());
}
}
public override void OnBeginDrag(PointerEventData eventData)
{
base.OnBeginDrag(eventData);
foreach (var img in bars)
{
img.DOFade(1, beginDuration);
}
}
public override void OnEndDrag(PointerEventData eventData)
{
base.OnEndDrag(eventData);
foreach (var img in bars)
{
img.DOFade(0, endDuration);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment