Created
April 19, 2017 18:16
-
-
Save nkjzm/d237af5da28c3471d1d05fa28b28cc7e to your computer and use it in GitHub Desktop.
自動的にスクロールバーが隠れるScrollRect
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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