if(_scrollBar.backgroundWidget != null)
{
UIEventListener bgl = UIEventListener.Get(_scrollBar.backgroundWidget.gameObject);
if(bgl != null)
{
bgl.onPress += OnScrollBarPressed;
bgl.onDrag += OnScrollBarDragged;
}
}
void OnScrollBarPressed(GameObject go, bool isPressed)
{
if(!isPressed)
{
OnScrollBarChanged();
}
}
void OnScrollBarDragged(GameObject go, Vector2 delta)
{
OnScrollBarChanged();
}
void OnScrollBarChanged()
{
Vector3 newLocalPos = _scrollView.gameObject.transform.localPosition;
if(_scrollView.movement == UIScrollView.Movement.Vertical)
{
newLocalPos.y = _scrollBar.value * (_wrapContent.itemSize * (NUM_ITEMS / (float)NUM_COLUMNS) - _uiPanel.GetViewSize().y) + _svStartLocalPos.y;
}
else if(_scrollView.movement == UIScrollView.Movement.Horizontal)
{
newLocalPos.x = -_scrollBar.value * (_wrapContent.itemSize * (NUM_ITEMS / (float)NUM_ROWS) - _uiPanel.GetViewSize().x) + _svStartLocalPos.x;
}
SpringPanel.Begin(_scrollView.panel.cachedGameObject, newLocalPos, 8).onFinished = OnSpringPanelFinished;
}
void OnSpringPanelFinished()
{
_scrollView.RestrictWithinBounds(false);
}