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; }
/// <summary> /// <para>Initialize the adapter. This is automatically called in Start(), but it may also be called manually, if for some reason you implement Start() and don't want to call base.Start()</para> /// <para>Will call Canvas.ForceUpdateCanvases(), Params.InitIfNeeded(), will initialize the internal state and will change the items count to 0</para> /// <para>IMPORTANT: Do not call it in Awake(), OnEnable(), OnDisable(). OnStart() is the best place to do it.</para> /// </summary> public void Init() { Canvas.ForceUpdateCanvases(); _Params.InitIfNeeded(this); if (_Params.Snapper) { _Params.Snapper.Adapter = this; } if (_Params.scrollRect.horizontalScrollbar != null || _Params.scrollRect.verticalScrollbar != null) { throw new UnityException("SRIA only works with a " + typeof(ScrollbarFixer8).Name + " component added to the Scrollbar and the ScrollRect shouldn't have any scrollbar set up in the inspector (it hooks up automatically)"); } //Func<int, float> getSizeFn; if (_Params.scrollRect.horizontal) getSizeFn = i => GetItemWidth(i); else getSizeFn = i => GetItemHeight(i); _ItemsDesc = new ItemsDescriptor(_Params.DefaultItemSize); //, _Params.DefaultItemSizeUsage == BaseParams.DefaultSizeUsage.PLACEHOLDER_SIZE); _InternalState = InternalState.CreateFromSourceParamsOrThrow(_Params, _ItemsDesc); _VisibleItems = new List <TItemViewsHolder>(); _AVGVisibleItemsCount = 0; Refresh(); _InternalState.UpdateLastProcessedCTVirtualInsetFromParentStart(); SetVirtualAbstractNormalizedScrollPosition(1f, false); // scroll to start _Params.scrollRect.onValueChanged.AddListener(OnScrollViewValueChanged); if (ScrollPositionChanged != null) { ScrollPositionChanged(GetNormalizedPosition()); } // Debug stuff #if UNITY_EDITOR && !UNITY_WSA && !UNITY_WSA_10_0 // UNITY_WSA uses .net core, which SRIADebugger is not compatible with var debugger = GameObject.FindObjectOfType <SRIADebugger>(); if (debugger) { debugger.InitWithAdapter(this); } #endif Initialized = true; }