Ejemplo n.º 1
0
        /// <summary>
        /// Called internally in <see cref="OSA{TParams, TItemViewsHolder}.Init()"/> and every time the scrollview's size changes.
        /// This makes sure the content and viewport have valid values. It can also be overridden to initialize custom data
        /// </summary>
        public virtual void InitIfNeeded(IOSA iAdapter)
        {
            _ScrollViewRT = iAdapter.AsMonoBehaviour.transform as RectTransform;
            LayoutRebuilder.ForceRebuildLayoutImmediate(ScrollViewRT);

            AssertValidWidthHeight(ScrollViewRT);

            var sr = ScrollViewRT.GetComponent <ScrollRect>();

            if (sr && sr.enabled)
            {
                throw new OSAException("The ScrollRect is not needed anymore starting with v4.0. Remove or disable it!");
            }

            if (!Content)
            {
                throw new OSAException("Content not set!");
            }
            if (!Viewport)
            {
                Viewport = ScrollViewRT;
                if (Content.parent != ScrollViewRT)
                {
                    throw new OSAException("Content's parent should be the ScrollView itself if there's no viewport specified!");
                }
            }
            if (!_Snapper)
            {
                _Snapper = ScrollViewRT.GetComponent <Snapper8>();
            }

            if (ForwardDragSameDirectionAtBoundary && !ForwardDragToParents)
            {
                Debug.Log("OSA: ForwardDragSameDirectionAtBoundary is true, but ForwardDragToParents is false. This will have no effect");
            }

            if ((ContentPadding.left == -1) != (ContentPadding.right == -1))
            {
                Debug.Log("OSA: ContentPadding.right and .left should either be both zero or positive or both -1. Setting both to 0...");
                ContentPadding.left = ContentPadding.right = 0;
            }

            if ((ContentPadding.top == -1) != (ContentPadding.bottom == -1))
            {
                Debug.Log("OSA: ContentPadding.top and .bottom should either be both zero or positive or both -1. Setting both to 0...");
                ContentPadding.top = ContentPadding.bottom = 0;
            }


            effects.InitIfNeeded();

            // There's no concept of content padding when looping. spacing should be used instead
            if (effects.LoopItems)
            {
                bool showLog = false;
                int  ctSp    = (int)ContentSpacing;
                if (IsHorizontal)
                {
                    if (ContentPadding.left != ctSp)
                    {
                        showLog             = true;
                        ContentPadding.left = ctSp;
                    }

                    if (ContentPadding.right != ctSp)
                    {
                        showLog = true;
                        ContentPadding.right = ctSp;
                    }
                }
                else
                {
                    if (ContentPadding.top != ctSp)
                    {
                        showLog            = true;
                        ContentPadding.top = ctSp;
                    }

                    if (ContentPadding.bottom != ctSp)
                    {
                        showLog = true;
                        ContentPadding.bottom = ctSp;
                    }
                }

                if (showLog)
                {
                    Debug.Log("OSA: setting conteng padding to be the same as content spacing (" + ContentSpacing.ToString("#############.##") + "), because looping is enabled");
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Called internally in <see cref="OSA{TParams, TItemViewsHolder}.Init()"/> and every time the scrollview's size changes.
        /// This makes sure the content and viewport have valid values. It can also be overridden to initialize custom data
        /// </summary>
        public virtual void InitIfNeeded(IOSA iAdapter)
        {
            _ScrollViewRT = iAdapter.AsMonoBehaviour.transform as RectTransform;
            var sr = ScrollViewRT.GetComponent <ScrollRect>();

            if (sr && sr.enabled)
            {
                throw new UnityException("OSA: The ScrollRect is not needed anymore starting with v4.0. Remove or disable it!");
            }

            if (!Content)
            {
                throw new UnityException("OSA: Content not set!");
            }
            if (!Viewport)
            {
                Viewport = ScrollViewRT;
                if (Content.parent != ScrollViewRT)
                {
                    throw new UnityException("OSA: Content's parent should be the ScrollView itself if there's no viewport specified!");
                }
            }
            if (!_Snapper)
            {
                _Snapper = ScrollViewRT.GetComponent <Snapper8>();
            }

            effects.InitIfNeeded();

            // There's no concept of content padding when looping. spacinf should be used instead
            if (effects.loopItems)
            {
                bool showLog = false;
                int  ctSp    = (int)ContentSpacing;
                if (IsHorizontal)
                {
                    if (ContentPadding.left != ctSp)
                    {
                        showLog             = true;
                        ContentPadding.left = ctSp;
                    }

                    if (ContentPadding.right != ctSp)
                    {
                        showLog = true;
                        ContentPadding.right = ctSp;
                    }
                }
                else
                {
                    if (ContentPadding.top != ctSp)
                    {
                        showLog            = true;
                        ContentPadding.top = ctSp;
                    }

                    if (ContentPadding.bottom != ctSp)
                    {
                        showLog = true;
                        ContentPadding.bottom = ctSp;
                    }
                }

                if (showLog)
                {
                    Debug.Log("OSA: setting conteng padding to be the same as content spacing (" + ContentSpacing.ToString("#############.##") + "), because looping is enabled");
                }
            }
        }