Example #1
0
        private void ApplyScrollEffects(RectTransform page)
        {
            int   index  = visiblePageToIndex[page];
            float offset = OffsetFromIndex(index);

            bool isActivePage   = page == activePage;
            bool isInteractable = shouldTilesAlwaysBeInteractable || isActivePage;

            BaseScrollEffect.UpdateData updateData = new BaseScrollEffect.UpdateData();
            updateData.page           = page;
            updateData.pageIndex      = index;
            updateData.pageCount      = PageCount;
            updateData.pageOffset     = offset;
            updateData.scrollOffset   = ScrollOffset;
            updateData.spacing        = pageProvider.GetSpacing();
            updateData.looping        = loop;
            updateData.isInteractable = isInteractable;
            updateData.moveDistance   = CurrentMoveDistance;

            for (int i = 0; i < scrollEffects.Length; i++)
            {
                BaseScrollEffect scrollEffect = scrollEffects[i];
                if (scrollEffect.enabled)
                {
                    scrollEffect.ApplyEffect(updateData);
                }
            }
        }
Example #2
0
        public override void ApplyEffect(BaseScrollEffect.UpdateData updateData)
        {
            float distance    = updateData.pageOffset - updateData.scrollOffset;
            float absDistance = Mathf.Abs(distance);

            updateData.page.anchoredPosition3D = new Vector3(
                (mirrorX ? absDistance : distance) * Weights.x,
                (mirrorY ? absDistance : distance) * Weights.y,
                (mirrorZ ? absDistance : distance) * Weights.z);
        }
Example #3
0
        public override void ApplyEffect(BaseScrollEffect.UpdateData updateData)
        {
            // Calculate the difference.
            float difference = updateData.scrollOffset - updateData.pageOffset;

            // Calculate the scale for this page.
            float ratioScrolled = Mathf.Abs(difference) / updateData.spacing;
            float scale         = ((1.0f - ratioScrolled) * (1.0f - minScale)) + minScale;

            scale = Mathf.Clamp(scale, 0.0f, 1.0f);

            // Update the scale.
            updateData.page.localScale = new Vector3(scale, scale, scale);
        }
Example #4
0
        public override void ApplyEffect(BaseScrollEffect.UpdateData updateData)
        {
            TiledPage tiledPage = updateData.page.GetComponent <TiledPage>();

            if (tiledPage == null)
            {
                Debug.LogError("Page (" + updateData.page.name + ") does not have TiledPage. " +
                               "Cannot apply TileScrollEffect.");
                return;
            }

            /// Calculate the distance between the scroll position and this page.
            float difference        = updateData.scrollOffset - updateData.pageOffset;
            float clampedDifference = Mathf.Clamp(difference, -updateData.spacing, updateData.spacing);

            tiledPage.ApplyScrollEffect(clampedDifference, updateData.spacing, updateData.isInteractable);
        }
Example #5
0
        public override void ApplyEffect(BaseScrollEffect.UpdateData updateData)
        {
            CanvasGroup pageCanvasGroup = updateData.page.GetComponent <CanvasGroup>();

            /// All pages require a CanvasGroup for manipulating Alpha.
            if (pageCanvasGroup == null)
            {
                Debug.LogError("Cannot adjust alpha for page " + updateData.page.name + ", missing CanvasGroup");
                return;
            }

            // Calculate the difference
            float difference = updateData.scrollOffset - updateData.pageOffset;

            /// Calculate the alpha for this page.
            float alpha = 1.0f - (Mathf.Abs(difference) / updateData.spacing);

            alpha = (alpha * (1.0f - minAlpha)) + minAlpha;
            alpha = Mathf.Clamp(alpha, 0.0f, 1.0f);

            /// If this is the last page or the first page,
            /// Then we clamp the alpha to 1 when dragging past the edge
            /// Of the scrolling region.
            if (!updateData.looping)
            {
                if (updateData.pageIndex == 0 && difference < 0)
                {
                    alpha = 1.0f;
                }
                else if (updateData.pageIndex == updateData.pageCount - 1 && difference > 0)
                {
                    alpha = 1.0f;
                }
            }

            pageCanvasGroup.alpha = alpha;
        }