Esempio n. 1
0
        /// <summary>
        /// Checks if an adapter is available from the recycled list otherwise creates an instance of one
        /// </summary>
        /// <returns></returns>
        private AbstractScrollViewAdapter GetAdapter()
        {
            if (this.adaptersPoolContainer.transform.childCount > 0)
            {
                // Manually find a child adaptor if possible (GetComponentInChildren doesn't work)
                foreach (Transform child in this.adaptersPoolContainer.transform)
                {
                    if (null != child)
                    {
                        AbstractScrollViewAdapter childAdapter = child.GetComponent<AbstractScrollViewAdapter>() as AbstractScrollViewAdapter;
                        if (null != childAdapter)
                        {
                            return childAdapter;
                        }
                    }
                }
            }

            AbstractScrollViewAdapter adapter = Instantiate<AbstractScrollViewAdapter>(this.baseAdapter) as AbstractScrollViewAdapter;
            adapter.gameObject.SetActive(false);
            adapter.transform.SetParent(this.adaptersPoolContainer.transform);
            adapter.SetContext(this);

            return adapter;
        }
Esempio n. 2
0
        /// <summary>
        /// Checks what anchors are visible and adds adaptors to them if they don't already have them
        /// </summary>
        private void RefreshAdapters()
        {
            for (int i = 0, max = Mathf.Min(this.itemCount, this.anchors.Count); i < max; ++i)
            {
                RectTransform anchor = this.anchors[i];
                bool isAnchorActive = this.EvaluateAdapterAtPosition(anchor);
                bool isAnchorSetup = anchor.childCount > 0;
                if (isAnchorActive && isAnchorSetup || !isAnchorActive && !isAnchorSetup)
                {
                    continue;
                }

                if (isAnchorActive && !isAnchorSetup)
                {
                    AbstractScrollViewAdapter adapter = this.GetAdapter();
                    adapter.transform.SetParent(anchor);
                    adapter.Setup(this.dataSource.GetItem(i));
                    adapter.gameObject.SetActive(true);
                    continue;
                }

                if(!isAnchorActive && isAnchorSetup)
                {
                    AbstractScrollViewAdapter adapter = anchor.GetComponentInChildren<AbstractScrollViewAdapter>() as AbstractScrollViewAdapter;
                    if(null != adapter)
                    {
                        this.DisposeAdapter(adapter);
                    }
                }
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Recycles and removes an adapter returning it to the pool
        /// </summary>
        /// <param name="adapter">the adapter to return to the pool</param>
        internal void DisposeAdapter(AbstractScrollViewAdapter adapter)
        {
            if (null == adapter)
            {
                return;
            }

            adapter.gameObject.SetActive(false);
            adapter.transform.SetParent(this.adaptersPoolContainer.transform);
        }