public void ScrollToView(Rect rect, bool ani, bool setFirst)
{
_owner.EnsureBoundsCorrect();
if (_needRefresh)
Refresh();
if (_yOverlap > 0)
{
float bottom = _yPos + _viewHeight;
if (setFirst || rect.y <= _yPos || rect.height >= _viewHeight)
{
if (_pageMode)
this.SetPosY(Mathf.Floor(rect.y / _pageSize.y) * _pageSize.y, ani);
else
SetPosY(rect.y, ani);
}
else if (rect.y + rect.height > bottom)
{
if (_pageMode)
this.SetPosY(Mathf.Floor(rect.y / _pageSize.y) * _pageSize.y, ani);
else if (rect.height <= _viewHeight / 2)
SetPosY(rect.y + rect.height * 2 - _viewHeight, ani);
else
SetPosY(rect.y + rect.height - _viewHeight, ani);
}
}
if (_xOverlap > 0)
{
float right = _xPos + _viewWidth;
if (setFirst || rect.x <= _xPos || rect.width >= _viewWidth)
{
if (_pageMode)
this.SetPosX(Mathf.Floor(rect.x / _pageSize.x) * _pageSize.x, ani);
SetPosX(rect.x, ani);
}
else if (rect.x + rect.width > right)
{
if (_pageMode)
this.SetPosX(Mathf.Floor(rect.x / _pageSize.x) * _pageSize.x, ani);
else if (rect.width <= _viewWidth / 2)
SetPosX(rect.x + rect.width * 2 - _viewWidth, ani);
else
SetPosX(rect.x + rect.width - _viewWidth, ani);
}
}
if (!ani && _needRefresh)
Refresh();
}