public void Init()
        {
            Canvas.ForceUpdateCanvases();

            _Collocation.InitIfNeeded(this);

            if (_Collocation.scrollRect.horizontalScrollbar != null || _Collocation.scrollRect.verticalScrollbar != null)
            {
                throw new UnityException("SmartScrollView only works with a " + typeof(SmartScrollViewScrollbar).Name + " component added to the Scrollbar and the ScrollRect shouldn't have any scrollbar set up in the inspector (it hooks up automatically)");
            }

            _ItemsDesc     = new ItemsDescriptor(_Collocation.DefaultItemSize);
            _InternalState = InternalState.CreateFromSourceParamsOrThrow(_Collocation, _ItemsDesc);

            _VisibleItems         = new List <UILoopSmartItem>();
            _AVGVisibleItemsCount = 0;

            Refresh();
            _InternalState.UpdateLastProcessedCTVirtualInsetFromParentStart();
            SetVirtualAbstractNormalizedScrollPosition(1f, false);             // scroll to start
            _Collocation.scrollRect.onValueChanged.AddListener(OnScrollViewValueChanged);

            if (ScrollPositionChanged != null)
            {
                ScrollPositionChanged(GetNormalizedPosition());
            }

            Initialized = true;
        }
        protected InternalStateGeneric(TParams sourceParams, ItemsDescriptor itemsDescriptor)
        {
            _SourceParams = sourceParams;
            _ItemsDesc    = itemsDescriptor;

            var lg = sourceParams.content.GetComponent <LayoutGroup>();

            if (lg && lg.enabled)
            {
                lg.enabled = false;
                Debug.Log("LayoutGroup on GameObject " + lg.name + " has beed disabled in order to use Tools");
            }

            var contentSizeFitter = sourceParams.content.GetComponent <ContentSizeFitter>();

            if (contentSizeFitter && contentSizeFitter.enabled)
            {
                contentSizeFitter.enabled = false;
                Debug.Log("ContentSizeFitter on GameObject " + contentSizeFitter.name + " has beed disabled in order to use Tools");
            }

            var layoutElement = sourceParams.content.GetComponent <LayoutElement>();

            if (layoutElement)
            {
                GameObject.Destroy(layoutElement);
                Debug.Log("LayoutElement on GameObject " + contentSizeFitter.name + " has beed DESTROYED in order to use Tools");
            }

            if (sourceParams.scrollRect.horizontal)
            {
                startEdge           = RectTransform.Edge.Left;
                endEdge             = RectTransform.Edge.Right;
                transvStartEdge     = RectTransform.Edge.Top;
                _GetRTCurrentSizeFn = root => root.rect.width;
            }
            else
            {
                startEdge           = RectTransform.Edge.Top;
                endEdge             = RectTransform.Edge.Bottom;
                transvStartEdge     = RectTransform.Edge.Left;
                _GetRTCurrentSizeFn = root => root.rect.height;
            }


            _SourceParams.UpdateContentPivotFromGravityType();

            CacheScrollViewInfo();
        }
 protected virtual void CollectItemsSizes(ItemCountChangeMode changeMode, int count, int indexIfInsertingOrRemoving, ItemsDescriptor itemsDesc)
 {
     itemsDesc.ReinitializeSizes(changeMode, count, indexIfInsertingOrRemoving, _Collocation.DefaultItemSize);
 }
Exemple #4
0
 protected InternalState(TParams sourceParams, ItemsDescriptor itemsDescriptor) : base(sourceParams, itemsDescriptor)
 {
 }
Exemple #5
0
            internal static InternalState CreateFromSourceParamsOrThrow(TParams sourceParams, ItemsDescriptor itemsDescriptor)
            {
                if (sourceParams.scrollRect.horizontal && sourceParams.scrollRect.vertical)
                {
                    throw new UnityException("Can't optimize a ScrollRect with both horizontal and vertical scrolling modes. Disable one of them");
                }

                return(new InternalState(sourceParams, itemsDescriptor));
            }