void AdjustScrollPositionAfterPageMoved(eDirection directionMoved) { var oneOrMinusOne = directionMoved == eDirection.Left ? -1 : 1; float pageSize = ScrollRect.GetPageSize(); var directionVector = ScrollRect.GetDirectionVector(); var adjustment = (directionVector * (pageSize + SpaceBetweenPages) * oneOrMinusOne); ScrollRect.ResetDragOffset = true; ScrollRect.content.anchoredPosition += adjustment; UpdatePages(); // if we're already scrolling, stop, recalculate, and scroll from there if (scrollCoroutine != null) { scrollRectAnimation_InitialPosition += adjustment; scrollRectAnimation_DesiredPosition += adjustment; } }
/// <summary> /// Called by UpdateScrollRectPagePositions when ShowPagePreviews is true /// </summary> void UpdateSeamlessPagePositions_PagePreviews() { if (!Application.isPlaying) { return; } if (!LoopSeamlessly) { return; } // we need at least 3 pages for our positioning code to work properly, // so duplicate pages as necessary // This isn't working yet, but will hopefully be available in a later version of PagedRect /*if (NumberOfPages <= 3 || Pages.Any(p => p.IsDuplicate)) * { * SeamlessLooping_HandleDuplicatePages(); * }*/ // this will work differently to the regular method // instead of moving pages as we scroll past certain offsets at the start/end, we will instead move pages whenever we change the current page, // provided we're less than two pages from the start/end bool pageMoved = false; var pagePosition = GetPagePosition(CurrentPage); float oneOrMinusOne = 1; var pageSize = ScrollRect.horizontal ? m_otherPageSize.x : m_otherPageSize.y; // if we have enough pages, then move pages around earlier to make the experience more 'seamless' // (and avoid users seeing the actual page move). With fewer pages, this isn't an option var minPage = NumberOfPages >= 5 ? 2 : 1; if (pagePosition <= minPage) { var pageToMove = Pages.Last(); pageToMove.transform.SetAsFirstSibling(); oneOrMinusOne = -1; pageMoved = true; } else if (NumberOfPages - pagePosition <= minPage) { var pageToMove = Pages.First(); pageToMove.transform.SetAsLastSibling(); pageMoved = true; } if (pageMoved) { ScrollRect.ResetDragOffset = true; var directionVector = ScrollRect.GetDirectionVector(); var adjustment = (directionVector * (pageSize + SpaceBetweenPages) * oneOrMinusOne); ScrollRect.content.anchoredPosition += adjustment; UpdatePages(); // if we're already scrolling, stop, recalculate, and scroll from there if (scrollCoroutine != null) { scrollRectAnimation_InitialPosition += adjustment; scrollRectAnimation_DesiredPosition += adjustment; } PagedRectTimer.DelayedCall(0, () => Viewport.GetComponent <PagedRect_LayoutGroup>().SetLayoutHorizontal(), this); } }