private void Refresh()
{
if (_owner.displayObject == null || _owner.displayObject.isDisposed)
return;
_needRefresh = false;
UpdateContext.OnBegin -= _refreshDelegate;
if (_pageMode)
{
int page;
float delta;
if (_yOverlap > 0 && _yPerc != 1 && _yPerc != 0)
{
page = Mathf.FloorToInt(_yPos / _pageSize.y);
delta = _yPos - page * _pageSize.y;
if (delta > _pageSize.y / 2)
page++;
_yPos = page * _pageSize.y;
if (_yPos > _yOverlap)
{
_yPos = _yOverlap;
_yPerc = 1;
}
else
_yPerc = _yPos / _yOverlap;
}
if (_xOverlap > 0 && _xPerc != 1 && _xPerc != 0)
{
page = Mathf.FloorToInt(_xPos / _pageSize.x);
delta = _xPos - page * _pageSize.x;
if (delta > _pageSize.x / 2)
page++;
_xPos = page * _pageSize.x;
if (_xPos > _xOverlap)
{
_xPos = _xOverlap;
_xPerc = 1;
}
else
_xPerc = _xPos / _xOverlap;
}
}
else if (_snapToItem)
{
float tmpX = _xPerc == 1 ? 0 : _xPos;
float tmpY = _yPerc == 1 ? 0 : _yPos;
_owner.GetSnappingPosition(ref tmpX, ref tmpY);
if (_xPerc != 1 && !Mathf.Approximately(tmpX, _xPos))
{
_xPos = tmpX;
_xPerc = _xPos / _xOverlap;
if (_xPerc > 1)
{
_xPerc = 1;
_xPos = _xOverlap;
}
}
if (_yPerc != 1 && !Mathf.Approximately(tmpY, _yPos))
{
_yPos = tmpY;
_yPerc = _yPos / _yOverlap;
if (_yPerc > 1)
{
_yPerc = 1;
_yPos = _yOverlap;
}
}
}
Refresh2();
onScroll.Call();
if (_needRefresh) //user change scroll pos in on scroll
{
_needRefresh = false;
UpdateContext.OnBegin -= _refreshDelegate;
Refresh2();
}
_aniFlag = 0;
}